Ejemplo n.º 1
0
        PlayableTrackInfo _backingTrack; // Keep for tracking player.

        #endregion private members

        public VlcJcfPlayer(JcfMedia media, MediaConfiguration[] configs, string[] options)
        {
            _libVLC  = new LibVLC(options);
            _players = new Dictionary <PlayableTrackInfo, MediaPlayer>(media.InstrumentTracks.Count + 1);

            var backingPath   = "file://" + Path.Combine(media.Path, media.BackingTrack.Identifier.ToString().ToUpper() + "_jcfx");
            var backingPlayer = new MediaPlayer(_libVLC);

            backingPlayer.Media = new Media(_libVLC, backingPath, FromType.FromLocation);
            foreach (var config in configs)
            {
                backingPlayer.Media.AddOption(config);
            }
            backingPlayer.PositionChanged += Player_PositionChanged;
            _players[media.BackingTrack]   = backingPlayer;
            _backingTrack = media.BackingTrack;

            foreach (var track in media.InstrumentTracks)
            {
                var path   = "file://" + Path.Combine(media.Path, track.Identifier.ToString().ToUpper() + "_jcfx");
                var player = new MediaPlayer(_libVLC);
                player.Media = new Media(_libVLC, path, FromType.FromLocation);
                foreach (var config in configs)
                {
                    player.Media.AddOption(config);
                }
                _players[track] = player;
            }

            Length = media.Length;
        }
        public void AddPlayableTrack(TrackBase source)
        {
            PlayableTrackInfo playable = new PlayableTrackInfo();

            playable.Title  = source.MetaData.Title.Value;
            playable.Artist = source.MetaData.AlbumArtists.JoinedValue;

            playable.IsPlayableOffline = source.PlayableOffline;
            playable.IsPlayableOnline  = source.PlayableOnline;

            if (source.PlayableOffline)
            {
                playable.OfflinePlayer = source.SupportedMediaPlayers;
            }
            else
            {
                playable.OnlinePlayer = source.SupportedMediaPlayers;
            }

            if (source is TrackVirtual && source.PlayableOnline)
            {
                TrackVirtual sourceVirtual = source as TrackVirtual;
                playable.SpotifyURI        = sourceVirtual.SpotifyURI;
                playable.PlaytimeInSeconds = 10; // TODO
            }
            else if (source is TrackLocal && source.PlayableOffline)
            {
                TrackLocal sourceLocal = source as TrackLocal;
                playable.FilePath          = sourceLocal.MusicFileProperties.Path;
                playable.PlaytimeInSeconds = sourceLocal.MusicFileProperties.Duration;
            }

            tracks.Add(playable);
        }
        public PlayzoneBackgroundWorker()
        {
            playerWorker = new BackgroundWorker();
            playerWorker.WorkerSupportsCancellation = true;
            playerWorker.DoWork += ConsumePlaylist;

            tracks           = new List <PlayableTrackInfo>();
            currentlyPlaying = null;
            isPaused         = false;

            spotifyService = DependencyInjector.GetService <ISpotifyService>();
            foobarService  = DependencyInjector.GetService <IFoobarService>();
        }
Ejemplo n.º 4
0
 public uint GetVolume(PlayableTrackInfo track)
 {
     return((uint)players[track].Volume);
 }
Ejemplo n.º 5
0
 public void SetVolume(PlayableTrackInfo track, uint volume)
 {
     players[track].Volume = volume / 100.0f;
 }
Ejemplo n.º 6
0
 public void SetVolume(PlayableTrackInfo track, uint volume)
 {
     _players[track].Volume = (int)volume;
 }
        private async void ConsumePlaylist(object sender, DoWorkEventArgs e)
        {
            bool didCommitPause = false;

            while (true)
            {
                if (playerWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                else if (isPaused)
                {
                    if (didCommitPause == false)
                    {
                        if (currentlyPlaying.IsPlayableOffline)
                        {
                            await foobarService.Pause();
                        }
                        else if (currentlyPlaying.IsPlayableOnline)
                        {
                            await spotifyService.PausePlayback();
                        }
                        didCommitPause = true;
                    }
                    Thread.Sleep(500);
                    continue;
                }
                else
                {
                    if (tracks.Count > 0)
                    {
                        if (currentlyPlaying != null)
                        {
                            if (currentlyPlaying.IsPlayableOffline)
                            {
                                await foobarService.Pause();
                            }
                            else if (currentlyPlaying.IsPlayableOnline)
                            {
                                await spotifyService.PausePlayback();
                            }
                        }

                        didCommitPause = false;

                        currentlyPlaying = tracks.First();
                        tracks.Remove(currentlyPlaying);

                        if (currentlyPlaying.IsPlayableOffline)
                        {
                            switch (currentlyPlaying.OfflinePlayer)
                            {
                            case SupportedMediaPlayers.Foobar2000:     // TODO: maybe not this way
                                string playlistPath       = AppDomain.CurrentDomain.BaseDirectory + "_playzone_mix.m3u";
                                System.IO.StreamWriter sw = new System.IO.StreamWriter(playlistPath);
                                sw.WriteLine(currentlyPlaying.FilePath);
                                sw.Flush();
                                sw.Close();
                                sw.Dispose();
                                System.Diagnostics.Process.Start(playlistPath);
                                break;
                            }

                            int sleepTime = currentlyPlaying.PlaytimeInSeconds * 1000 + 2000;
                            if (sleepTime < 12000)
                            {
                                sleepTime = 12000;
                            }

                            Thread.Sleep(sleepTime); // + 2 sec for API delay // TODO: maybe not this way
                        }
                        else if (currentlyPlaying.IsPlayableOnline)
                        {
                            switch (currentlyPlaying.OnlinePlayer)
                            {
                            case SupportedMediaPlayers.Spotify:
                                await spotifyService.ChangePlaybackMusic(currentlyPlaying.SpotifyURI);

                                break;
                            }

                            int sleepTime = currentlyPlaying.PlaytimeInSeconds * 1000 + 2000;
                            if (sleepTime < 12000)
                            {
                                sleepTime = 12000;
                            }

                            Thread.Sleep(sleepTime); // + 2 sec for API delay // TODO: maybe not this way
                        }
                    }
                }
            }
        }
 public void Stop()
 {
     playerWorker.CancelAsync();
     currentlyPlaying = null;
     tracks.Clear();
 }
Ejemplo n.º 9
0
 public void SetVolume(PlayableTrackInfo track, uint volume)
 {
     _channels[track].Volume = volume / 100.0f;
 }
Ejemplo n.º 10
0
 public uint GetVolume(PlayableTrackInfo track) => (uint)_channels[track].Volume;
Ejemplo n.º 11
0
 public void SetVolume(PlayableTrackInfo track, uint volume)
 {
   _player.SetVolume((float)volume, (float)volume);
 }
Ejemplo n.º 12
0
 public uint GetVolume(PlayableTrackInfo track)
 {
   return 50;
 }