如何在当前播放时间的基础上再增加5秒?
实际上这是我的代码:
CMTime currentTime = music.currentTime;我不能使用CMTimeGetSeconds(),因为我需要CMTime格式。
谢谢你的回答。
编辑:如何为CMTime设置变量?
发布于 2013-02-27 03:56:22
这里有一种方法:
CMTimeMakeWithSeconds(CMTimeGetSeconds(music.currentTime) + 5, music.currentTime.timescale);发布于 2013-02-28 07:20:06
优雅的方式是使用CMTimeAdd
CMTime currentTime = music.currentTime;
CMTime timeToAdd = CMTimeMakeWithSeconds(5,1);
CMTime resultTime = CMTimeAdd(currentTime,timeToAdd);
//then hopefully
[music seekToTime:resultTime];您可以通过以下方式创建CMTime结构
CMTimeMake
CMTimeMakeFromDictionary
CMTimeMakeWithEpoch
CMTimeMakeWithSeconds发布于 2015-03-31 21:18:06
在Swift中:
private extension CMTime {
func timeWithOffset(offset: TimeInterval) -> CMTime {
let seconds = CMTimeGetSeconds(self)
let secondsWithOffset = seconds + offset
return CMTimeMakeWithSeconds(secondsWithOffset, preferredTimescale: timescale)
}
}https://stackoverflow.com/questions/15098004
复制相似问题