IOS_33 _ playing in the background and ios_33 playing in the background
Playing music in the background: Three StepsImplement the following in the didEnterBackground method of appDelegate:
App beginBackgroundTaskWithExpirationHandler Method
Enable background tasks to run programs in the background
-(Void) applicationDidEnterBackground :( UIApplication *) application {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // one of the three steps for background playback: run the application in the background [application beginBackgroundTaskWithExpirationHandler: nil];}
In the Supporting Files directory, [33 _ audio-Info. plist]
Add a [Required background modes]
The value is App plays audio or streams audio/video using AirPlay]
Third, the initialization method in the tool class 【
Initialize], Set the audio session type, and activate
+ (Void) initialize {// back-end playback. Step 3: Set the audio session type AVAudioSession * session = [AVAudioSession sharedInstance]; // The type is play and recording [session setCategory: AVAudioSessionCategoryPlayAndRecord error: nil]; // You must activate the audio session [session setActive: YES error: nil];}
The other three common audio session types are:
Ios can play music in the background. How can I control it to play the next one?
-(Void) audioPlayerDidFinishPlaying :( AVAudioPlayer *) player successfully :( BOOL) flag {} In this method, a timer can play the next sound. Of course, the premise must be set to allow background playback: In viewdidload, set it to AVAudioSession * session = [AVAudioSession sharedInstance]; [session setActive: YES error: nil]; [session setCategory: AVAudioSessionCategoryPlayback error: nil]; you can play multiple audio streams at the front end, back end, or off the screen.
Music Playing software running in the background
If you don't listen to it, it will take a relatively simple function and take up a small amount of resources. You just need to listen quietly and set automatic start upon startup. A song is played cyclically, which rarely occupies resources. The icon in the lower right corner is displayed.