J. Joe
J. Joe

Reputation: 381

player.SetDataSource media play both of tracks at the same time?

protected override void OnCreate (Bundle savedInstanceState)
    {
        base.OnCreate (savedInstanceState);
        player = new MediaPlayer ();
//Next item event
        imgNext.Click+= delegate(object sender, EventArgs e) {
            NextTracks(mPosition);
        };

}

public void StartMedia(string url_string) {

        Load_Data ();
        seekBar.Progress = 0;
        seekBar.Max = 100;
        //player.Reset ();
        player.SetAudioStreamType (Stream.Music);
        player.SetDataSource(url_string);
        player.Prepare();
        player.Start ();
        imgPlayorPause.SetImageResource (Resource.Drawable.ic_pause_black_36dp);
        //UpdatedTimerTask ();



    }
public void NextTracks(int positon)
    {
        player = null;
        if (positon >= mListData.Count ()) {
            mPosition = 0;
        } else {
            mPosition++;

        }

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

Media play both old track and new track at the same time. How to set it as null.

Updated add code

Upvotes: 0

Views: 57

Answers (1)

Luis Beltran
Luis Beltran

Reputation: 1704

After you declare your class, add:

MediaPlayer player;

(it means it has to be outside any method, but inside the class). Then, inside OnCreate:

player=new MediaPlayer();

Finally, before you call player.Reset(), add a call to player.Stop();

Upvotes: 1

Related Questions