gpt4 book ai didi

ios - 在 MPMoviePlayer 中获取视频的总播放时长

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

我需要获取有关使用 MPMoviePlayer 播放视频的总时间的信息。当用户观看 3 分钟的视频长达 2 分钟并向后移动到 1.30 并关闭视频时如何处理这种情况。要求是知道分数用户准确观看的视频。

最佳答案

来自 MPMoviePlayerController 上的 Apple 文档:

Movie Player Notifications

A movie player generates notifications to keep your app informed about the state of movie playback. In addition to being notified when playback finishes, your app can be notified in the following situations:

  • When the movie player begins playing, is paused, or begins seeking forward or backward

使用这些通知,您可以设置自己的计时器以了解视频已播放的总时间。具体来说,您可能需要 MPMoviePlayerPlaybackStateDidChangeNotification

了解观看视频的总百分比可能有点棘手,但我认为仍有可能。您需要注册 MPMediaPlayback 协议(protocol)并将其与上面提到的 PlaybackStateDidChangeNotification 结合使用。

我有一个想法(虽然可能不是最好或最有效的方法)是创建一个 BOOL 值数组,视频的每一秒 1。播放视频时,获取播放器上的 currentPlaybackTime 并在播放时标记每一秒。如果视频状态发生变化(暂停、快进等),停止标记它们直到它恢复,然后根据新的 currentPlaybackTime 从新索引开始并继续标记。完成后,计算已标记索引的百分比。

MPMoviePlayerController
MPMediaPlayback Protocol

如果这对你有用,请告诉我!

关于ios - 在 MPMoviePlayer 中获取视频的总播放时长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23427263/

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