IOS multimedia playing music AVAudioPlayer and AVPlayer

Source: Internet
Author: User

IOS multimedia playing music AVAudioPlayer and AVPlayer

1. iOS audio playback Mode

AVAudioPlayer AVPlayer system audio and audio Arrangement

AVAudioPlayer

It is easy to use, but can only play local audio, does not support streaming media playback

AVPlayer

After iOS4.0, you can use AVPlayer to play local audio and support streaming media playback. However, there are few interfaces and the processing of audio is not flexible enough.

Audio queue

The audio queue mainly processes streaming media playback and provides powerful and flexible API interfaces (the C-row interface). However, it is complicated to process.

2 AVAudioPlayer usage

To use AVAudioPlayer and AVPlayer, you must reference the AVFoundation class library.

Add the following method to the loadview method in the. m file:

NSBundle * bundle = [NSBundle mainBundle];

// Audio file path

NSString * urlString = [bundle pathForResource: @ "First Lady" ofType: @ "mp3"];

// Initialize the url

NSURL * url = [[NSURL alloc] initFileURLWithPath: urlString];

AVAudioPlayer * audioplayer = [[AVAudioPlayeralloc] initWithContentsOfURL: url error: NULL];

NSLog (@ "hello ");

// Prepare for playing

[Audioplayer prepareToPlay];

// [Audioplayer play];

If ([audioplayer play]) {

NSLog (@ "start playing ");

}


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.