IOS calls music play and Video Player
Play Music
NSString * path = [[NSBundlemainBundle] pathForResource: @ "premeditation" ofType: @ "mp3"];
If (path ){
NSURL * url = [NSURLfileURLWithPath: path];
Player = [[AVAudioPlayeralloc] initWithContentsOfURL: urlerror: nil];
[PlayersetDelegate: self];
Player. volume = 1;
Player. pan = 1;
Player. numberOfLoops =-1;
If ([playerprepareToPlay]) {
NSLog (@ "prepareToPlay: % @", path );
[Playerplay];
} Else {
NSLog (@ "no prepareToPlay ");
}
// [Player release];
}
Be sure to pay attention to the reference of the player. If you apply for a temporary variable directly within the function, the player will be executed after the function is executed and the release will be released. If you need to use it inside the function, so please sleep, but this will block the operation of the main thread
Video Player
NSURL * movieurl = [NSURLURLWithString: @ "http://v.youku.com/player/getRealM3U8/vid/XNDUwNjc4MzA4/type/video.m3u8"];
MPMoviePlayerViewController * player = [[MPMoviePlayerViewControlleralloc] initWithContentURL: movieurl];
[SelfpresentMoviePlayerViewControllerAnimated: player];