Exemple #1
0
        private void PlaySong(Song song)
        {
            // If the song is null there is nothing to play
            if (song == null)
            {
                if (PlaylistEnded != null)
                {
                    PlaylistEnded();
                }
                return;
            }

            // As soon as we are trying to play any song we are moving forward again.
            playbackDirection = TP_PLAYBACKDIRECTION.Forward;

            string temp = FindAudiofile(song);

            if (temp == "" || temp == null)
            {
                throw new Exception("Zu diesem Song wurde kein Audiofile gefunden.");
            }
            else if (System.IO.File.Exists(temp))
            {
                Stop();

                // This is the point where the song is actually played for real.
                //IMedia media = factory.CreateMedia<IMedia>(temp);
                //factory.CreatePlayer<IAudioPlayer>().Open(media);
                VlcMedia media = new VlcMedia(instance, temp);
                CurrentSong = song;
                if (vlc == null)
                {
                    vlc = new VlcMediaPlayer(media);
                }
                else
                {
                    vlc.Media = media;
                }
                vlc.Play();
                PlaybackState = TP_PLAYBACKSTATE.Playing;
                // If we are not already navigating, log the song to the navigation history so it is available in case the user starts skipping
                if (playbackMode == TP_PLAYBACKMODE.Playlist)
                {
                    totalHistory.Add(song);
                    historyPosition++;
                }
            }
            else
            {
                //TODO: Automatically re-scan
                throw new System.IO.FileNotFoundException("Die Datei des abzuspielenden Songs wurde nicht gefunden. Möglicherweise muss die Bibliothek aktualisiert werden.", temp);
            }
        }