Beispiel #1
0
        public async Task Player_ChangeState()
        {
            var state = await Player.GetState();

            if (state == PlayerState.Playing)
            {
                try
                {
                    var completion = new TaskCompletionSource <PlayerState>();

                    using (Player.StateChanges
                           .Where(element => element == PlayerState.Paused)
                           .Timeout(TimeSpan.FromSeconds(2))
                           .Subscribe(value =>
                    {
                        completion.SetResult(value);
                    }))
                    {
                        await Player.Pause();

                        await completion.Task;
                    };
                }
                finally
                {
                    await Player.Play();
                }
            }
        }
Beispiel #2
0
        private static async Task DumpPlayer(BluPlayer player)
        {
            Console.WriteLine($"State: {await player.GetState()}");
            Console.WriteLine($"Shuffle: {await player.GetShuffleMode()}");
            Console.WriteLine($"Repeat: {await player.GetRepeatMode()}");
            Console.WriteLine($"Volume: {await player.GetVolume()}%");
            Console.WriteLine($"Position: {await player.GetPosition()}");

            DumpPresets(await player.PresetList.GetPresets());
            DumpMedia(await player.GetMedia());
            DumpQueueInfo(await player.PlayQueue.GetInfo());
            await DumpMusicBrowser(player.MusicBrowser);

            Console.WriteLine(new string('=', 80));
            Console.WriteLine();

            Console.WriteLine("Waiting for changes...");
            WriteInstructions();

            player.StateChanges.Subscribe(state =>
            {
                Console.WriteLine($"State: {state}");
            });

            player.ShuffleModeChanges.Subscribe(mode =>
            {
                Console.WriteLine($"Shuffle: {mode}");
            });

            player.RepeatModeChanges.Subscribe(mode =>
            {
                Console.WriteLine($"Repeat: {mode}");
            });

            player.VolumeChanges.Subscribe(volume =>
            {
                Console.WriteLine($"Volume: {volume}%");
            });

            player.PositionChanges.Subscribe(position =>
            {
                Console.WriteLine($"Position: {position}");
            });

            player.MediaChanges.Subscribe(media =>
            {
                DumpMedia(media);
            });

            player.PresetList.Changes.Subscribe(presets =>
            {
                DumpPresets(presets);
            });

            player.PlayQueue.Changes.Subscribe(info =>
            {
                DumpQueueInfo(info);
            });
        }
Beispiel #3
0
        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var endpoint = await BluEnvironment.ResolveEndpoints().FirstOrDefaultAsync();

            if (endpoint != null)
            {
                Player = await BluPlayer.Connect(endpoint);

                PlayerName = Player.Name;

                PlayerState = await Player.GetState();

                Player.StateChanges.ObserveOnDispatcher().Subscribe(value => PlayerState = value);

                Volume = await Player.GetVolume();

                Player.VolumeChanges.ObserveOnDispatcher().Subscribe(value => Volume = value);

                UpdateMedia(await Player.GetMedia());
                Player.MediaChanges.ObserveOnDispatcher().Subscribe(UpdateMedia);
            }
        }