0

我有一个MPMediaItem,其中是 iPad 本地 iTunes 库的视频。我现在如何在 UIView 中玩这个?以下代码不起作用

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];
4

1 回答 1

0

为什么以下不起作用?

什么都没发生...

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];
于 2014-04-30T13:25:31.117 回答