本地播放器

1.在需要創(chuàng)建播放器的界面添加頭文件#import "AVFoundation/AVFoundation.h"

/**

?設(shè)置視頻播放

?*/

- (void)setupVideoPlayer{

// 創(chuàng)建url

//設(shè)置本地視頻url

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

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

//設(shè)置網(wǎng)絡(luò)視頻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];

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容