我想在移动设备上播放.wav文件。我想我的麻烦在于实际正确访问文件。以下是我目前的代码:
string path = "\\Windows\\badRead.wav";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
player.PlaySync();
player.PlaySync();
我错过了什么?我收到的错误是“请确保指定位置存在声音文件。 它是在搜索服务器上的wav文件吗?提前谢谢。
答案 0 :(得分:2)
你读过这个:http://peterfoot.net/SystemMediaSoundPlayerVersusThePlaySoundAPI.aspx
可能你必须先发出一个player.Load()才能使用player.PlaySync:
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();
}
}
另一种方法是本机使用Play> Sound API:
http://msdn.microsoft.com/en-us/library/ms228710%28v=vs.90%29.aspx
答案 1 :(得分:0)
我使用javascript而不是尝试播放声音服务器端。
我找到了答案here