I am using VB Express 2012 (VB.net) to make a game for educational use in schools that has .wav sound effects and .mp3 background music. My code is given below, and works fine on any personal computer, but hits a roadblock for computers where permission is not granted to write / delete files to the folder containing the application execute file due to my method for playing mp3's using WMPLib.WindowsMediaPlayer. Since wmp requires a URL to an external file for mp3 files (Why???), I have to write the mp3s from my.resource folder to the client computer to obtain a valid URL, then delete them upon closing the program. This fails if permission is not granted.
Is there another way to play an mp3 file from my.resources from the released application using the wmp.dll that does NOT require writing the file to the client computer? Streaming of some sort perhaps? I have never delved into that area before. By the way, it is unreasonable to convert my mp3s to wav files since the size of the application would be way too large. (I have many mp3s, although my code snippet only shows one as an example. Here's my Code:
For the sound effects I use
My.Computer.Audio.Play(My.Resources.soundeffect, AudioPlayMode.Background)
For the background music, in order for the songs to play uninterrupted by sound effects I added the wmp.dll reference and use the following code:
Dim WithEvents Player As New WMPLib.WindowsMediaPlayer
Player.settings.setMode("Loop", True)
Dim appPath As String
'get the location of application execute file
appPath = Application.StartupPath & "\" & "SongNameHere" & ".mp3"
'write the mp3 file to the folder containing the execute file so wmp accepts the URL
My.Computer.FileSystem.WriteAllBytes(appPath,My.Resources.ResourceManager.GetObject("SongNameHere"), False)
'assign the valid URL to the wmp player, it autostarts.
Player.URL = appPath
And, just in case it is important, on .formclosing I delete the songs with the following code:
My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\" & "SongNameHere" & ".mp3")