Getting accurate time from FFMPeg with Objective C (Audio Queue Services)
M开发者_JS百科y iPhone app plays an audio file using FFMPeg.
I'm getting the elapsed time (to show to user) from the playing audio (in minutes and seconds after converting from microseconds, given by FFMPeg) like so:
AudioTimeStamp currentTimeStamp;
AudioQueueGetCurrentTime (audioQueue, NULL, ¤tTimeStamp, NULL);
getFFMPEGtime = currentTimeStamp.mSampleTime/self.basicAudioDescription.mSampleRate;
self.currentAudioTime = [NSString stringWithFormat: @"%02d:%02d",
(int) getFFMPEGtime / (int)60000000,
(int) ((getFFMPEGtime % 60000000)/1000000)];
Everything works fine, but when I scrub back or forward to play another portion of the song, the elapsed time will go back to zero, no matter the current position. The timer will always zero out.
I know I'm suposed to do some math to keep track of the old time and the new time, maybe constructing another clock or so, perhaps implementing another callback function, etc... I'm not sure what way I should go.
My questions are:
1) What's the best approach to keep track of the elapsed time when going back/forward in a song, avoiding the clock to always going back to zero?
2) Should I look deeply into FFMPeg functions or should I stick with Objective-C and Cocoa Touch for solving this problem?
Please, I need some advices/ideas from experienced programmers. I'm stuck. Thanks beforehand!
If you're doing this to show elapsed time in the media to the user (which the fact you're turning it into a formatted string suggests), then you should instead query the playback system you're using for the time it thinks it is at in the file. The audio queue is completely unaware of your media so you'll have to duplicate work done by the playback system to map it to a media time. Timestamps from the audio queue are more like a high accuracy clock for things like A/V sync.
精彩评论