Play sound file on windows mobile device (.wav specifically)
-
17-06-2021 - |
Question
I want to play a .wav file on a mobile device. I guess my trouble lies in actually accessing the file correctly. The following is the code I currently have:
string path = "\\Windows\\badRead.wav";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
player.PlaySync();
player.PlaySync();
What am I missing? The error I'm receiving is "Please be sure a sound file exists at the specified location. IS it that it's searching for the wav file on the server? Thank you in advance.
Solution 2
I used javascript instead of trying to play the sound server side.
I found my answer here
OTHER TIPS
Have you read this: http://peterfoot.net/SystemMediaSoundPlayerVersusThePlaySoundAPI.aspx
Possibly you have to issue a player.Load() first before using 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();
}
}
Another approach would be to use the Play>Sound API natively:
http://msdn.microsoft.com/en-us/library/ms228710%28v=vs.90%29.aspx