示例#1
0
        private async void playButton_Click(object sender, RoutedEventArgs e)
        {
            playButton.IsEnabled      = false;
            stationComboBox.IsEnabled = false;
            stopButton.IsEnabled      = true;

            var selectedStation = stationComboBox.SelectedItem as StationItem;

            if (selectedStation != null)
            {
                try
                {
                    shoutcastStream = await ShoutcastStreamFactory.ConnectAsync(selectedStation.Url,
                                                                                new ShoutcastStreamFactoryConnectionSettings()
                    {
                        RelativePath = selectedStation.RelativePath
                    });

                    shoutcastStream.MetadataChanged += StreamManager_MetadataChanged;
                    MediaPlayer.SetMediaStreamSource(shoutcastStream.MediaStreamSource);
                    MediaPlayer.Play();

                    SampleRateBox.Text  = "Sample Rate: " + shoutcastStream.AudioInfo.SampleRate;
                    BitRateBox.Text     = "Bit Rate: " + shoutcastStream.AudioInfo.BitRate;
                    AudioFormatBox.Text = "Audio Format: " + Enum.GetName(typeof(UWPShoutcastMSS.Streaming.StreamAudioFormat), shoutcastStream.AudioInfo.AudioFormat);
                }
                catch (Exception ex)
                {
                    playButton.IsEnabled      = true;
                    stationComboBox.IsEnabled = true;
                    stopButton.IsEnabled      = false;

                    if (shoutcastStream != null)
                    {
                        try
                        {
                            shoutcastStream.Disconnect();
                        }
                        catch (Exception)
                        {
                        }
                        finally
                        {
                            shoutcastStream.Dispose();
                        }
                    }

                    MessageDialog dialog = new MessageDialog("Unable to connect!");
                    await dialog.ShowAsync();
                }
            }
        }
示例#2
0
        private void stopButton_Click(object sender, RoutedEventArgs e)
        {
            playButton.IsEnabled      = true;
            stationComboBox.IsEnabled = true;
            stopButton.IsEnabled      = false;

            if (shoutcastStream != null)
            {
                shoutcastStream.MetadataChanged -= StreamManager_MetadataChanged;
                MediaPlayer.Stop();
                MediaPlayer.Source = null;

                shoutcastStream.Disconnect();
                shoutcastStream = null;
            }
        }