Trying to set playback rate on an mp3 file

Hello Everyone,

I am new to Xamarin and working on my first android app. I am using a MediaPlayer object to load an mp3 file and play it back. I would like to set the mp3 to playback at 2x speed. When I look at https://developer.xamarin.com/api/type/Android.Media.MediaPlayer/ it shows there is a method for setPlaybackRate but I do not have that method on my object. Any ideas how to set the playback rate for an audio track?

Thanks,
Andrew

Tagged:

Best Answer

Answers

  • ebetzlerebetzler USMember ✭✭

    +1 to this question

  • AndrewPHansonAndrewPHanson USMember ✭✭

    Bump. I'm still looking for the answer if anyone knows.

  • AndrewPHansonAndrewPHanson USMember ✭✭

    @AndrewPHanson said:
    It looks like you can create a PlaybackParams object and set the speed and pitch in there. You can then set the PlaybackParams object inside the MediaPlayer object to your created playbackParams.

            
    private MediaPlayer mediaPlayer;
    private PlaybackParams playbackParams;
                
    playbackParams.SetSpeed(2.0f);
    playbackParams.SetPitch(2.0f);            
                            
    mediaPlayer = new MediaPlayer();
    mediaPlayer.SetDataSource(path);
    mediaPlayer.PlaybackParams = playbackParams;
    

    I haven't been able to try it yet, but I'll give it a shot tonight and let you know if it works.

    I confirmed that this worked. Hope this helps someone else.

  • ebetzlerebetzler USMember ✭✭

    @AndrewPHanson said:

    @AndrewPHanson said:
    It looks like you can create a PlaybackParams object and set the speed and pitch in there. You can then set the PlaybackParams object inside the MediaPlayer object to your created playbackParams.

            
    private MediaPlayer mediaPlayer;
    private PlaybackParams playbackParams;
                
    playbackParams.SetSpeed(2.0f);
    playbackParams.SetPitch(2.0f);            
                            
    mediaPlayer = new MediaPlayer();
    mediaPlayer.SetDataSource(path);
    mediaPlayer.PlaybackParams = playbackParams;
    

    I haven't been able to try it yet, but I'll give it a shot tonight and let you know if it works.

    I confirmed that this worked. Hope this helps someone else.

    Works for >=6.0, but what about older APIs?

Sign In or Register to comment.