1. 程式人生 > >iOS啟動APP,播放視訊,會出現黑屏

iOS啟動APP,播放視訊,會出現黑屏

建議換一下方式,親測有效

AVPlayerItem *item = [AVPlayerItemplayerItemWithURL:[[NSBundlemainBundle] URLForResource:@"q1111.mp4"withExtension:nil]];

// 3.建立AVPlayer

_player = [AVPlayerplayerWithPlayerItem:item];

// 4.新增AVPlayerLayer

AVPlayerLayer *playerLayer = [AVPlayerLayerplayerLayerWithPlayer:_player];

playerLayer.frame

= CGRectMake(0, 0, screenW, screenH);

playerLayer.videoGravity =AVLayerVideoGravityResizeAspectFill;

[self.view.layeraddSublayer:playerLayer];

[_player play];