protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            await connection.ConnectAsync();

            deviceWatcher.Start();

            message.Text = CONNECT;

            base.OnNavigatedTo(e);
        }
예제 #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                await SpeechAsync("JukeBox: There's no internet connection");
            }
            else
            {
                await SpeechAsync("Welcome to JukeBox");
            }

            await connection.ConnectAsync((message) =>
            {
                switch (message.Type)
                {
                case Common.MessageType.PlayMusic:
                    mediaPlayer.Source = new Uri(message.Arguments);
                    mediaPlayer.Play();
                    textMessage.Text = "Playing...";
                    break;

                case Common.MessageType.PauseMusic:
                    if (mediaPlayer.CurrentState == MediaElementState.Paused)
                    {
                        mediaPlayer.Play();
                        textMessage.Text = "Resumed";
                    }
                    else
                    {
                        mediaPlayer.Pause();
                        textMessage.Text = "Pause";
                    }
                    break;

                case Common.MessageType.StopMusic:
                    mediaPlayer.Stop();
                    textMessage.Text = "Stop";
                    break;

                default:
                    break;
                }
            });

            textMessage.Text = CONNECT;

            base.OnNavigatedTo(e);
        }