IOS AVPlayViewController 实现视频播放的控制

1 import UIKit
2 import AVFoundation
3 import AVKit
4
5 class ViewController:UIViewController {
6 override func viewDidLoad() {
7 super.viewDidLoad()
8 // Do any additional setup after loading the view,
typically from a nib.
9 let moviePath =
Bundle.main.path(forResource:“Sunrise”, ofType:“mp4”)
10 let movieURL = URL(fileURLWithPath:moviePath!)
11
12 let avPlayer = AVPlayer(url:movieURL as URL)
13 let playerVC = AVPlayerViewController()
14 playerVC.player = avPlayer
15 playerVC.videoGravity =
AVLayerVideoGravityResizeAspect;
16 playerVC.allowsPictureInPicturePlayback = true
17 playerVC.showsPlaybackControls = true
18 playerVC.view.frame = self.view.bounds
19
20 playerVC.player!.play()
21 self.view.addSubview(playerVC.view);
22 }
23 }

//配置画中画功能
为了激活在iPad中视频播放的画中画功能,还需要对项目进行一些
设置操作。首先点击项目设置页面中的【Capabilities】标签进行
Capabilities设置面板,然后激活【Background Modes】选项,并勾选
【Audio, AirPlay and Picture in Picture】选项

你可能感兴趣的:(IOS AVPlayViewController 实现视频播放的控制)