美文网首页
本地播放器

本地播放器

作者: 狂暴的小蜗牛 | 来源:发表于2020-03-27 09:39 被阅读0次

1.在需要创建播放器的界面添加头文件#import "AVFoundation/AVFoundation.h"

/**

 设置视频播放

 */

- (void)setupVideoPlayer{

// 创建url

//设置本地视频url

//    NSString *myFilePath = [[NSBundle mainBundle]pathForResource:@"movies"ofType:@"mp4"];

//    NSString *webVideoPath = [NSURL fileURLWithPath:myFilePath]

//设置网络视频url

    NSString *webVideoPath = @"https://vdse.bdstatic.com//19b5482c80fe2129b3b65d7689aaf886.mp4";

    NSURL*webVideoUrl = [NSURL URLWithString:webVideoPath];

    AVPlayerItem*videoItem = [[AVPlayerItem alloc]initWithURL:webVideoUrl];

    AVPlayer*player = [AVPlayer playerWithPlayerItem:videoItem];

    player.volume=0;

    AVPlayerLayer*playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];

    playerLayer.backgroundColor = [UIColor whiteColor].CGColor;

    playerLayer.videoGravity =AVLayerVideoGravityResizeAspectFill;

    playerLayer.frame=self.view.bounds;

    [self.view.layer insertSublayer:playerLayer atIndex:0];

    [player play];

}

相关文章

网友评论

      本文标题:本地播放器

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