SetTrackAsCurrent() public method

public SetTrackAsCurrent ( IMediaFile item ) : void
item IMediaFile
return void
Beispiel #1
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);
        }
        /// <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));
            }
        }