2013-02-26 154 views
13

मैं अपने वर्तमान बजाने के समय में 5 सेकंड कैसे जोड़ सकता हूं? क्योंकि मैं CMTime प्रारूप की जरूरतएवीप्लेयर - सीएमटाइम में सेकेंड जोड़ें

CMTime currentTime = music.currentTime; 

मैं CMTimeGetSeconds (का उपयोग नहीं कर सकते),:
असल में यह मेरा कोड है।

अपने जवाब के लिए धन्यवाद ...

संपादित करें: मैं CMTime के लिए एक चर सेट कर सकते हैं कैसे?

CMTimeMakeWithSeconds(CMTimeGetSeconds(music.currentTime) + 5, music.currentTime.timescale); 

उत्तर

21

यहाँ एक तरीका है यदि आप इनमें से

CMTimeMake 
CMTimeMakeFromDictionary 
CMTimeMakeWithEpoch 
CMTimeMakeWithSeconds 

अधिक से CMTime struct बना सकते हैं @ : https://developer.apple.com/library/mac/#documentation/CoreMedia/Reference/CMTime/Reference/reference.html

+0

बिल्कुल सही !!! धन्यवाद :) –

+0

जब मैं '5' के साथ '+ 5' को प्रतिस्थापित करता हूं तो यह काम नहीं कर रहा है ... क्या आप जानते हैं कि क्या गलत है? –

+0

सेकेंड में वर्तमान समय क्या है? शायद संख्या नकारात्मक हो जाती है? – BlueVoodoo

18

सुरुचिपूर्ण तरीका CMTimeAdd

CMTime currentTime = music.currentTime; 
CMTime timeToAdd = CMTimeMakeWithSeconds(5,1); 

CMTime resultTime = CMTimeAdd(currentTime,timeToAdd); 

//then hopefully 
[music seekToTime:resultTime]; 

उपयोग कर रहा है अपने संपादित करने के लिए:

+0

'AVPlayer' 'setCurrentTime' का जवाब नहीं दे सकता है –

+0

असंगत प्रकार 'NSTimeInterval' (उर्फ 'डबल') के पैरामीटर के लिए 'सीएमटाइम' भेजना –

+0

शायद आपको [संगीत तलाश टोटाइम: परिणाम समय] का उपयोग करना चाहिए – tomasgatial

2

स्विफ्ट में:

private extension CMTime { 

    func timeWithOffset(offset: NSTimeInterval) -> CMTime { 

     let seconds = CMTimeGetSeconds(self) 
     let secondsWithOffset = seconds + offset 

     return CMTimeMakeWithSeconds(secondsWithOffset, timescale) 

    } 

}