简体   繁体   English

如何在iOS中使用AVPlayer的功能“ setRate”

[英]How to use AVPlayer's function “setRate” in iOS

This is a API document about setRate function in AVPlayer and I just don't understand the concept of this function. 这是有关AVPlayer中setRate函数的API文档,我只是不了解此函数的概念。

itemTime and hostClockTime? itemTime和hostClockTime? What are they? 这些是什么? When do I need them? 我什么时候需要它们?

Can you give me a example of using those parameters? 您能给我一个使用这些参数的例子吗?

/*!
    @method         setRate:time:atHostTime:
    @abstract       Simultaneously sets the playback rate and the relationship between the current item's current time and host time.
    @discussion     You can use this function to synchronize playback with an external activity.

                    The current item's timebase is adjusted so that its time will be (or was) itemTime when host time is (or was) hostClockTime.
                    In other words: if hostClockTime is in the past, the timebase's time will be interpolated as though the timebase has been running at the requested rate since that time.  If hostClockTime is in the future, the timebase will immediately start running at the requested rate from an earlier time so that it will reach the requested itemTime at the requested hostClockTime.  (Note that the item's time will not jump backwards, but instead will sit at itemTime until the timebase reaches that time.)

                    Note that advanced rate control is not currently supported for HTTP Live Streaming.
    @param itemTime The time to start playback from, specified precisely (i.e., with zero tolerance).
                    Pass kCMTimeInvalid to use the current item's current time.
    @param hostClockTime
                    The host time at which to start playback.
                    If hostClockTime is specified, the player will not ensure that media data is loaded before the timebase starts moving.
                    If hostClockTime is kCMTimeInvalid, the rate and time will be set together, but without external synchronization;
                    a host time in the near future will be used, allowing some time for data media loading.
*/

As the documentation describes, you use this function to synchronize playback with an external activity. 如文档所述,您可以使用此功能将回放与外部活动同步。

In this question here AVPlayer not synchronized the user (in their answer) is using the same function to synchronize the playback of three separate videos (making sure they all play back at exactly the same rate and remain in synch). 在此问题中, AVPlayer未同步用户(在他们的答案中),该用户使用相同的功能来同步三个单独视频的播放(确保它们以完全相同的速率播放并保持同步)。

You can also adjust the rate to speed up or slow down video playback (a "sort of" slow motion for example). 您还可以调整速率以加快或减慢视频播放速度(例如,“某种”慢动作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM