去掉对status的监听

This commit is contained in:
bluesea 2024-04-08 19:55:15 +08:00
parent 5377417a1e
commit 684a5f3cf0
4 changed files with 65 additions and 26 deletions

View File

@ -611,8 +611,8 @@
filePath = "SwiftProject/Project/Controller/RecordingVideo/CCSpatialVideoDisplayController/CCSpatialVideoDisplayController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "340"
endingLineNumber = "340"
startingLineNumber = "347"
endingLineNumber = "347"
landmarkName = "viewDidAppear(_:)"
landmarkType = "7">
</BreakpointContent>
@ -627,10 +627,42 @@
filePath = "SwiftProject/Project/Controller/RecordingVideo/CCSpatialVideoDisplayController/CCSpatialVideoDisplayController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "627"
endingLineNumber = "627"
startingLineNumber = "634"
endingLineNumber = "634"
landmarkName = "selectedSpatialType(selectedIndex:)"
landmarkType = "7">
<Locations>
<Location
uuid = "EF28D223-534C-4D5B-8564-50D9720BA766 - 6adcab4b430491b5"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "SwiftProject.CCSpatialVideoDisplayController.selectedSpatialType(selectedIndex: Swift.Int) -&gt; ()"
moduleName = "SwiftProject"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aaa/Documents/IOS%20Dev/VR/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/CCSpatialVideoDisplayController/CCSpatialVideoDisplayController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "632"
endingLineNumber = "632"
offsetFromSymbolStart = "56">
</Location>
<Location
uuid = "EF28D223-534C-4D5B-8564-50D9720BA766 - 6adcab4b430491b5"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "SwiftProject.CCSpatialVideoDisplayController.selectedSpatialType(selectedIndex: Swift.Int) -&gt; ()"
moduleName = "SwiftProject"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aaa/Documents/IOS%20Dev/VR/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/CCSpatialVideoDisplayController/CCSpatialVideoDisplayController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "632"
endingLineNumber = "632"
offsetFromSymbolStart = "52">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>

View File

@ -233,32 +233,39 @@ class CCSpatialVideoDisplayController: BaseController {
Task {
print("ccs viewdid load ---------")
await self.loadVideoAssetReader()
DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now()+0.2) {
self.configureInfo()
// AirPlay
self.checkAirPlayStatus()
}
// DispatchQueue.main.async {
//
// }
}
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
print("播放状态status改变....")
if(keyPath == "status"){
guard let ce = change else {
return
}
let newVa = ce[NSKeyValueChangeKey.newKey] as! AVPlayer.Status
let oldVa = ce[NSKeyValueChangeKey.oldKey] as! AVPlayer.Status
if (newVa != oldVa) {
if newVa == .readyToPlay {
player?.play()
}
}
}
}
// override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
// print("\(keyPath)...\(change).")
// if(keyPath == "status"){
// guard let ce = change else {
// return
// }
//
// let newVa = ce[NSKeyValueChangeKey.kindKey] as? Int
//
// if newVa != nil {
// if AVPlayer.Status(rawValue: newVa!) == .readyToPlay {
// DispatchQueue.main.async {[weak self] in
// print(">>>>>>bo fang....")
// self?.player?.play()
// }
// }
// }
//
//
//
// }
// }
func configureInfo(){
@ -266,7 +273,7 @@ class CCSpatialVideoDisplayController: BaseController {
player = AVPlayer()
player?.allowsExternalPlayback = true
player?.usesExternalPlaybackWhileExternalScreenIsActive = true
player?.addObserver(self, forKeyPath: "status", context: nil)
// player?.addObserver(self, forKeyPath: "status", context: nil)
print("getPlayerItem >>>>>>>")
self.view.backgroundColor = UIColor(hexString: "#060507")
@ -521,7 +528,7 @@ class CCSpatialVideoDisplayController: BaseController {
releaseVideoComposition()
assetReader?.cancelReading()
NotificationCenter.default.removeObserver(self)
player?.removeObserver(self, forKeyPath: "status")
// player?.removeObserver(self, forKeyPath: "status")
}
func releaseVideoComposition() {

View File

@ -157,7 +157,7 @@ extension CCSpatialVideoDisplayController {
//play
DispatchQueue.main.async {
self.player!.play()
self.player?.play()
print("资产加载完毕。。。。开始播放player\n err:\(self.player?.error)")
}