I have an app in the store that needs to play Music in background mode. Now with the iOS5.1 release, the music stops when the device is locked/moved to background.
I looked at the release notes and didn't find anything related.... Any idea?
In your app.plist your need to specify that your app will be playing audio in the background. For key "Required background modes" add a value "App plays audio". Note that raw name for that key is UIBackgroundModes, and the value you need to insert in that array is "audio".
Related
So I have a video app for tvOS and I would like to serve ads on it, but one of the requirements is to not serve them while the TV is not showing them.
All good, but if you change the source of your TV and the Apple TV is still running it will continue to run and not lock or turn off while watching the videos. I thought that the resign active notification or entered background will give me that information, but they do not.
Is there any way to check if tvOS is currently on screen?
I am using tvOS 12 and AVPlayer.
I've integrated opentok ios sdk in my iOS 7 app, it is working fine, except this problem:
During video chat if I don't access iPhone for 5-10 seconds..then my app moves into background, causing viewer at other end to hear only audio. Video is disabled after app goes to background state.
I've observed same thing with their official example
https://github.com/opentok/opentok-ios-sdk/tree/master/samples/OpenTokFullTutorial
How can I avoid my app going to background while video chat is ongoing. Skype is working fine in this case, I want to achieve same thing.
What you want to do is prevent the iPhone from going to sleep. To do this, you cant try this:
[UIApplication sharedApplication].idleTimerDisabled = YES;
Here is iOS documentation on idleTimerDisabled
If you don't want the app going into background at all (like when the user taps on home button), you can opt to kill the app when it's not running instead of having it run in the background. To do that, check out iOS guide on opting out of background execution
If you do not want your app to run in the background at all, you can
explicitly opt out of background by adding the
UIApplicationExitsOnSuspend key (with the value YES) to your app’s
Info.plist file. When an app opts out, it cycles between the
not-running, inactive, and active states and never enters the
background or suspended states. When the user presses the Home button
to quit the app, the applicationWillTerminate: method of the app
delegate is called and the app has approximately 5 seconds to clean up
and exit before it is terminated and moved back to the not-running
state.
Hope that helped!
I've noticed that when my app start, the music I'm listening is automatically stopped, and I've noticed that when I start some other apps, the music just continue... this means that I don't know how to manage the actual playing music in the device to let it plays or stop.
I'm developing a game with obj-c and cocos2d btw, I've searched but sadly I've found nothing... so here's my question, how can I let the music I'm listening with my device continue to play even if I start the app ?
edit: I'm using SimpleAudioEngine to start a background music and some sound effects in my app
Place this line in your application:didFinishLaunchingWithOptions: method of your AppDelegate or in general before using the audio player.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
According to the documentation, the AVAudioSessionCategoryAmbient category is
for an app in which sound playback is nonprimary—that is, your app can
be used successfully with the sound turned off.
This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays over iPod audio. When you
use this category, audio from other apps mixes with your audio. Your
audio is silenced by screen locking and by the Silent switch (called
the Ring/Silent switch on iPhone).
please import AVFoundation/AVFoundation.h
Swift:
Before playing enter this line:
let audioSession = AVAudioSession.sharedInstance()
if audioSession.otherAudioPlaying {
_ = try? audioSession.setCategory(AVAudioSessionCategoryAmbient, withOptions: AVAudioSessionCategoryOptions.MixWithOthers)
}
For people looking to solve this within react native (iOS)
My problem was quite the opposite where some of our muted videos with no music was causing background sound to be paused from other apps for no reason.
To fix this, also pass ignoreSilentSwitch="obey" prop alongside disableFocus and muted props through your Video component.
According to the docs:
You can activate the audio session at any time after setting its category, but it’s generally preferable to defer this call until your app begins audio playback. Deferring the call ensures that you won’t prematurely interrupt any other background audio that may be in progress.
Be sure not to be starting the audio session directly via its setActive method or indirectly via AVAudioEngine or other playback engine(s) immediately after the app launches. You should set only the category at this stage if you don't want your app to interrupt others on launch. If you're using AVAudioEngine, defer setting up the engine or connecting anything to the engine's mainMixerNode or outputNode until you actually need to start playing something.
When your app starts playing music, it will pause any audio currently playing. For obvious reasons. If you want your music to carry on playing when the app launches then don't let the app play any music.
I'm using iPodMusicPlayer for my MPMusicController.
And I want to get music queue as MPMediaItemCollection.
How can I do that?
In my app, you can select and play music in your music library by MPMediaPickerController.
Then, if you were playing music by iPod music app, it is interrupted.
After music you selected in my app finished, I want to back to music on iPod music app.
Thank you.
I'm afraid you can't - Apple retains sole control of the inner workings of the ipodmusicplayer
I read iOS Programming Guide, and I found not only "audio, location, voip", but also "External Accessory & Newsstand apps" are allowed in background mode. documents are as following:
In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background,
such as a music player app
Apps that keep users informed of their location at all times, such as a navigation app
Apps that supportVoice over Internet Protocol (VoIP)
Newsstand apps that need to download and process new content
Apps that receive regular updates from external accessories
However, I couldn't find the value for External Accessory in "Required background modes" key. Only I can choose is "App plays audio, App registers for location updates, App provides Voice over IP services".
Is it impossible to receive data from External Accessory when app is background mode ?
Thanks.
Though I couldn't select from lists, I could type "external-accessory", and it worked well.
Values for the UIBackgroundModes array for iOS5 and iOS6
audio
location
voip
newsstand-content
external-accessory
bluetooth-central
bluetooth-peripheral (supported from iOS6)