添加avplayercontroler,实现播放控制,但还需进一步实现控制下的边转边播数据流对应

This commit is contained in:
bluesea 2024-03-13 11:02:38 +08:00
parent 5b2f052ad3
commit 271d5ca96b
2 changed files with 20 additions and 15 deletions

View File

@ -86,9 +86,9 @@ class CCSpatialVideoDisplayController: BaseController {
var player:AVPlayer? var player:AVPlayer?
var playerLay:AVPlayerLayer? // var playerLay:AVPlayerLayer?
var playerController:AVPlayerViewController?
lazy var mTopImgView:UIImageView = { lazy var mTopImgView:UIImageView = {
//393*236 //393*236
@ -225,13 +225,18 @@ class CCSpatialVideoDisplayController: BaseController {
// navtionBar?.addSubview(backButton) // navtionBar?.addSubview(backButton)
navtionBar?.addSubview(transformButton) navtionBar?.addSubview(transformButton)
navtionBar?.addSubview(mTopCenterTypeButton) navtionBar?.addSubview(mTopCenterTypeButton)
self.view.addSubview(progressView) // self.view.addSubview(progressView)
playerLay = AVPlayerLayer(player: self.player) // playerLay = AVPlayerLayer(player: self.player)
playerLay!.backgroundColor = UIColor.clear.cgColor // playerLay!.backgroundColor = UIColor.clear.cgColor
playerLay!.frame = CGRect.init(x: 0, y: 250, width: self.view.frame.size.width, height: 240) // playerLay!.frame = CGRect.init(x: 0, y: 250, width: self.view.frame.size.width, height: 240)
self.view.layer.addSublayer(playerLay!) playerController = AVPlayerViewController()
playerController?.player = player
playerController!.view.backgroundColor = .clear
playerController?.view.frame = CGRect.init(x: 0, y: 170, width: self.view.frame.size.width, height: 400)
self.addChild(playerController!)
self.view.addSubview(playerController!.view)
self.view.addSubview(tipsButton) self.view.addSubview(tipsButton)
@ -325,8 +330,8 @@ class CCSpatialVideoDisplayController: BaseController {
print("已连接") print("已连接")
link = true link = true
isPlaying = true isPlaying = true
playerLay!.player!.usesExternalPlaybackWhileExternalScreenIsActive = true playerController!.player!.usesExternalPlaybackWhileExternalScreenIsActive = true
playerLay!.player!.allowsExternalPlayback = true playerController!.player!.allowsExternalPlayback = true
// //
// mTopCenterTypeButton.setTitle("", for: UIControl.State.normal) // mTopCenterTypeButton.setTitle("", for: UIControl.State.normal)
@ -356,8 +361,8 @@ class CCSpatialVideoDisplayController: BaseController {
link = false link = false
isPlaying = false isPlaying = false
// AirPlay // AirPlay
playerLay!.player!.usesExternalPlaybackWhileExternalScreenIsActive = false playerController!.player!.usesExternalPlaybackWhileExternalScreenIsActive = false
playerLay!.player!.allowsExternalPlayback = false playerController!.player!.allowsExternalPlayback = false
if self.selectedIndex == .monocular2D { if self.selectedIndex == .monocular2D {
mTopCenterTypeButton.setTitle("单眼2D", for: UIControl.State.normal) mTopCenterTypeButton.setTitle("单眼2D", for: UIControl.State.normal)
@ -455,11 +460,11 @@ class CCSpatialVideoDisplayController: BaseController {
isPlaying = !isPlaying isPlaying = !isPlaying
if(isPlaying == true){ if(isPlaying == true){
// AirPlay // AirPlay
playerLay!.player!.usesExternalPlaybackWhileExternalScreenIsActive = true playerController!.player!.usesExternalPlaybackWhileExternalScreenIsActive = true
playerLay!.player!.allowsExternalPlayback = true playerController!.player!.allowsExternalPlayback = true
}else{ }else{
playerLay!.player!.usesExternalPlaybackWhileExternalScreenIsActive = false playerController!.player!.usesExternalPlaybackWhileExternalScreenIsActive = false
playerLay!.player!.allowsExternalPlayback = false playerController!.player!.allowsExternalPlayback = false
} }
} }