gpt4 book ai didi

ios - AVPlayer Fairplay HLS 不会在视频暂停时停止音频播放

转载 作者:行者123 更新时间:2023-11-29 11:47:08 34 4
gpt4 key购买 nike

我正在按照 Apple 的 Fairplay Streaming 示例代码使用 Fairplay 实现,网址为 https://developer.apple.com/streaming/fps/ ,尽管我试图只选择与 Online Fairplay Streaming 相关的部分,而不是持久性/离线播放。在下面的代码中,没有 Fairplay 的视频可以正常播放/暂停/搜索,但是当我播放受 Fairplay 保护的视频时,只有视频轨道可以正常运行。

暂停播放不会停止音频播放,更改音轨不会停止前一个音轨,所以两者一起播放,也许搜索也不起作用。

除了下面这个帮助类之外,我还有 AssetLoaderDelegateAssetPlaybackManager 来自 Apple 的 FairPlay Streaming Server SDK 客户端示例代码 https://developer.apple.com/streaming/fps/并且我已经更新了代码来为我们的 DRM key 提供商处理 SPC/CKC。

我是否错过了实现代码的某些重要部分来处理 FPS 流式传输的音频?你能给我指出正确的方向吗?非常感谢。

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
}
}

如果需要,我还可以在 AssetLoaderDelegateAssetPlaybackManager 中提供代码。

最佳答案

我的错。我在上面的代码中调用了两次 play()...Grrr.. 一次是 PlayerViewController 的显示完成,第二次是在 AssetPlaybackDelegate< 的回调中AssetPlaybackManager 中的 KVO 触发。这样播放器控件停止播放视频,但很可能还有第二个(音频)流在那里播放。我在 playerReadyToPlay 回调中删除了 play(),现在 Player 中的所有控件都按预期工作。我可以暂停、继续、搜索、更改音轨。

关于ios - AVPlayer Fairplay HLS 不会在视频暂停时停止音频播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43147627/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com