public void OnPrepared(MediaPlayer mp) { player.Start(); MusicControls.songName.Text = Songleton.Instance[SongPos].Title; MusicControls.songDuration.Text = getTime(player.Duration); MusicControls.ThreadHandler(0); }
public void PlaySong() { if (MusicControls.musicThread.IsAlive) { MusicControls.ThreadHandler(1); } player.Reset(); //是因为以下没在主页展示,所以调用时为空指针,报错。先生成再播放 MusicControls.imgPlay.SetImageResource(MusicControls.PAUSE_RESOURCE); var trackUri = ContentUris.WithAppendedId(MediaStore.Audio.Media.ExternalContentUri, Songleton.Instance[SongPos].Id); try { player.SetDataSource(Application.Context, trackUri); } catch (Exception e) { Log.Error(MainActivity.MUSIC_ERR_TAG, "Error setting data source", e); } player.PrepareAsync(); }