Hi,
    I am migrating my streaming audio application from audio unit based API
to AVAudioEngine based API. Everything works fine. Except Audio Route
Change.

When ever application receive RouteChange notification, AudioEngine
automatically stops(audioEngine.running return false), as it stops it
clears the scheduled buffer from AudioPlayerNode. my application stops the
playback.

I have put a hack to check the engine running status, if it is not running,
starting the engine. which makes application works fine. But Route Change
transition is not smooth. My application goes to buffering mode for
sometime to fill the audioBuffer as scheduled buffer was cleared when
engine stops.

Is this expected behaviour or bug in AVAudioEngine?

I want make audio route smooth.

I have pasted the Route Change notification handling code and Hack to start
the engine when ever player status change:

    func handleRouteChange(notification: NSNotification) {

        println("route changes engineRunning \(audioPlayer.engineRunning())"
)

        if let userInfo = notification.userInfo {

            if let reasonKeyValue =
userInfo[AVAudioSessionRouteChangeReasonKey]?.integerValue {

                if let reasonValue =
AVAudioSessionRouteChangeReason(rawValue: UInt(reasonKeyValue)) {

                    switch reasonValue {

                    case .OldDeviceUnavailable:

                        println("Old Device unavailable")

                        stop()

                    default:

                        break

                    }

                }

            }

        }

    }

//HACK to start the engine

    var playerStatus: AudioPlayerStatus = .Init {

        didSet {

            println("Audio Engine state \(audioEngine.running)")

            if playerStatus == AudioPlayerStatus.Playing || playerStatus ==
AudioPlayerStatus.Buffering {

                if audioEngine.running == false {

                    startEngine()

                    println("started engine")

                }

            }

        }

    }

Output:

route changes engineRunning false

Override


Regards

Sasikumar JP
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to