video暂停时,AVPlayer Fairplay HLS不会停止audio播放
尽pipe我试图只select与在线Fairplay Streaming相关的部分,而不是持久性/离线播放,但我正在使用Apple的Fairplay Streaming示例代码在https://developer.apple.com/streaming/fps/上使用Fairplay实现。 在下面的代码中,没有Fairplay的video播放/暂停/寻找正常,但是当我播放Fairplay保护的video时,只有video轨道的行为正确。
暂停播放不会停止audio播放,更改音轨不会停止以前的音轨,所以两个播放,也许寻找也不起作用。
除了这个帮助类以外,我还从Apple的FairPlay Streaming Server SDK的客户端示例代码中获得了AssetLoaderDelegate
和AssetPlaybackManager
,我已经更新了代码来处理我们的DRM密钥的SPC / CKC供应商。
我是否想要实现代码的一些重要部分来处理FPSstream媒体的audio? 你能指点我正确的方向吗? 非常感谢。
class PlayHelper { static let shared = PlayHelper() fileprivate var playerViewController: PlayerViewController? init() { AssetPlaybackManager.sharedManager.delegate = self } // Play video without DRM func playVideo(from urlString: String, at context: UIViewController) { guard let videoURL = URL(string: urlString) else { Log.error("Video URL can't be created from string: \(urlString)") return } let player = AVPlayer(url: videoURL) let playerViewController = PlayerViewController() playerViewController.player = player context.present(playerViewController, animated: true) { playerViewController.player?.play() } } // Play FPS video func playFpsVideo(with asset: AVURLAsset, at context: UIViewController) { // Cleanup, should be done when playerViewController is actually dismissed if self.playerViewController != nil { // The view reappeared as a results of dismissing an AVPlayerViewController. // Perform cleanup. AssetPlaybackManager.sharedManager.setAssetForPlayback(nil) self.playerViewController?.player = nil self.playerViewController = nil } let item = AVPlayerItem(asset: asset) let player = AVPlayer(playerItem: item) // Customize player player.appliesMediaSelectionCriteriaAutomatically = true let playerViewController = PlayerViewController() playerViewController.player = player self.playerViewController = playerViewController context.present(playerViewController, animated: true) { playerViewController.player?.play() } } // Stop video func stop() { // Cleanup, should be done when playerViewController is dismissed if self.playerViewController != nil { // Results of dismissing an AVPlayerViewController, perform cleanup AssetPlaybackManager.sharedManager.setAssetForPlayback(nil) self.playerViewController?.player = nil self.playerViewController = nil } } } // MARK: - Extend `PlayHelper` to conform to the `AssetPlaybackDelegate` protocol extension PlayHelper: AssetPlaybackDelegate { func streamPlaybackManager(_ streamPlaybackManager: AssetPlaybackManager, playerReadyToPlay player: AVPlayer) { player.play() } func streamPlaybackManager(_ streamPlaybackManager: AssetPlaybackManager, playerCurrentItemDidChange player: AVPlayer) { guard let playerViewController = playerViewController, player.currentItem != nil else { return } playerViewController.player = player } }
如果需要,我也可以在AssetLoaderDelegate
和AssetPlaybackManager
提供代码。
我的错。 我在上面的代码中调用了play()
两次… Grrr ..一次PlayerViewController
完成,第二次在由AssetPlaybackDelegate
中的KVO触发的AssetPlaybackDelegate
的callback中。 这样玩家控制停止播放video,但很可能是第二个(audio)stream仍然在那里播放。 我删除了playerReadyToPlay
callback中的play()
,现在播放器中的所有控件都按预期工作。 我可以暂停,恢复,寻找,改变音轨。
- iOS – 缩放和裁剪CMSampleBufferRef / CVImageBufferRef
- 捕捉照片时切换AVCaptureSession预设
- 如何在EXIF中logging制造商注释或用户注释?
- AVFoundation – 反转AVAsset并输出video文件
- UIWebView:当应用程序进入后台时,HTML5audio会在iOS 6中暂停
- AVAssetExportSession – 在IOS中join2个mp4文件
- 使用AVPlayer和AVMutableComposition进行未alignment的声音播放
- CVPixelBuffer到CIImage总是返回零
- iPhone 7 Plus – AVFoundation双摄像头