Beispiel #1
0
        private static void OnPlaybackStatusUpdate(SharkEvent p_SharkEvent)
        {
            if (Application.Library.Broadcast.CurrentBroadcastStatus != BroadcastStatus.Broadcasting)
            {
                return;
            }

            var s_Event = (PlaybackStatusUpdateEvent)p_SharkEvent;

            if (s_Event.Status != PlaybackStatus.Completed && s_Event.Status != PlaybackStatus.Paused &&
                s_Event.Status != PlaybackStatus.Suspended)
            {
                return;
            }

            var s_CurrentIndex = QueueManager.GetPlayingSongIndex();

            if (s_CurrentIndex != -1 && s_CurrentIndex < QueueManager.GetCurrentQueue().Count - 2)
            {
                var s_NextSong = QueueManager.GetCurrentQueue()[s_CurrentIndex + 1];
                Application.Library.Broadcast.PlaySong(s_NextSong.SongID, s_NextSong.QueueID);
                return;
            }

            // Allows for custom queuing logic by Modules.
            var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

            if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
            {
                var s_First = s_ModuleSongs.First();
                Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                return;
            }

            // Try to play a new song.
            if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
            {
                var s_SongID = PlaylistManager.DequeueNextSong();
                Application.Library.Broadcast.PlaySong(s_SongID, Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_SongID
                })[s_SongID]);
                return;
            }

            var s_Random    = new Random();
            var s_SongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
            var s_FirstSong = QueueManager.CollectionSongs[s_SongIndex];

            var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                s_FirstSong
            });

            Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
        }
Beispiel #2
0
        internal static void UpdateQueue()
        {
            var s_Index = Application.Library.Queue.GetPlayingSongIndex();

            Trace.WriteLine(String.Format("Updating Queue. Current Song: {0} - Total Songs: {1}", s_Index, Application.Library.Queue.CurrentQueue.Count));

            // We're running out of songs; add new ones.
            if (s_Index + 1 >= Application.Library.Queue.CurrentQueue.Count)
            {
                var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

                if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
                {
                    return;
                }

                if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
                {
                    var s_PlaylistSongID = PlaylistManager.DequeueNextSong();
                    Application.Library.Broadcast.AddSongs(new List <Int64> {
                        s_PlaylistSongID
                    });
                    return;
                }

                var s_Random          = new Random();
                var s_RandomSongIndex = s_Random.Next(0, CollectionSongs.Count);

                var s_SongID = CollectionSongs[s_RandomSongIndex];

                if (CollectionSongs.Count <= PlayedSongs.Count)
                {
                    PlayedSongs.Clear();
                }

                // Make sure the song we're adding is within our history limits.
                while (PlayedSongs.Contains(s_SongID))
                {
                    s_RandomSongIndex = s_Random.Next(0, CollectionSongs.Count);
                    s_SongID          = CollectionSongs[s_RandomSongIndex];
                }

                Trace.WriteLine(String.Format("Adding song {0} to queue (from collection).", s_SongID));

                Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_SongID
                });
            }
        }
Beispiel #3
0
        private static void OnComplianceIssue(SharkEvent p_SharkEvent)
        {
            if (!SettingsManager.MobileCompliance())
            {
                DisableMobileCompliance();
                return;
            }

            // Allows for custom queuing logic by Modules.
            var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

            if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
            {
                var s_First = s_ModuleSongs.First();
                Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                return;
            }

            // Try to play a new song.
            if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
            {
                var s_SongID = PlaylistManager.DequeueNextSong();
                Application.Library.Broadcast.PlaySong(s_SongID, Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_SongID
                })[s_SongID]);
                return;
            }

            var s_Random    = new Random();
            var s_SongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
            var s_FirstSong = QueueManager.CollectionSongs[s_SongIndex];

            var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                s_FirstSong
            });

            Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
        }
Beispiel #4
0
        private static void OnPendingDestruction(SharkEvent p_SharkEvent)
        {
            if (Application.Library.Broadcast.CurrentBroadcastStatus != BroadcastStatus.Broadcasting)
            {
                return;
            }

            // Allows for custom queuing logic by Modules.
            var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

            if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
            {
                var s_First = s_ModuleSongs.First();
                Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                return;
            }

            if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
            {
                var s_SongID = PlaylistManager.DequeueNextSong();
                Application.Library.Broadcast.PlaySong(s_SongID, Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_SongID
                })[s_SongID]);
                return;
            }

            // Broadcast ran out of songs somehow; add and play a random song.
            var s_Random    = new Random();
            var s_SongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
            var s_FirstSong = QueueManager.CollectionSongs[s_SongIndex];

            var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                s_FirstSong
            });

            Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
        }
Beispiel #5
0
        private static void OnSongPlaying(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongPlayingEvent)p_SharkEvent;

            Trace.WriteLine(String.Format("Currently playing song: {0} ({1})", s_Event.SongName, s_Event.SongID));

            if (s_Event.SongID == 0)
            {
                // We stopped playing, how did this happen?
                // Quickly! Add two to the queue!

                // Allows for custom queuing logic by Modules.
                var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(2);

                if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
                {
                    var s_First = s_ModuleSongs.First();
                    Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                    return;
                }

                if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
                {
                    var s_SongID   = PlaylistManager.DequeueNextSong();
                    var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                        s_SongID
                    });
                    Application.Library.Broadcast.PlaySong(s_SongID, s_QueueIDs[s_SongID]);
                    return;
                }

                var s_Random          = new Random();
                var s_FirstSongIndex  = s_Random.Next(0, CollectionSongs.Count);
                var s_SecondSongIndex = s_Random.Next(0, CollectionSongs.Count);

                var s_FirstSong  = CollectionSongs[s_FirstSongIndex];
                var s_SecondSong = CollectionSongs[s_SecondSongIndex];

                while (s_SecondSong == s_FirstSong)
                {
                    s_SecondSongIndex = s_Random.Next(0, CollectionSongs.Count);
                    s_SecondSong      = CollectionSongs[s_SecondSongIndex];
                }

                var s_Songs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_FirstSong, s_SecondSong
                });
                Application.Library.Broadcast.PlaySong(s_FirstSong, s_Songs[s_FirstSong]);
                return;
            }

            PlayedSongs.Add(s_Event.SongID);

            // Clear songs from history (if needed).
            for (var i = 0; i < PlayedSongs.Count - SettingsManager.MaxHistorySongs(); ++i)
            {
                PlayedSongs.RemoveAt(0);
            }

            UpdateQueue();
        }