【问题标题】:Play a video from local itunes Library in a uiview frame在 uiview 框架中播放本地 iTunes 库中的视频
【发布时间】:2014-04-29 14:34:03
【问题描述】:

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

【问题讨论】:

标签: ios mpmediaitem movieplayer


【解决方案1】:

为什么以下不起作用?

什么都没发生……

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 2019-01-08
    • 2012-12-21
    相关资源
    最近更新 更多