美文网首页
OC播放项目本地mp4文件

OC播放项目本地mp4文件

作者: tinyang | 来源:发表于2020-05-18 16:34 被阅读0次

    NSString*videoPath = [[NSBundle mainBundle]pathForResource:@"视频名称"ofType:@"mp4"];

    NSURL*url = [NSURL fileURLWithPath:videoPath];

    AVAsset*asset = [AVAsset assetWithURL:url];

    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];

    self.player = [AVPlayer playerWithPlayerItem:item];

    AVPlayerLayer*playerLayer  = [AVPlayerLayer playerLayerWithPlayer:self.player];

    playerLayer.frame=CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);

    playerLayer.videoGravity =AVLayerVideoGravityResizeAspectFill;

    [self.view.layer addSublayer:playerLayer];

    [self.player play];

相关文章

网友评论

      本文标题:OC播放项目本地mp4文件

      本文链接:https://www.haomeiwen.com/subject/gettrttx.html