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

//Media
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.SetDataSource(url_string);
player.Prepare();
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 {
mPosition++;

    }
} else {
    mPosition = positon;
}

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

}

I have tried some ways such as:

player.Stop();
if (Isrepeat == false).......
or

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

Best Answer

Answers

  • 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);
    
  • VenkataSivaprasadReddyPulagamVenkataSivaprasadReddyPulagam ✭✭✭ USMember ✭✭✭

    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

  • VenkataSivaprasadReddyPulagamVenkataSivaprasadReddyPulagam ✭✭✭ USMember ✭✭✭

    @Englbach

    hi,
    Thank you for the reply....

Sign In or Register to comment.