예제 #1
0
 private void OnMediaFileChanged(object sender, MediaFileChangedEventArgs e)
 {
     if (CurrentMediaFile?.Url == e?.File?.Url)
     {
         MediaNotificationManager?.UpdateNotifications(e?.File, Status);
     }
     MediaFileChanged?.Invoke(sender, e);
 }
 private void OnStatusChanged(object sender, StatusChangedEventArgs e)
 {
     if (sender != CurrentPlaybackManager)
     {
         return;
     }
     MediaNotificationManager?.UpdateNotifications(MediaQueue.Current, e.Status);
     StatusChanged?.Invoke(sender, e);
 }
예제 #3
0
        /// <summary>
        /// Adds all MediaFiles to the Queue and starts playing the first item
        /// </summary>
        /// <param name="mediaFiles"></param>
        /// <returns></returns>
        public async Task Play(IEnumerable <IMediaFile> mediaFiles)
        {
            MediaQueue.Clear();
            MediaQueue.AddRange(mediaFiles);

            await PlayNext();

            MediaNotificationManager?.StartNotification(CurrentMediaFile);
        }
예제 #4
0
        public async Task Seek(TimeSpan position)
        {
            if (CurrentPlaybackManager == null)
            {
                return;
            }
            await CurrentPlaybackManager.Seek(position);

            MediaNotificationManager?.UpdateNotifications(CurrentMediaFile, Status);
        }
예제 #5
0
        public async Task Stop()
        {
            if (CurrentPlaybackManager == null)
            {
                return;
            }
            await CurrentPlaybackManager.Stop();

            MediaNotificationManager?.StopNotifications();
        }
예제 #6
0
        /// <summary>
        /// Adds all MediaFiles to the Queue and starts playing the first item
        /// </summary>
        /// <param name="mediaFiles"></param>
        /// <returns></returns>
        public async Task Play(IEnumerable <IMediaFile> mediaFiles)
        {
            MediaQueue.Clear();
            MediaQueue.AddRange(mediaFiles);

            // Play from index 0
            MediaQueue.SetIndexAsCurrent(0);
            await PlayCurrent();

            MediaNotificationManager?.StartNotification(CurrentMediaFile);
        }
        /// <summary>
        /// Adds all MediaFiles to the Queue and starts playing the first item
        /// </summary>
        /// <param name="mediaFiles"></param>
        /// <returns></returns>
        public async Task Play(IEnumerable <IMediaFile> mediaFiles)
        {
            var enumerable = mediaFiles as IList <IMediaFile> ?? mediaFiles.ToList();

            MediaQueue.Clear();
            MediaQueue.AddRange(enumerable);

            await Task.WhenAll(
                PlayNext(),
                GetMediaInformation(enumerable),
                Task.Run(() => MediaNotificationManager?.StartNotification(MediaQueue.Current)));
        }
예제 #8
0
        private void OnPlayingChanged(object sender, PlayingChangedEventArgs e)
        {
            if (sender == CurrentPlaybackManager)
            {
                if (!_startedPlaying && Duration != TimeSpan.Zero)
                {
                    MediaNotificationManager?.UpdateNotifications(MediaQueue.Current, Status);
                    _startedPlaying = true;
                }

                PlayingChanged?.Invoke(sender, e);
            }
        }
예제 #9
0
        private void OnStatusChanged(object sender, StatusChangedEventArgs e)
        {
            if (sender != CurrentPlaybackManager)
            {
                return;
            }

            if (Status == MediaPlayerStatus.Playing)
            {
                _startedPlaying = false;
            }

            MediaNotificationManager?.UpdateNotifications(CurrentMediaFile, e.Status);
            StatusChanged?.Invoke(sender, e);
        }
예제 #10
0
        public async Task Play(IMediaFile mediaFile = null)
        {
            if (mediaFile == null)
            {
                if (Status == MediaPlayerStatus.Paused)
                {
                    await Resume();

                    return;
                }

                mediaFile = CurrentMediaFile;
            }

            if (_currentPlaybackManager != null && Status == MediaPlayerStatus.Failed)
            {
                await PlayNext();

                return;
            }

            if (mediaFile == null)
            {
                await Play(MediaQueue);

                return;
            }

            if (!MediaQueue.Contains(mediaFile))
            {
                MediaQueue.Add(mediaFile);
            }

            MediaQueue.SetTrackAsCurrent(mediaFile);

            await RaiseMediaFileFailedEventOnException(async() =>
            {
                await PlayCurrent();
            });

            MediaNotificationManager?.StartNotification(mediaFile);
        }
예제 #11
0
        /// <summary>
        /// Adds MediaFile to the Queue and starts playing
        /// </summary>
        /// <param name="mediaFile"></param>
        /// <returns></returns>
        public async Task Play(IMediaFile mediaFile)
        {
            if (_currentPlaybackManager != null && Status == MediaPlayerStatus.Failed)
            {
                await PlayNext();

                return;
            }

            if (mediaFile == null)
            {
                await Play(MediaQueue);

                return;
            }

            if (!MediaQueue.Contains(mediaFile))
            {
                MediaQueue.Add(mediaFile);
            }

            MediaQueue.SetTrackAsCurrent(mediaFile);

            try
            {
                var beforePlayTask = _onBeforePlay?.Invoke(_currentMediaFile);
                if (beforePlayTask != null)
                {
                    await beforePlayTask;
                }
                await CurrentPlaybackManager.Play(mediaFile);
                await GetMediaInformation(new[] { mediaFile });

                MediaNotificationManager?.StartNotification(mediaFile);
            }
            catch (Exception ex)
            {
                OnMediaFileFailed(this, new MediaFileFailedEventArgs(ex, mediaFile));
            }
        }
        public async Task Stop()
        {
            await CurrentPlaybackManager.Stop();

            MediaNotificationManager?.StopNotifications();
        }