Forum Xamarin.Android

Media always get error at Prepare method when Media next track

EnglbachEnglbach VNMember ✭✭

Error: has been thrown( A Java.Lang.IllegalStateException was thrown)

In OnCreate

player = new MediaPlayer ();
player.Stop ();
public void StartMedia(string url_string)
Load_Data ();
seekBar.Max = player.Duration;

player.Stop ();
player.Reset ();
player.SetAudioStreamType (Stream.Music);
player.Start ();
imgPlayorPause.SetImageResource (Resource.Drawable.ic_pause_black_36dp);
//UpdatedTimerTask ();
UpdateProcessBar ();


When I click button then next track. But that will show a error at player.Prepare();

public void NextTracks(int positon)
if (Isrepeat == false) {
if (positon >= mListData.Count ()) {
mPosition = 1;
} else {

} else {
    mPosition = positon;

StartMedia(mListData [mPosition].stream_url + "?client_id=" + clienId);


I have tried some ways such as:

if (Isrepeat == false).......

player=new MediaPlayer();
if (Isrepeat == false)....

Best Answer


  • D3nnisD3nnis USUniversity ✭✭✭

    You should put player.SetDataSource(url_string); before player.SetAudioStreamType (Stream.Music);

  • EnglbachEnglbach VNMember ✭✭

    @D3nnis said:
    You should put player.SetDataSource(url_string); before player.SetAudioStreamType (Stream.Music);

    I still get this problem...

  • D3nnisD3nnis USUniversity ✭✭✭
    edited May 2016

    Try to put the url_string in a Uri first:

        Android.Net.Uri uri = Android.Net.Uri.Parse (url_string);
        player.SetDataSource (this, uri);
  • hi friends
    i have a problem with media player code
    how to get total audio or video length (total play time) of a music or video clip
    both in uri streaming and url streaming

  • @Englbach

    Thank you for the reply....

Sign In or Register to comment.