媒体播放器例外

时间:2012-09-07 17:39:08

标签: axwindowsmediaplayer

我正在编写一个Windows应用程序。我的形式有媒体播放器。当我将URL设置为“fsgfbnhgb”(错误!)时,播放器本身会显示错误。但这并不好。我有“尝试”和“捕获”块,在try块中,当URL为“fgdsfgasgfas”时没有任何异常!因为玩家本身捕获异常。 如何自行设置媒体播放器的错误?

try
{
  player.URL = "fdgsdgsdg";
  player.Ctlcontrols.play();
}
catch
{
  snd.Play();
  MessageBox.Show("An error occurred during reading the alarm music path. Check that its directory is valid.", "Alarm music error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

谢谢大家

1 个答案:

答案 0 :(得分:0)

你可以尝试在try {} catch {}

中检查文件是否存在
try{
    string url = "sdahgjk";
   if (!File.Exists(url))
        throw new Exception("Exception Message Here");
   player.Url = url;
   player.Ctlcontrols.play();
        }
        catch
        {
            snd.Play();
            MessageBox.Show("An error occurred during reading the alarm music path. Check that its directory is valid.", "Alarm music error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }