音乐播放
NSString *path = [[NSBundle
mainBundle] pathForResource:@"预谋"
ofType:@"mp3"];
if (path) {
NSURL *url = [NSURL
fileURLWithPath:path];
player= [[AVAudioPlayer
alloc]initWithContentsOfURL:url
error:nil];
[player
setDelegate:self];
player.volume =
1;
player.pan =
1;
player.numberOfLoops = -1;
if ([player
prepareToPlay]) {
NSLog(@"prepareToPlay:%@",path);
[player
play];
}
else {
NSLog(@"no prepareToPlay");
}
//[player release];
}
一定要注意player的引用,如果直接在函数内部申请一个临时变量,那么这个player会在函数执行完成,执行release 会被释放掉,如果需要在函数内部使用,那么请sleep下,不过这样会堵塞主线程的运作
视频播放器
NSURL * movieurl = [NSURL
URLWithString:@"http://v.youku.com/player/getRealM3U8/vid/XNDUwNjc4MzA4/type/video.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController
alloc] initWithContentURL:movieurl];
[self
presentMoviePlayerViewControllerAnimated:player];