コード例 #1
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            if (MediaPlayer.State == MediaState.Playing)
            {
                MediaPlayer.Pause();
            }
            else
            {
                MediaHistory history = MediaHistory.Instance;

                if (s == null)
                {
                    s = DoShuffle();
                    if (s == null)
                    {
                        MessageBox.Show("The media library doesn't contain songs");
                        return;
                    }
                }

                tbSong.Text = "Now playing " + s.Artist + " " + s.Name;
                MediaPlayer.Play(s);
                UpdateNowPlaying();
                UpdateHistory();
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a MediaHistoryItem for the song we are playing and
        /// adds it to the history area of the Music + Videos Hub.
        /// </summary>
        private void AddToHistory()
        {
            if (_playingSong != null)
            {
                MediaHistoryItem historyItem = new MediaHistoryItem();
                historyItem.Title  = _playingSong.Name;
                historyItem.Source = "";

                // TODO: Use a more unique image here that better identifies
                // the history item as having come from this app.
                historyItem.ImageStream = _playingSong.Album.GetThumbnail();

                if (historyItem.ImageStream == null)
                {
                    // No album art found, use a generic place holder image.
                    StreamResourceInfo sri = Application.GetResourceStream(new Uri("AlbumThumbnailPlaceholder.png", UriKind.Relative));
                    historyItem.ImageStream = sri.Stream;
                }

                // If we get activated by the MediaHistoryItem we're creating here,
                // our NavigationContext will have a key-value pair ("playSong", "<Song Name>")
                // where <Song Name> is the Name property of the _playingSong object.
                historyItem.PlayerContext[_playSongKey] = _playingSong.Name;

                // Add our item to the MediaHistory area of the Music + Videos Hub.
                MediaHistory mediaHistory = MediaHistory.Instance;
                mediaHistory.WriteRecentPlay(historyItem);
            }
        }
コード例 #3
0
        public async Task <string> Add(StorageFile file)
        {
            bool isAudio = file.ContentType.Contains("audio");

            string       token;
            MediaHistory previouslySavedMedia = _histories.FirstOrDefault(h => h.Filename == file.Name);

            if (previouslySavedMedia == null)
            {
                string       mru     = StorageApplicationPermissions.FutureAccessList.Add(file);
                MediaHistory history = CreateHistory(file, mru, isAudio);
                _histories.Insert(0, history);
                token = history.Token;
            }
            else
            {
                _histories.Remove(previouslySavedMedia);
                _histories.Insert(0, previouslySavedMedia);
                token = previouslySavedMedia.Token;
            }

            await SaveHistory();

            return(token);
        }
コード例 #4
0
        public void UpdateMediaHistory(string fileToken, TimeSpan totalWatched)
        {
            MediaHistory mediaHistory = _histories.FirstOrDefault(h => h.Token == fileToken);

            if (mediaHistory != null)
            {
                mediaHistory.TotalWatchedMilliseconds = totalWatched.TotalMilliseconds;
            }
            PublishUpdate();
        }
コード例 #5
0
        private async Task GatherTimeInformation()
        {
            var          historyService = App.Container.Resolve <HistoryService>();
            MediaHistory history        = historyService.GetHistory(_token);

            await DispatchHelper.InvokeAsync(() =>
            {
                TimeWatched = TimeSpan.FromMilliseconds(history.TotalWatchedMilliseconds);
            });
        }
コード例 #6
0
ファイル: HistoryService.cs プロジェクト: OFark/Compressarr
        public Guid StartProcessing(WorkItem wi)
        {
            using var db = new LiteDatabase(fileService.GetAppFilePath(AppFile.mediaInfo));

            var history = new MediaHistory();
            ILiteCollection <MediaHistory> histories = default;

            try
            {
                histories = db.GetCollection <MediaHistory>();
                history   = histories.Query().Include(x => x.Entries).Where(x => x.FilePath == wi.SourceFile).FirstOrDefault();
            }
            catch (InvalidCastException)
            {
                db.DropCollection(HISTORYTABLE);
                histories = db.GetCollection <MediaHistory>();
                //todo: report on screen
            }

            if (history == default)
            {
                history = new MediaHistory()
                {
                    FilePath = wi.SourceFile
                };
                histories.Insert(history);
            }

            history.Entries ??= new();

            var processingHistory = new ProcessingHistory()
            {
                Arguments           = wi.Arguments.ToList(),
                DestinationFilePath = wi.DestinationFile,
                FilterID            = wi.Job.FilterID,
                Preset = wi.Job.PresetName
            };

            var entry = new HistoryEntry()
            {
                HistoryID         = Guid.NewGuid(),
                Started           = DateTime.Now,
                Type              = "Processed",
                ProcessingHistory = processingHistory
            };

            history.Entries.Add(entry);

            histories.EnsureIndex(x => x.Id);

            histories.Update(history);

            return(entry.HistoryID);
        }
コード例 #7
0
        private MediaHistory CreateHistory(IStorageItem item, string token, bool isAudio)
        {
            var history = new MediaHistory
            {
                Token      = token,
                Filename   = item.Name,
                LastPlayed = DateTime.Now,
                TotalWatchedMilliseconds = 0,
                IsAudio = isAudio
            };

            return(history);
        }
コード例 #8
0
        private void UpdateHistory()
        {
            MediaHistoryItem   historyItem = new MediaHistoryItem();
            StreamResourceInfo sri         = Application.GetResourceStream(new Uri("NowPlayingIcon.jpg", UriKind.Relative));

            historyItem.ImageStream = sri.Stream;
            historyItem.Source      = "";
            historyItem.Title       = s.Name;
            historyItem.PlayerContext.Add(_key, songIndex.ToString());
            MediaHistory history = MediaHistory.Instance;

            history.WriteRecentPlay(historyItem);
        }
コード例 #9
0
        private void UpdateNowPlaying()
        {
            MediaHistoryItem   nowPlaying = new MediaHistoryItem();
            StreamResourceInfo sri        = Application.GetResourceStream(new Uri("NowPlayingIcon.jpg", UriKind.Relative));

            nowPlaying.ImageStream = sri.Stream;
            nowPlaying.Source      = "";
            nowPlaying.Title       = s.Name;
            nowPlaying.PlayerContext.Add(_key, songIndex.ToString());
            MediaHistory history = MediaHistory.Instance;

            history.NowPlaying = nowPlaying;
        }
コード例 #10
0
        public async Task <StorageFile> RetrieveFileAt(int index)
        {
            if (index < _histories.Count)
            {
                MediaHistory history = _histories[index];
                try
                {
                    StorageFile file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(history.Token);

                    return(file);
                }
                catch (FileNotFoundException)
                {
                    return(null);
                }
            }
            return(null);
        }
コード例 #11
0
 public static void CreateMediaHistory()
 {
     try
     {
         for (int i = 0; i < 30; i++)
         {
             //Create a snapshot of the page title
             StreamResourceInfo sri =
                 Application.GetResourceStream(new Uri(AppResources.ImageHistory, UriKind.RelativeOrAbsolute));
             var mediaHistoryItem = new MediaHistoryItem();
             //<hubTileImageStream> must be a valid ImageStream.
             mediaHistoryItem.ImageStream = sri.Stream;
             mediaHistoryItem.Source      = "";
             mediaHistoryItem.Title       = "STOP Music";
             mediaHistoryItem.PlayerContext.Add("STOP Music" + i, "STOP Music");
             MediaHistory mediaHistory = MediaHistory.Instance;
             mediaHistory.WriteRecentPlay(mediaHistoryItem);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }