我有一个MPMediaItem,其中是iPad本地itunes库的视频。我如何在UI中玩现在查看这个?以下代码不起作用:
MPMediaItem *video = [allVideos objectAtIndex:indexPath.row];
NSURL *url = [video valueForProperty:MPMediaItemPropertyAssetURL];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[player prepareToPlay];
[player.view setFrame: videoView.bounds];
[videoView addSubview: player.view];
[player play];
为什么以下内容不起作用?
什么都没发生。。。
MPMediaItem *song = [allVideos objectAtIndex:indexPath.row];
NSLog(@"%@",[song valueForProperty:MPMediaItemPropertyAssetURL]);
NSURL *url = [song valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayer *player = [[AVPlayer alloc] init];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:avAsset];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:playerItem];
player = [[AVPlayer alloc]initWithPlayerItem:playerItem];
//[player seekToTime:kCMTimeZero];
[player play];