的MediaPlayer在Android的速度控制速度、MediaPlayer、Android

由网友(幹幹凈凈旳心)分享简介:我开发一个播放器应用程序。我使用的MediaPlayer为。I am developing a player app. I am using MediaPlayer for that.现在我想改变播放曲目的速度。 Now I want to change the speed of playing track....

我开发一个播放器应用程序。我使用的MediaPlayer为。

I am developing a player app. I am using MediaPlayer for that.

现在我想改变播放曲目的速度。

Now I want to change the speed of playing track.

我已经看到了这个功能,所以许多应用程序。我怎样才能做到这一点?

I've seen so many apps with this functionality. How can I do this?

请帮我。

感谢您

推荐答案

在 MediaPlayer的不提供此功能,但拥有的Soundpool此功能。 该的Soundpool类有一个名为 setRate法(INT流ID,浮动利率)。如果你有兴趣的API这里看看。

The MediaPlayer does not provide this feature but SoundPool has this functionality. The SoundPool class has a method called setRate (int streamID, float rate). If you are interested in the API have a look here.

这个片段将正常工作。

 float playbackSpeed=1.5f; 
 SoundPool soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);

 soundId = soundPool.load(Environment.getExternalStorageDirectory()
                         + "/sample.3gp", 1);
 AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
 final float volume = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

 soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener()
 {
     @Override
     public void onLoadComplete(SoundPool arg0, int arg1, int arg2)
     {
         soundPool.play(soundId, volume, volume, 1, 0, playbackSpeed);
     }
 });
阅读全文

相关推荐

最新文章