2012-06-27 104 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