AVPlayer 暂停不工作 TVOS
AVPlayer pause not working TVOS
我正在制作一个 tvOS 应用程序。我的应用程序中有两个选项卡 A
和 B
。假设视频正在 VC 中的选项卡 A
中播放。当我从 A->B
切换标签时,我想暂停当前播放的视频。我在 viewWillDisappear
中这样做,但视频只是第一次暂停。当我再次切换标签 B->A
并按下电视遥控器上的播放按钮时,它会播放,但如果我再次尝试切换标签 A->B
,视频会继续并且不会停止。
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
avplayerVC?.player?.rate = 0.0
print("Player Playing Rate : ", "\(avplayerVC?.player?.rate)")
}
我正在使用 avPlayer.pause() 方法和 avPlayer.rate = 0.0 来停止它,但是 none 每次都有效。
日志显示 Player Playing Rate : Optional(0.0)
。但视频实际上并没有暂停。这是我的完整代码。
class PlayViewController : UIViewController {
var avplayerVC : AVPlayerViewController?
var videoUrlStr : String?
override func viewDidLoad() {
super.viewDidLoad()
print("In PlayViewController View Did Load")
avplayerVC = AVPlayerViewController()
let avAsset = AVAsset(URL: NSURL.init(string: videoUrlStr!)!)
let avPlayerItem = AVPlayerItem(asset: avAsset)
avplayerVC?.player = AVPlayer(playerItem: avPlayerItem)
avplayerVC?.player?.seekToTime(kCMTimeZero)
print("Status 1: " + "\(avplayerVC?.player?.status.rawValue)")
print(self.view?.frame)
// doesn't work
avplayerVC?.view.frame = self.view.frame
self.view.addSubview((avplayerVC?.view!)!)
avplayerVC?.player?.play()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
print("Changing rate")
avplayerVC?.player?.rate = 0.0
print("Player Playing Rate : ", "\(avplayerVC?.player?.rate)")
}
}
任何帮助将不胜感激。
我和AVPlayerViewController
有同样的问题,也许我的回答对你有帮助:
我正在制作一个 tvOS 应用程序。我的应用程序中有两个选项卡 A
和 B
。假设视频正在 VC 中的选项卡 A
中播放。当我从 A->B
切换标签时,我想暂停当前播放的视频。我在 viewWillDisappear
中这样做,但视频只是第一次暂停。当我再次切换标签 B->A
并按下电视遥控器上的播放按钮时,它会播放,但如果我再次尝试切换标签 A->B
,视频会继续并且不会停止。
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
avplayerVC?.player?.rate = 0.0
print("Player Playing Rate : ", "\(avplayerVC?.player?.rate)")
}
我正在使用 avPlayer.pause() 方法和 avPlayer.rate = 0.0 来停止它,但是 none 每次都有效。
日志显示 Player Playing Rate : Optional(0.0)
。但视频实际上并没有暂停。这是我的完整代码。
class PlayViewController : UIViewController {
var avplayerVC : AVPlayerViewController?
var videoUrlStr : String?
override func viewDidLoad() {
super.viewDidLoad()
print("In PlayViewController View Did Load")
avplayerVC = AVPlayerViewController()
let avAsset = AVAsset(URL: NSURL.init(string: videoUrlStr!)!)
let avPlayerItem = AVPlayerItem(asset: avAsset)
avplayerVC?.player = AVPlayer(playerItem: avPlayerItem)
avplayerVC?.player?.seekToTime(kCMTimeZero)
print("Status 1: " + "\(avplayerVC?.player?.status.rawValue)")
print(self.view?.frame)
// doesn't work
avplayerVC?.view.frame = self.view.frame
self.view.addSubview((avplayerVC?.view!)!)
avplayerVC?.player?.play()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
print("Changing rate")
avplayerVC?.player?.rate = 0.0
print("Player Playing Rate : ", "\(avplayerVC?.player?.rate)")
}
}
任何帮助将不胜感激。
我和AVPlayerViewController
有同样的问题,也许我的回答对你有帮助: