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 ");
}