Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there a Play, Pause, Rewind, Fast Forward methods in Android?

Tags:

java

android

I am working on an Android application that allows the user to speak into the device. Then i want to save that, and rewind part of it to play it again, maybe fast forward to another part of the audio, pause it, play it, etc. Like a basic tape recorder.

Are there any built APIs or methods or code to allow this? If not, then where do I go from here?

Any help would be greatly appreciated.

like image 986
Zach Smith Avatar asked Sep 08 '11 21:09

Zach Smith


1 Answers

Using MediaPlayer you can seek to different positions in the stream but this is different from playing fast forward (or fast rewind), also known as "trick play" in DVRs.

However, fast forward can probably implemented using seekTo like this:

  • Set a periodic timer (ie postDelayed or scheduleAtFixedRate), every 100 msecs.
  • In timer's Runnable, call seekTo with a value that is a factor representing the play rate you want.
    • So if you want 2x fast forward then after every 100 msec period you will seek to curr_pos + 100 msecs. This means 100 msecs have passed but now you are at prev_pos + 200 msecs.
    • Performing 4x means after every 100 msec period you seek to curr_pos + 300 msecs.

.

  • I just realized that seekTo probably seeks to the nearest reference or I-frame. So calling seekTo(curr_pos + 100) may not get to the precise spot you want.

I might be required to implement FF in a video player I am working on. If I get it working I'll update my answer here.

like image 145
Peter Tran Avatar answered Oct 20 '22 11:10

Peter Tran