예제 #1
0
        public async void PlayNext()
        {
            int rowId = ApplicationSettings.GetSettingsValue <int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);

            PlayQueueEntryTable currentPlayQueueRow = DatabaseManager.Current.LookupPlayQueueEntryById(rowId);

            if (currentPlayQueueRow != null)
            {
                int nextRowId = currentPlayQueueRow.NextId;
                ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, nextRowId);

                if (nextRowId == 0)
                {
                    SendMessageToForeground(PlayQueueConstantBGMessageId.PlayQueueFinished);
                }
            }
            else
            {
                PlayQueueEntryTable head = DatabaseManager.Current.LookupPlayQueueEntryHead();

                if (head != null)
                {
                    ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, head.RowId);
                }
                else
                {
                    ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);
                }
            }

            await PlayCurrent();
        }
예제 #2
0
        private int AddSong(int songId)
        {
            // Keep queue trimmed
            if (LookupMap.Count >= MAX_QUEUE_SIZE)
            {
                PlayQueueEntryModel head = null;

                if (PlaybackQueue.Count > 0)
                {
                    head = PlaybackQueue.First();
                }

                if (head != null)
                {
                    if (CurrentPlaybackQueueEntryId == head.RowId)
                    {
                        // TODO: #6 raise alert about queue being full
                        return(-1);
                    }
                    else
                    {
                        RemoveEntry(head.RowId);
                    }
                }
            }

            PlayQueueEntryModel currentTail = null;

            if (PlaybackQueue.Count > 0)
            {
                currentTail = PlaybackQueue.Last();
            }

            PlayQueueEntryTable newPlayQueueEntry;

            if (currentTail == null)
            {
                newPlayQueueEntry = new PlayQueueEntryTable(songId, 0, 0);

                DatabaseManager.Current.AddPlayQueueEntry(newPlayQueueEntry);
            }
            else
            {
                newPlayQueueEntry = new PlayQueueEntryTable(songId, 0, currentTail.RowId);

                DatabaseManager.Current.AddPlayQueueEntry(newPlayQueueEntry);

                currentTail.NextId = newPlayQueueEntry.RowId;
            }

            PlayQueueEntryModel newEntry = new PlayQueueEntryModel(newPlayQueueEntry);

            LookupMap.Add(newEntry.RowId, newEntry);
            PlaybackQueue.Add(newEntry);

            NotifyPropertyChanged(Properties.NextTrack);
            NotifyPropertyChanged(Properties.PrevTrack);

            return(newEntry.RowId);
        }
예제 #3
0
        public bool CanBack()
        {
            int rowId = ApplicationSettings.GetSettingsValue <int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);

            PlayQueueEntryTable currentPlayQueueRow = DatabaseManager.Current.LookupPlayQueueEntryById(rowId);

            return(currentPlayQueueRow != null && currentPlayQueueRow.PrevId > 0);
        }
예제 #4
0
        async Task PlayCurrent()
        {
            int rowId = ApplicationSettings.GetSettingsValue <int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);

            TrackInfo trackInfo = null;

            if (rowId > 0)
            {
                trackInfo = TrackInfo.TrackInfoFromRowId(rowId);
            }

            // TODO: #18  Support other types
            if (trackInfo != null)
            {
                try
                {
                    StorageFile file = await StorageFile.GetFileFromPathAsync(trackInfo.Path);

                    isFirstOpen = true;
                    mediaPlayer.SetFileSource(file);
                    IsActive = true;
                }
                catch (Exception ex)
                {
                    Logger.Current.Log(new CallerInfo(), LogLevel.Error, "Couldn't play track {0} got message {1}", trackInfo.SongId, ex.Message);

                    IsActive = false;

                    PlayNext();
                }
            }
            else
            {
                IsActive = false;

                PlayQueueEntryTable head = DatabaseManager.Current.LookupPlayQueueEntryHead();

                if (head != null)
                {
                    ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, head.RowId);

                    trackInfo = TrackInfo.TrackInfoFromRowId(head.RowId);

                    if (trackInfo != null)
                    {
                        StorageFile file = await StorageFile.GetFileFromPathAsync(trackInfo.Path);

                        playAfterOpen = false;
                        mediaPlayer.SetFileSource(file);
                    }
                }
                else
                {
                    ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);
                }
            }
        }
