2016-07-18 3 views
-1

Я получаю текущее значение воспроизведения в секундах, но мне нужно в миллисекундах. Я попробовал currentTime.value/currentTime.scale. Но он не получил точной стоимости.Как получить текущее время воспроизведения, CMTime в миллисекундах в AVPlayer?

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

вы не можете сделать второй/1000? –

+0

@ HariKrishnan.P Вы уверены, что умножаете секунды на 1000? lol Я в замешательстве! Это должно быть секунды/1000 –

+0

miliseconds = секунды/1000. его правильный. Я ошибаюсь, чтобы написать –

ответ

2

хорошо, прежде всего, значение, которое вы хотите, millisecond не секунды

Таким образом, вы можете просто использовать CMTimeGetSeconds (< #CMTime время #>) получить Секунды
тогда, если вы хотите миллисекунду, использование секунд/1000.f для поплавка или двойного значения

для CMTime расчета метод использования CMTime
CMTimeMultiplyByRatio (< #CMTime тим е #>, < # int32_t мультипликатора #>, < # int32_t делителем #>)
просто сделать это -> CMTimeMultiplyByRatio (yourCMTimeValue, 1, 1000)

Doc компании Apple

@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

Да, я получил его после прочтения о CMTime. Спасибо за ответ :) –

+1

Законы математики говорят, что миллисекунда извлекается * умножением * второй с 1000 – codelearner

+0

@codelearner emmm? Если, как вы сказали, 1 миллисекунда = 1 секунда, умножая 1000, как 1000 миллисекунд равна 1 секунде? –

Смежные вопросы