player.SetDataSource媒体同时播放这两首曲目?

时间:2016-04-29 06:18:46

标签: xamarin xamarin.android

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);
    }

媒体同时播放旧曲目和新曲目。如何将其设置为null。

更新了添加代码

1 个答案:

答案 0 :(得分:1)

宣布课程后,请添加:

AlertDialog alertDialog = new AlertDialog.Builder(this).create();

(这意味着它必须在任何方法之外,但在课堂内)。然后,在OnCreate中:

MediaPlayer player;

最后,在致电player=new MediaPlayer();之前,请先致电player.Reset()