Ejemplo n.º 1
0
        private async Task SetMedia(IMediaItem media)
        {
            if (media == null)
            {
                throw new ArgumentNullException(nameof(media), "Media is missing. Can't play");
            }

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

            await LogHelper.ResetBackendFile();

            // Send the media we want to play
            await SetMediaFile(media);

            if (_mediaPlayer == null)
            {
                return;
            }
            CurrentPlaybackMedia = media;
            var mem = _mediaPlayer.media().eventManager();

            mem.OnParsedChanged += OnParsedStatus;
        }
Ejemplo n.º 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);

                ApplicationSettingsHelper.SaveSettingsValue(nameof(CurrentMedia), CurrentMedia);
            }
            else if (media is StreamMedia)
            {
                await InitializePlayback(media, autoPlay);
            }
        }