I have tried this in my class constructor to test the windows media player for playing sounds (specifically mp3) from files inside the .exe resource folder. It writes the file correctly to the temp diectory and the file plays just fine if launched from the folder both in WMP and VLC.
But I still cannot get the sound to play in the app.
class AudioPlayer
{
private static string _tempFolder;
private static string _filename;
private string _musicPath;
public WindowsMediaPlayer _wmp;
public AudioPlayer()
{
_tempFolder = Path.GetTempPath();
_filename = "Music1.mp3";
_musicPath = Path.Combine(_tempFolder,_filename);
CopyResource(_musicPath, Resources.Music1);
_wmp = new WindowsMediaPlayer();
_wmp.URL = _musicPath;
_wmp.controls.play();
}
private void CopyResource(string resourceName, byte[] file)
{
File.WriteAllBytes(resourceName, file);
}
}
Would this be a threading issue? I would think not since this is a form creating the audio player not a console app so it does not terminate immediately. I also get no errors indicating an issue with playback.