-
Nov 18th, 2015, 08:09 AM
#1
Thread Starter
New Member
Application.Startup not working
Hi,
Have simple code that when form opens it plays a audio file. I embed the file in bin\Debug. Also added file a Resource. I want the file to be embed in the exe so I have to only give one file.
MediaPlayer1.URL = Application.StartupPath & "\resources\My Country Tis of Thee.mp3"
This does not work.
MediaPlayer1.URL = My.Resources"My Country Tis of Thee.mp3" shows error
Error 1 'President_Nov.My.Resources' is a namespace and cannot be used as an expression.
If needed I can submit entire code.
Thanks
Bobv
-
Nov 18th, 2015, 09:30 AM
#2
Re: Application.Startup not working
Hi,
As far as I am aware the Windows Media Player expects a URL to a File of the correct format so that it can be played. Therefore if you want to embed your sound file as a Resource so that you only have one EXE file then you need to be able to strip out the Sound File element of the EXE file into a different temporary file and then play that file.
Since all File Resources are embedded as Byte Arrays you can easily write this file out to a temporary file and then play that file. Have a look at this example:-
vb.net Code:
Dim tempFileName As String = IO.Path.GetTempFileName IO.File.WriteAllBytes(tempFileName, My.Resources.SomeSoundFile) MsgBox("play the File :-" & tempFileName)
If for some reason the Windows Media Player expects (and will only play) a file name with an MP3 File Extension then you can also use the IO.Path Class to change the temporary file names extension as you need.
Hope that helps.
Cheers,
Ian
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|