標籤:音樂 loop rgb margin back pat family with 注意
音樂播放
NSString *path = [[NSBundlemainBundle] pathForResource:@"預謀"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];
}
一定要注意player的引用,假設直接在函數內部申請一個暫時變數。那麼這個player會在函數運行完畢,運行release 會被釋放掉,假設須要在函數內部使用。那麼請sleep下。只是這樣會阻塞主線程的運作
視頻播放器
NSURL * movieurl = [NSURLURLWithString:@"http://v.youku.com/player/getRealM3U8/vid/XNDUwNjc4MzA4/type/video.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewControlleralloc] initWithContentURL:movieurl];
[selfpresentMoviePlayerViewControllerAnimated:player];
iOS 調用音樂播放以及視頻播放器