gpt4 book ai didi

ios - 检测 AVPlayerViewController 何时关闭

转载 作者:行者123 更新时间:2023-12-02 01:42:38 30 4
gpt4 key购买 nike

在表格 View 单元格中,我从 url 播放视频:

        let player = AVPlayer(url: URL(string: "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8")!)
player.automaticallyWaitsToMinimizeStalling = false

let vc = AVPlayerViewController()
vc.player = player

// Loop video
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) { [weak self] _ in
player.seek(to: CMTime.zero)
player.play()
}

self.parentViewController.present(vc, animated: true, completion: {
if #available(iOS 10.0, *) {
vc.player?.playImmediately(atRate: 1.0)
} else {
vc.player?.play()
}
})

如何检测 AVPlayerViewController 何时关闭/关闭?我想在它关闭时做点什么。

最佳答案

当 AVPlayerViewController 被关闭时,我不知 Prop 体的 delegatenotification

但是,您可以尝试以下步骤,因为您展示了 AVPlayerViewController

<强>1。符合 UIViewControllerTransitioningDelegate

使 呈现 AVPlayerViewControllerUIViewController 符合转换委托(delegate)

class YourVC: UIViewController, UIViewControllerTransitioningDelegate

<强>2。 AVPlayerController 设置

使呈现 AVPlayerController 的 View Controller 成为 AVPlayerControllertransitioningDelegate

let vc = AVPlayerViewController()

// Add this
vc.transitioningDelegate = self

vc.player = player

<强>3。最后实现transition委托(delegate)函数

// MARK: UIViewControllerTransitioningDelegate
// Gets called when a modal was dismissed
func animationController(forDismissed dismissed: UIViewController)
-> UIViewControllerAnimatedTransitioning?
{
// The dismissal was before the movie ended
print("AVPlayerController dismissed")
return nil
}

试一试,看看是否有帮助

关于ios - 检测 AVPlayerViewController 何时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71401679/

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