Exemple #1
0
        private void OnCurrentSongChanged(object sender, CurrentSongChangedEventArgs e)
        {
            CurrentSong.Unsubscribe(e.OldCurrentSong);
            CurrentSong.Subscribe(e.NewCurrentSong);

            OtherSongs.Unsubscribe(e.NewCurrentSong);
            OtherSongs.Subscribe(e.OldCurrentSong);

            CurrentSongChanged?.Invoke(this, new SubscriptionsEventArgs <IPlaylist, CurrentSongChangedEventArgs>(sender, e));
        }
Exemple #2
0
 public void ProcCurrentSongChanged(Song song)
 {
     CurrentSongChanged?.InvokeOnMainThread(this, song);
 }
Exemple #3
0
        private void UpdateCurrentSong()
        {
            if (DisableUpdates)
            {
                SimpleLogger.DefaultLog("MediaSessionManager::UpdateCurrentSong called, but updates are disabled.");
                return;
            }

            SimpleLogger.DefaultLog("MediaSessionManager::UpdateCurrentSong called...");

            var sessions = CurrentSessions.Values.ToList();

            SimpleLogger.DefaultLog("> All sessions:");
            foreach (var data in sessions)
            {
                SimpleLogger.DefaultLog($"    > Artist={data.Artist}; Title={data.Title}; IsPlaying={data.IsPlaying}");
            }

            sessions = sessions.Where(value => value.IsPlaying).ToList();
            SimpleLogger.DefaultLog("> Playing sessions:");
            foreach (var data in sessions)
            {
                SimpleLogger.DefaultLog($"    > Artist={data.Artist}; Title={data.Title}; IsPlaying={data.IsPlaying}");
            }

            // sessions = sessions.Where(value => value.Artist != "" || value.Title != "").ToList();
            // TODO: Implement settings for this.
            // For now since I'm using this mainly for music info, don't show if artist or album art are not set
            sessions = sessions.Where(value => value.Artist != "" && value.AlbumArt != null).ToList();
            SimpleLogger.DefaultLog("> Sessions with info:");
            foreach (var data in sessions)
            {
                SimpleLogger.DefaultLog($"    > Artist={data.Artist}; Title={data.Title}; IsPlaying={data.IsPlaying}");
            }

            if (sessions.Count == 0)
            {
                if (!LastPlaybackData.HasValue)
                {
                    SimpleLogger.DefaultLog("MediaSessionManager::UpdateCurrentSong DONE (both null)");
                }
                else
                {
                    LastPlaybackData = null;
                    CurrentSongChanged?.Invoke(this, new CurrentSongChangedEventArgs());
                    SimpleLogger.DefaultLog("MediaSessionManager::UpdateCurrentSong DONE (old is not null, new is null)");
                }
                return;
            }

            // TODO: Be more intelligent with the selection
            // var sorted = playing.OrderByDescending(value => value.updatedAt).ToList();
            var playbackData = sessions.Last();

            if (LastPlaybackData.Equals(playbackData))
            {
                SimpleLogger.DefaultLog("MediaSessionManager::UpdateCurrentSong DONE (old and new are equal)");
                return;
            }

            LastPlaybackData = playbackData;
            CurrentSongChanged?.Invoke(this, new CurrentSongChangedEventArgs {
                PlaybackData = playbackData
            });
            SimpleLogger.DefaultLog("MediaSessionManager::UpdateCurrentSong DONE");
        }
Exemple #4
0
 /// <summary>
 /// Raises the <see cref="E:CurrentSongChanged" /> event.
 /// </summary>
 /// <param name="e">The <see cref="Kfstorm.DoubanFM.Core.EventArgs{T}" /> instance containing the event data.</param>
 protected virtual void OnCurrentSongChanged(EventArgs <Song> e)
 {
     CurrentSongChanged?.Invoke(this, e);
 }