• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
AudioRoute Change Handling with AVAudioEngine
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AudioRoute Change Handling with AVAudioEngine


  • Subject: AudioRoute Change Handling with AVAudioEngine
  • From: Sasikumar JP <email@hidden>
  • Date: Fri, 05 Dec 2014 12:01:17 +0530

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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: kAudioHardwarePropertySleepingIsAllowed
  • Next by Date: Re: AVAudioSessionSilenceSecondaryAudioHintNotification
  • Previous by thread: kAudioHardwarePropertySleepingIsAllowed
  • Next by thread: Re: AVAudioSessionSilenceSecondaryAudioHintNotification
  • Index(es):
    • Date
    • Thread