private void ToggleShuffle()
 {
     if (!_isShuffled)
     {
         shufflePlaylist(_index);
         _isShuffled = true;
     }
     else
     {
         var index = _nonShuffledPlaylist.IndexOf(CurrentMedia);
         _playlist   = _nonShuffledPlaylist;
         _index      = index;
         _isShuffled = false;
     }
     OnPlaylistChanged?.Invoke();
 }
Exemple #2
0
        private async Task SetMedia(IMediaItem media, bool autoPlay = true)
        {
            if (media == null)
            {
                throw new ArgumentNullException(nameof(media), "Media is missing. Can't play");
            }

            if (Playlist.ElementAt(CurrentMedia) != null)
            {
                Stop();
            }

            if (media is VideoItem || media is TrackItem)
            {
                StorageFile currentFile;
                try
                {
                    currentFile = media.File ?? await StorageFile.GetFileFromPathAsync(media.Path);
                }
                catch (Exception exception)
                {
                    Playback_MediaFileNotFound?.Invoke(media);
                    return;
                }
            }

            if (media is VideoItem)
            {
                var video = (VideoItem)media;
                await InitializePlayback(video, autoPlay);

                var roamFile = await ApplicationData.Current.RoamingFolder.TryGetItemAsync("roamVideo.txt");

                if (roamFile != null)
                {
                    var roamVideos = await FileIO.ReadLinesAsync(roamFile as StorageFile);

                    if (roamVideos.Any())
                    {
                        if (roamVideos[0] == media.Name)
                        {
                            int leftTime = 0;
                            if (int.TryParse(roamVideos[1], out leftTime))
                            {
                                video.TimeWatchedSeconds = leftTime;
                            }
                        }
                    }
                }

                if (video.TimeWatched != TimeSpan.FromSeconds(0))
                {
                    SetTime((long)video.TimeWatched.TotalMilliseconds);
                }

                TileHelper.UpdateVideoTile();
            }
            else if (media is TrackItem)
            {
                var track = (TrackItem)media;
                await InitializePlayback(track, autoPlay);

                int index = IsShuffled ?
                            NonShuffledPlaylist.IndexOf(Playlist[CurrentMedia]): CurrentMedia;
                ApplicationSettingsHelper.SaveSettingsValue(nameof(CurrentMedia), index);
            }
            else if (media is StreamMedia)
            {
                await InitializePlayback(media, autoPlay);
            }
        }