I'm writing an application that occasionally records the user's voice. During recording, I would like the application to pause whatever music happens to be playing (pandora, ipod, etc) and when recording is finished, I want it to resume that music for the user.
Using MPMusicPlayerController's pause/play methods works with the iPod music. In fact, 'pause' will pause Pandora without trouble also; however, 'play' resumes the iPod instead of Pandora.
Pointers to relevant documentation are appreciated.
I stopped researching, but I don't believe there is a way to do this.
Related
I'm doing some audio streaming with iOS 7's Multipeer Connectivity framework. The streaming works well, but when I put the app on background it stops working.
Someone can tell me if this is a framework limitation, or I'm doing something wrong?
And, if it is a framework limitation, is it possible to do something to avoid this?
Can I use Background Tasks, to keep streaming and music working on background?
Is possible do this? If is not possible, do any alternatives exist for MultiPeer audio streaming between iOS devices?.
I´m using this example: https://github.com/tonyd256/TDAudioStreamer.
Explained on this page: http://robots.thoughtbot.com/streaming-audio-to-multiple-listeners-via-ios-multipeer-connectivity.
Thanks a lot!
On the Apple documentation for playing audio in the background (scroll down a bit). Some relevant paragraphs:
When the UIBackgroundModes key contains the audio value, the system’s media frameworks automatically prevent the corresponding app from being suspended when it moves to the background. As long as it is playing audio or video content or recording audio content, the app continues to run in the background. However, if recording or playback stops, the system suspends the app.
You can use any of the system audio frameworks to work with background audio content, and the process for using those frameworks is unchanged.
This means that iOS should recognize that you're playing audio through Core Audio, and keep your app unsuspended, as long as you've correctly configured your app for playing audio in the background.
Because your app is not suspended while playing media files, callbacks operate normally while your app is in the background. In your callbacks, though, you should do only the work necessary to provide data for playback. For example, a streaming audio app would need to download the music stream data from its server and push the current audio samples out for playback. Apps should not perform any extraneous tasks that are unrelated to playback.
You should be able to operate normally as long as your app is still playing audio, and is allowed to do what it needs to in order to continue playing audio. This means that you should be able to continue to use MPC in the background to receive the audio data and play it.
Be sure to read the entire documentation on the subject, especially regarding Audio Sessions.
iOS devices get limited cpu cycles for explicit purposes when they have been backgrounded by the user.
According to Apple's documentation on multitasking and execution in the background, the following types of apps are supported, but have to be explicitly declared:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background.
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Your case falls under Apps that play audible content to the user while in the background, such as a music player app. You can find more information from the link provided above.
I have created an app with PhoneGap that plays music from an online stream. It continues playing in background while the iPhone is locked but, and it stops when an incoming phone call arrives.
The problem is that when the phone call ends, music does not sound anymore. I use an HTML5 audio element to play the stream, and my app traces show me that play and playing HTML5 audio element events are triggered after phone call ends.
However, it simply does not produce any music or sound at all.
Hook up to the pause and resume events of Cordova in your app, if you're in paused state, then your app is suspended and would not play anything. You should invoke your play function on the resume event. Fore more info see Events: http://cordova.apache.org/docs/en/2.6.0/cordova_events_events.md.html#Events
it happens when play command is executed before audio device enabled
for your app.
yeah it is because of the app shutdown when your call arrives, to get back to app & to play audio it requires some seconds, in short it requires some seconds to start audio device after your call ends.if your play instruction executed before audio device is initiated for your application
you can solve this by cordova's resume event
As an android programmer, there are similar issues. When dealing with CordovaWeb views doing HTML5, if the activity is interrupted for something else, such as a phone call, it needs to be handled in code. In Android, when there is an interrupt, onPause or similar is called. Inside of that, you would need to save state, and the URL of the page for the webview.
When you navigate back, you need to restore the state.
I know i am speaking in Android while this is iOS, but there is some overlap when doing stuff like that.
See: Save & restoring WebView in an embedded PhoneGap app
I am developing an app which can stop or play a music from iPod or other audio at a specific time even if is in background. Is it possible?
I know that with a local notification can play an audio during 30 seconds, but I need more time. There are application which can do this like TuneIn Radio.
Thank you very much in advance!
Unless it is your app that is playing the music in the background I don't think it is going to be possible. The hardest part is the fact that you can't run an app in the background unless it is playsound, keeping track of the users location or is a voip client.
You can use a local notification, but the allarm sound is restricted to the 30 seconds and you can only stop any audio session if you app gets launched.
I need to be able to play a sound while running the application in the background.
I tried with UILocalNotifications but the file needs to be part of the bundle, and that will not be the case, as I need to generate the sound files on the fly...
So is there any way that I can play a sound while running in the background?
Thanks.
You can't, unless you continuously play audio and have the appropriate audio session category set for your app... then your app doesn't go to sleep, it continues to run (again so long as audio is playing).
This is part of the design limitations of iOS multitasking.
Apple has allowed people to get away with having a continuously looping blank audio file (AVAudioPlayer loop = -1 with a 1-sec blank CAF file) if the app is primarily audio related and it is obvious to the user that this has battery life implications (and can be disabled by the user), but YMMV... you app can also be rejected for this.
I'm using SimpleAudioEngine to play my sounds and I was wondering if there is anyway to check if iPod music is playing when the app is launched. If so, I want it to continue playing. I'm starting to think it may be called the simple engine for a reason as it doesn't allow features like this, where AVAudioEngine does...
Thanks :)
You should check out the official Audio Session Programming Guide and make sure that you are setting the correct session category. You will want to pick the category that allows your audio to mix with the iPod audio.