2016-07-18 8 views
-1

Ich bekomme aktuellen Spielwert in Sekunden, aber ich brauche in Millisekunden. Ich habe versucht, currentTime.value/currentTime.scale. Aber es hat keinen genauen Wert bekommen. So millisecond nicht Sekunden
Wie bekomme ich aktuelle Spielzeit, CMTime in Millisekunden in AVPlayer?

, kann man einfach CMTimeGetSeconds verwenden (< #CMTime time #>) zu Sekunden erhalten
dann

CMTime currentTime = vPlayer.currentItem.currentTime; //playing time 
CMTimeValue tValue=currentTime.value; 
CMTimeScale tScale=currentTime.timescale; 

NSTimeInterval time = CMTimeGetSeconds(currentTime); 
NSLog(@"Time :%f",time);//This is in seconds, it misses decimal value double shot=(float)tValue/(float)tScale; 
shotTimeVideo=[NSString stringWithFormat:@"%.2f",(float)tValue/(float)tScale]; 

CMTime currentTime = vPlayer.currentItem.currentTime; //playing time 
CMTimeValue tValue=currentTime.value; 
CMTimeScale tScale=currentTime.timescale; 

NSTimeInterval time = CMTimeGetSeconds(currentTime); 
NSLog(@"Time :%f",time);//This is in seconds, it misses decimal value 
double shot=(float)tValue/(float)tScale; 
shotTimeVideo=[NSString stringWithFormat:@"%.2f", (float)tValue/(float)tScale]; 
+0

können Sie nicht zweite/1000? –

+0

@ HariKrishnan.P bist du sicher, dass du die Sekunden mit 1000 multiplizierst? lol ich bin verwirrt! Es sollte Sekunden sein/1000 –

+0

Millisekunden = Sekunden/1000. es ist richtig. Ich bin falsch zu schreiben –

Antwort

2

in Ordnung, vor allem, ist der Wert, den Sie möchten, wenn Sie wollen Millisekunden, die Verwendung Sekunden/1000.f für Schwimmer oder doppelten Wert

für cmtime Verwendung cmtime Methode
CMTimeMultiplyByRatio (< #CMTime tim Berechnung e #>, < # int32_t Multiplikator #>, < # int32_t Divisor #>)
nur tun dies -> CMTimeMultiplyByRatio (yourCMTimeValue, 1, 1000)

Apples Doc

@function CMTimeMultiplyByRatio 
@abstract Returns the result of multiplying a CMTime by an integer, then dividing by another integer. 
@discussion The exact rational value will be preserved, if possible without overflow. If an overflow 
      would occur, a new timescale will be chosen so as to minimize the rounding error. 
      Default rounding will be applied when converting the result to this timescale. If the 
      result value still overflows when timescale == 1, then the result will be either positive 
      or negative infinity, depending on the direction of the overflow. 

      If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be 
      set. This flag will also be set if the CMTime operand has kCMTimeFlags_HasBeenRounded set. 

      If the denominator, and either the time or the numerator, are zero, the result will be 
      kCMTimeInvalid. If only the denominator is zero, the result will be either kCMTimePositiveInfinity 
      or kCMTimeNegativeInfinity, depending on the signs of the other arguments. 

      If time is invalid, the result will be invalid. If time is infinite, the result will be 
      similarly infinite. If time is indefinite, the result will be indefinite.        


@result  (time * multiplier)/divisor 
+0

Ja, ich habe es nach dem Lesen über CMTime. Danke für die Antwort :) –

+1

Gesetze der Mathematik sagt Millisekunde wird abgerufen durch * multiplizieren * Sekunde mit 1000 – codelearner

+0

@codelearner emmm? Wenn wie gesagt 1 Millisekunde = 1 Sekunde 1000 multipliziert, wie sind 1000 Millisekunden gleich 1 Sekunde? –