How to play background music with MPMusicPlayerController's applicationMusicPlayer in iOS? - ios

Hello i am trying to play background music with MPMusicPlayerController's applicationMusicPlayer in iOS.
I have also added Required background modes in Plist.
But it doesn't play background music.
How can i play background music with MPMusicPlayerController?
Thanks for your reading. :)

The applicationMusicPlayer does not support background music. Use MPMusicPlayerController's iPodMusicPlayer instead. It shares the state with the built-in iPod player and music will continue to play when your app enters the background.

Bryan is right about applicationMusicPlayer not playing music in background, but there is another solution:
You can use AVAudioPlayer to play either streamed or local(bundle) audio. It even allows you to play multiple audio file at the same time having an AVAudioPlayer instance for each.
Here's the documentation:
http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

Related

Is it possible to start audio play when app is in the background in iOS?

Is it possible to start audio play when app is in the background?
When my app is in the background , it calls the method to play the sound but AvAudioPlayer doesnt play.
Ive gone through various links on the web regarding this but all I could find is how to continue playing audio when app goes in the background. So does this mean we can't start the audio play in the background?
Thanks in advance :)

Play audio in background while built-in music player is active ?

Using the AVAudioSession class, it is possible to play audio in the background, but I was wondering if it is possible to play audio in the background and having the built-in music player playing at the same time. Based on the documentation, this seems to be impossible.
Is there a configuration that I am overlooking or a reliable workaround?

iOS 6 AVAudioSession issue

In my application I have made [audioSession setCategory:AVAudioSessionCategoryPlayback] to play audio in back ground and also to mute other audio play backs while playing song in my application. I am playing the audio using AVPlayer and also I have UIWebView for playing video in same Application. The issue arises when I play both video in web view and audio using AVPlayer. The music mixes in this case. Prior to iOS 6 when I rech same situation one audio pauses automatically and the mixing up does not occur. So kindly suggest some solutions.
Try to set
Required background modes -> App plays audio
in Info.plist.

Play game background music with iPod music using CocosDenshion

As you can suggest, I have a trouble =)
In the game I use CocosDenshion for playing both background music and sound effects. As far as I know and can see in the code, it uses AVAudioPlayer to play background music. The trouble is appeared when I try to launch my app with music from iPod library.
I set audio category to AmbientSound (tried setting both with AVAudioSession and C interface). If I then try to play game background track directly using AVAudioPlayer, it plays with iPod music in background without problems. But if try to play background music with SimpleAudioEngine, only iPod music is playing.
Can someone give an advice how to make CocosDenshion work in this case?

Airplay of audio using AVPlayer does not work in the background

I am doing audio playback using the AVPlayer class from a remote URL.
It plays fine if I just play to the headphones/built in speaker, but I am seeing some oddities with AirPlay.
When I change to use an AppleTV for AirPlay, it will stream the audio, but on my iphone the audio playback indicator (the small 'play' triangle in the top menu bar) disappears, and when I lock the phone instead of continuing in the background, it stops. (When playing normally, it plays in the background fine).
Why is the AVPlayer not working in the background for audio over AirPlay?
Is this what other see? Is there a way around it?
Ok - I dug through the apple dev forums and found a hint.
If you are using AVPlayer for audio only, and want it to work in the background while doing airplay, you need to disable the allowsAirPlayVideo setting.
Apparently AVPlayer on iOS 5+ assumes that it is playing back video via AirPlay, and so does not allow backgrounding, unless you explicitly disable video AirPlay.
Once you disable this (i.e. self.player.allowsAirPlayVideo = FALSE;) then your audio will still play via AirPlay, but now it will not be treated as video, only as audio, and so will allow the backgrounding to work.
Have you enable the 'Background Audio' mutlitasking setting in the app plist?

Resources