title: Play mp3 from my.resources using WMPLib.WindowsMediaPlayer from released application without writing file to client computer VB Express 2012, VB.net
body: <p>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.</p>
  
  <p><strong><em>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?</em></strong>  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:</p>
  
  <p><strong>For the sound effects I use</strong></p>
  
  <pre><code>My.Computer.Audio.Play(My.Resources.soundeffect, AudioPlayMode.Background) 
  </code></pre>
  
  <p><strong>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:</strong></p>
  
  <pre><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 &amp; "\" &amp; "SongNameHere" &amp; ".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
  </code></pre>
  
  <p> </p>
  
  <p><strong>And, just in case it is important, on .formclosing I delete the songs with the following code:</strong></p>
  
  <pre><code>My.Computer.FileSystem.DeleteFile(Application.StartupPath &amp; "\" &amp; "SongNameHere" &amp; ".mp3")
  </code></pre>