예제 #5
0
        public static TrackInfo TrackInfoFromRowId(int rowId)
        {
            try
            {
                PlayQueueEntryTable playQueueEntry = DatabaseManager.Current.LookupPlayQueueEntryById(rowId);

                if (playQueueEntry != null)
                {
                    SongTable songTable = DatabaseManager.Current.LookupSongById(playQueueEntry.SongId);

                    if (songTable != null)
                    {
                        AlbumTable  albumTable  = DatabaseManager.Current.LookupAlbumById(songTable.AlbumId);
                        ArtistTable artistTable = DatabaseManager.Current.LookupArtistById(songTable.ArtistId);

                        if (albumTable != null && artistTable != null)
                        {
                            ArtistTable albumArtistTable = DatabaseManager.Current.LookupArtistById(albumTable.ArtistId);

                            if (albumArtistTable != null)
                            {
                                return(new TrackInfo(songTable.Name, artistTable.Name, albumTable.Name, albumArtistTable.Name, songTable.Source, albumTable.AlbumArt, rowId, playQueueEntry.NextId, playQueueEntry.PrevId, playQueueEntry.SongId));
                            }
                            else
                            {
                                Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no artistEntry {1} matches!", rowId, albumTable.ArtistId);
                            }
                        }
                        else
                        {
                            Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no albumEntry {1} or artistEntry {2} matches ({3} {4})!", rowId, songTable.AlbumId, songTable.ArtistId, albumTable != null, artistTable != null);
                        }
                    }
                    else
                    {
                        Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no songEntry for {1} matches!", rowId, playQueueEntry.SongId);
                    }
                }
                else
                {
                    Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no playQueueEntry matches!", rowId);
                }
            }
            catch (SQLiteException ex)
            {
                Logger.Current.Log(new CallerInfo(), LogLevel.Error, "Couldn't play row {0}, got an exception {1}!", rowId, ex.Message);
            }

            return(null);
        }
예제 #6
0
        public async void ResetAndPlay()
        {
            PlayQueueEntryTable head = DatabaseManager.Current.LookupPlayQueueEntryHead();

            if (head != null)
            {
                ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, head.RowId);
            }
            else
            {
                ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);
            }

            await PlayCurrent();
        }
예제 #7
0
        public async void PlayPrev()
        {
            int rowId = ApplicationSettings.GetSettingsValue <int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);

            PlayQueueEntryTable currentPlayQueueRow = DatabaseManager.Current.LookupPlayQueueEntryById(rowId);

            int prevRowId = 0;

            if (currentPlayQueueRow != null)
            {
                prevRowId = currentPlayQueueRow.PrevId;
            }

            ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, prevRowId);

            await PlayCurrent();
        }
예제 #8
0
        async Task PlayCurrent()
        {
            int rowId = ApplicationSettings.GetSettingsValue <int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);

            TrackInfo trackInfo = null;

            if (rowId > 0)
            {
                trackInfo = TrackInfo.TrackInfoFromRowId(rowId);
            }

            // TODO: #18  Support other types
            if (trackInfo != null)
            {
                await PlayTrack(trackInfo, true);
            }
            else
            {
                IsActive = false;

                PlayQueueEntryTable head = DatabaseManager.Current.LookupPlayQueueEntryHead();

                if (head != null)
                {
                    ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, head.RowId);

                    trackInfo = TrackInfo.TrackInfoFromRowId(head.RowId);

                    if (trackInfo != null)
                    {
                        await PlayTrack(trackInfo, false);
                    }
                }
                else
                {
                    ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);
                }
            }
        }