Beispiel #1
0
        /// <summary>
        /// 播放下一首
        /// </summary>
        public async void SkipNext()
        {
            //TODO:判断播放模式
            //TODO:判断暂停状态
            //TODO:判断是播放列表还是电台
            PlaybackOperated?.Invoke(null, null);
            if (_isPlayingRadio)
            {
                await radio.PlayNext();

                PlayTrackInternal(radio.CurrentPlaying);
            }
            else
            {
                var list = PlaylistService.Instance;
                if (list.CurrentIndex == list.Count - 1)
                {
                    PlayTrack(0);
                }
                else
                {
                    PlayTrack(list.CurrentIndex + 1);
                }
            }
        }
Beispiel #2
0
        /// <returns>是否成功开始播放</returns>
        private bool PlayTrackInternal(SongModel song)
        {
            PlaybackOperated?.Invoke(song, null);
            // Start the background task if it wasn't running
            //if (!IsBackgroundTaskRunning || MediaPlayerState.Closed == CurrentPlayer.CurrentState)
            if (!IsBackgroundTaskRunning)
            {
                // First update the persisted start track
                SettingsService.Playback.Write("TrackId", song.MediaUri.ToString());
                SettingsService.Playback.Write("Position", new TimeSpan().ToString());

                // Start task
                StartBackgroundAudioTask();
                return(false);
            }
            else
            {
                //TODO: 增加如果播放不成功则刷新地址
                if (song.MediaUri == null)
                {
                    ExtensionMethods.InvokeAndWait(async() => song.MediaUri = new Uri(await Net.DataApi.GetDownloadLink(song, false)));
                }
                MessageService.SendMediaMessageToBackground(MediaMessageTypes.SetSong, song);
                MessageService.SendMediaMessageToBackground(MediaMessageTypes.StartPlayback);
                return(true);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 播放虾米内容,自动判断对象类型
 /// </summary>
 /// <param name="model"></param>
 public void PlayModel(object model)
 {
     PlaybackOperated?.Invoke(model, null);
     if (model == null)
     {
         return;
     }
     if (model is AlbumModel)
     {
         PlayAlbum(model as AlbumModel);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 播放上一首
        /// </summary>
        public void SkipPrevious()
        {
            if (_isPlayingRadio)
            {
                throw new InvalidOperationException("电台不支持上一首功能");
            }
            PlaybackOperated?.Invoke(null, null);
            var list = PlaylistService.Instance;

            if (list.CurrentIndex == 0)
            {
                PlayTrack(list.Count - 1);
            }
            else
            {
                PlayTrack(list.CurrentIndex - 1);
            }
        }