在uiview框架中播放来自本地itunes库的视频

时间:2014-04-29 14:34:03

标签: ios mpmediaitem movieplayer

我有一个 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];

1 个答案:

答案 0 :(得分: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];