2012-06-27 105 views
0

我想在移动设备上播放.wav文件。我想我的麻烦在于实际正确访问文件。以下是我目前的代码:在Windows移动设备上播放声音文件(.wav特别)

string path = "\\Windows\\badRead.wav"; 
System.Media.SoundPlayer player = new System.Media.SoundPlayer(path); 
player.PlaySync(); 
player.PlaySync(); 

我错过了什么?我收到的错误是“请务必声音文件存在于指定位置 难道是它的搜索服务器上的wav文件预先感谢您

+0

这应该工作,如果路径是正确的。你得到一个FileNotFound异常?您是否证实该文件存在于intermec设备上? – ScottieMc

+0

它确实存在。我认为问题在于未指定的驱动程序。它没有被映射,我不熟悉以这种方式访问​​文件。 – Eric

+0

你无法浏览到该文件并点击它来播放?如果它在那里失败,那么它可能是一个驱动程序问题。 – ScottieMc

回答

0

我用JavaScript而不是试图播放声音服务器端。

我找到了我的答案here

2

你读过这样的:?http://peterfoot.net/SystemMediaSoundPlayerVersusThePlaySoundAPI.aspx

可能你必须先使用player.PlaySync之前发出player.Load():

private SoundPlayer Player = new SoundPlayer(); 
    private void loadSoundAsync() 
    { 
     // Note: You may need to change the location specified based on 
     // the location of the sound to be played. 
     this.Player.SoundLocation = "http://www.tailspintoys.com/sounds/stop.wav"; 
     this.Player.LoadAsync(); 
    } 

    private void Player_LoadCompleted (
     object sender, 
     System.ComponentModel.AsyncCompletedEventArgs e) 
    { 
     if (this.Player.IsLoadCompleted) 
     { 
      this.Player.PlaySync(); 
     } 
    } 

另一种方法是使用播放>声音API本身:

http://msdn.microsoft.com/en-us/library/ms228710%28v=vs.90%29.aspx

+0

我不知道我完全理解。 Player_LoadCompleted从未被解雇。 – Eric

+0

这实际上没有奏效。它在我的本地机器上工作,但是当我将它投入服务器时,声音不会播放。 – Eric