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); 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; MessageDialog dialog = new MessageDialog("Unable to connect!"); await dialog.ShowAsync(); } } }
public override async Task TryConnectAsync(StationStream stream) { try { streamSource = await ShoutcastStreamFactory.ConnectAsync(stream.StreamUrl, new ShoutcastStreamFactoryConnectionSettings() { UserAgent = "Neptunium (http://github.com/Amrykid/Neptunium)", RelativePath = stream.RelativePath, RequestSongMetdata = stream.RequestMetadata }); streamSource.Reconnected += StreamSource_Reconnected; streamSource.MetadataChanged += ShoutcastStream_MetadataChanged; StreamMediaSource = MediaSource.CreateFromMediaStreamSource(streamSource.MediaStreamSource); StreamMediaSource.StateChanged += StreamMediaSource_StateChanged; this.StationPlaying = await NepApp.Stations.GetStationByNameAsync(stream.ParentStation); ShoutcastStationInfo = streamSource.StationInfo; RaiseStationInfoAcquired(streamSource.StationInfo); } catch (Exception ex) { if (ex is System.Runtime.InteropServices.COMException) { if (ex.HResult == -2147014836) { /* A connection attempt failed because the connected party did not properly respond after a period of time, or * established connection failed because connected host has failed to respond. */ //At this point, we've already timed out and informed the user. We can use return out of this. return; } } throw new Neptunium.Core.NeptuniumStreamConnectionFailedException(stream, ex); } }