1

I'm trying to run a mini program, which is able to play radio when I click button.

private void Yes933_Click(object sender, RoutedEventArgs e)
{
    if (Player.Source != null)
    {
        Player.LoadedBehavior = MediaState.Manual;
        Player.Stop();
        Player.Source = null;
    }
        Player.LoadedBehavior = MediaState.Manual;
        string StationUrl = "http://www.radiosingapore.org/#radio-y-e-s-93-3-fm";
        Player.Source = new Uri(StationUrl, UriKind.RelativeOrAbsolute);
        Player.Play();
}

If I click " next " button,it should play the next channel.

private void NextStation_Click(object sender, RoutedEventArgs e)
{
    robot.Nextstation();
}

Here's the Nextstation() method in another class:

public void Nextstation()
{
    if (mainWindows.Player.Source != null)
    {
        string StationUrl;
        switch (mainWindows.Player.Source.AbsoluteUri)
        {
            case "http://www.radiosingapore.org/#radio-class-95-fm":
            StationUrl = "http://www.radiosingapore.org/#radio-y-e-s-93-3-fm";
            break; 
            case "http://www.radiosingapore.org/#radio-y-e-s-93-3-fm":
            StationUrl = "http://www.radiosingapore.org/#radio-class-95-fm";
            break;
            default:
            StationUrl = "http://www.radiosingapore.org/#radio-class-95-fm";
            break;
         }
         mainWindows.Player.LoadedBehavior = MediaState.Manual;
         mainWindows.Player.Stop();
         mainWindows.Player.Source = null;
         mainWindows.Player.LoadedBehavior = MediaState.Manual;
         mainWindows.Player.Source = new Uri(StationUrl, UriKind.RelativeOrAbsolute);
         mainWindows.Player.Play();
    }

}

But it shows: enter image description here

I have no idea why is that so. Any suggestion? Thanks in advance.

HelloWorld
  • 77
  • 1
  • 6

0 Answers0