AVPlayer - Add Seconds to CMTime

前端 未结 4 1049
说谎
说谎 2021-02-12 15:21

How can I add 5 seconds to my current playing Time?
Actually this is my code:

CMTime currentTime = music.currentTime;

I can´t use CMTimeGet

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-12 15:35

    elegant way is using CMTimeAdd

    CMTime currentTime = music.currentTime;
    CMTime timeToAdd   = CMTimeMakeWithSeconds(5,1);
    
    CMTime resultTime  = CMTimeAdd(currentTime,timeToAdd);
    
    //then hopefully 
    [music seekToTime:resultTime];
    

    to your edit: you can create CMTime struct by these ways

    CMTimeMake
    CMTimeMakeFromDictionary
    CMTimeMakeWithEpoch
    CMTimeMakeWithSeconds
    

    more @: https://developer.apple.com/library/mac/#documentation/CoreMedia/Reference/CMTime/Reference/reference.html

提交回复
热议问题