Iphone development: audio, video, background, playing

Source: Internet
Author: User

When the application is suspended rather than permanently exiting, all the validity of the application will be suspended. In this case, if you need to play audio or video, you need to activate the play "single routine ", to ensure that the playing module is not suspended. Enable the audio or video to continue playing in the background without terminating the program due to suspension. You only need to add the following code in the corresponding position of the program:

NSError * myErr;
BOOL bAudioInputAvailable = FALSE;

AVAudioSession * audioSession = [AVAudioSession sharedInstance];
BAudioInputAvailable = [audioSession inputIsAvailable];

If (bAudioInputAvailable)
{
[AudioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: & myErr];
}
Else
{
[AudioSession setCategory: AVAudioSessionCategoryPlayback error: & myErr];
}

 


Be sure to execute the above Code in the playback code module or when the playback starts. Otherwise, the code is invalid.

 


In this way, even the screen lock does not affect the playing of music.

 

 

From cloud huaikong-abel

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.