开发者

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

I am working on an Android appl开发者_如何学Pythonication 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.


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.


Yes there are. Look at the MediaPlayer class:

http://developer.android.com/reference/android/media/MediaPlayer.html


Use AudioRecorder to record data. Use PCM format.

Then you can play it selectivelly via AudioTrack.


//Test Below Cod

double duration = mediaPlayer.getCurrentTime().toSeconds();
if (e.getKeyCode()==39)
{

    if (duration < mediaPlayer.getTotalDuration().toSeconds()-5)
        duration = duration + 5;
    else
        duration = mediaPlayer.getTotalDuration().toSeconds();
    //...
    mediaPlayer.setStartTime(Duration.seconds(duration));

}else
if (e.getKeyCode()==37)
{
    if (duration > 5)
        duration = duration - 5;
    else
        duration = 0;
    //...
    mediaPlayer.setStartTime(Duration.seconds(duration));
}                    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