ios_33_ Music Background Playback

Source: Internet
Author: User

Music Background playback: three stepsimplemented in the Didenterbackground method in Appdelegate:

The Beginbackgroundtaskwithexpirationhandler method of the app

Turn on background tasks to let the program run in the background

-(void) Applicationdidenterbackground: (uiapplication *) application{    //Use the method to release shared resources, Save user data, invalidate timers, and store enough application state information to restore your application to its Curre NT State in case it is terminated later.     If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits.    Background play one of three steps: Let the app run in the background    [application Beginbackgroundtaskwithexpirationhandler:nil];}



"33_ sound-info.plist" in the Supporting files directoryAdd a "Required background modes"the value is "APP plays audio or streams audio/video using AirPlay"

third, the initialization method of the tool class "

Initialize, set the type of the audio session and activate


+ (void) initialize{    //Background play, step three, set audio session type    avaudiosession *session = [avaudiosession sharedinstance];    Type: Play and record    [session Setcategory:avaudiosessioncategoryplayandrecord Error:nil];    and to activate the audio session    [session Setactive:yes Error:nil];}


the other three commonly used audio session types are:

Ios_33_ Music Background playback

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.