IOS_33 _ playing in the background and ios_33 playing in the background

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.