tumtumtum / StreamingKit

A fast and extensible gapless AudioPlayer/AudioStreamer for OSX and iOS (iPhone, iPad)
Other
2.42k stars 525 forks source link

Initializing STKAudioPlayer stops background audio #261

Closed clayfreeman closed 8 years ago

clayfreeman commented 8 years ago

In my app's view controller, I have a class property that calls STKAudioPlayer.init(). When launching the app, any currently playing audio is stopped even though STKAudioPlayer is not doing anything. Upon commenting out the class property, launching the app no longer stops any background audio. Is this normal behavior, or should audio only be stopped when playback is requested?

richardgroves commented 8 years ago

Sounds like you might not have set the audio session up to allow other audio, and as soon as the STKAudioPlayer starts talking to the audio sub-system it takes over.

Take a look at AVAudioSession - https://developer.apple.com/library/prerelease/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/index.html and especially AVAudioSessionCategoryAmbient

On Thu, Jan 28, 2016 at 4:25 PM, Clay Freeman notifications@github.com wrote:

In my app's view controller, I have a class property that calls STKAudioPlayer.init(). When launching the app, any currently playing audio is stopped even though STKAudioPlayer is not doing anything. Upon commenting out the class property, launching the app no longer stops any background audio. Is this normal behavior, or should audio only be stopped when playback is requested?

— Reply to this email directly or view it on GitHub https://github.com/tumtumtum/StreamingKit/issues/261.

Richard Groves Technical Director | NoodlFroot

M: +44 (0)7962 054 163

www.noodlfroot.com

NoodlFroot Limited is a company registered in England and Wales with registration number 07245048. Registered office: 20-22 Wenlock Road, London, N1 7GU.

clayfreeman commented 8 years ago

I can assure you that this has been applied already.

Sent from my iPhone

On Jan 28, 2016, at 10:47 AM, Richard Groves notifications@github.com wrote:

Sounds like you might not have set the audio session up to allow other audio, and as soon as the STKAudioPlayer starts talking to the audio sub-system it takes over.

Take a look at AVAudioSession - https://developer.apple.com/library/prerelease/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/index.html and especially AVAudioSessionCategoryAmbient

On Thu, Jan 28, 2016 at 4:25 PM, Clay Freeman notifications@github.com wrote:

In my app's view controller, I have a class property that calls STKAudioPlayer.init(). When launching the app, any currently playing audio is stopped even though STKAudioPlayer is not doing anything. Upon commenting out the class property, launching the app no longer stops any background audio. Is this normal behavior, or should audio only be stopped when playback is requested?

— Reply to this email directly or view it on GitHub https://github.com/tumtumtum/StreamingKit/issues/261.

Richard Groves Technical Director | NoodlFroot

M: +44 (0)7962 054 163

www.noodlfroot.com

NoodlFroot Limited is a company registered in England and Wales with registration number 07245048. Registered office: 20-22 Wenlock Road, London, N1 7GU. — Reply to this email directly or view it on GitHub.

clayfreeman commented 8 years ago

I believe I've found the issue; upon launching the application, the STKAudioPlayer seems to be pre-initialized before the application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) method is called, thus the playback mode isn't set to ambient until after initialization of STKAudioPlayer. To fix this issue, I've declared my class property as lazy so that it is loaded when requested in viewDidLoad().