MediaPlayer在WPF中运行不正常

时间:2013-03-19 16:11:50

标签: c# wpf media-player audio mainwindow

我在WPF中的MediaPlayer有一个非常奇怪的问题。播放器设置在主窗口consturctor中,它工作正常,但如果我把它放在某个计时器或方法内部,它就不行了!

源很好,属性设置为始终复制。我也检查了调试器,它确实读了一行。

我真的没有想法,如果你有什么话,请告诉我。

public MediaPlayer shot;

public MainWindow()
{
    InitializeComponent();
    Controller = new GameControl(this, Canvas);
    Controller.SetLevelsBtns(Canvas);

    shot = new MediaPlayer();
    shot.Open(new Uri(@"AbsolutePath\GunShot.mp3", UriKind.Absolute));
    shot.Play();
}

dosnt播放文件的代码:

 public void fireTimer_Tick(object sender, EventArgs e)
    {
        if (Keyboard.IsKeyDown(Key.Space) && Controller.GameOn && bulletsCartridge <= Controller.bullets.Length)
        {
            shot = new MediaPlayer();
            shot.Open(new Uri(@"C:\Users\tal_gar\Documents\project\KillTheZombie\bin\Debug\sounds\GunShot.mp3", UriKind.Absolute));
            shot.Play();
            Controller.fireTimer.Start();
            Controller.bullets[bulletsCartridge].SetBullet(Controller.player);
            Controller.bullets[bulletsCartridge].Draw(Canvas);
            Controller.bullets[bulletsCartridge].Alive = true;
            bulletsCartridge++;
            Controller.fireTimer.Stop();
        }
    }

0 个答案:

没有答案