Start New Discussion within our Software Development Community

Can you help me about inserting video in resources of visual basic and how to call it and play in my media player in a form..because i have media player in my project and my problem is how can i insert video and call it from resources...

i hope you can help me..Thanks a lot..!

I am going to assume that you mean adding a video to the embedded resources.

From the menu, goto Project->Properties. Then select the "Resources" tab. Next Select "Add Rersource"->"From Existing File". You can then select your video file. The file will be inserted with the File Name minus the extension as a binary array.

As far as I know, the media player control can only except a file reference to play. Therefore, you will need to write the binary array to a temporary file first.

Private TmpFiles As New List(Of String)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim fi As New IO.FileInfo(IO.Path.GetTempFileName())

   Dim tmppath As String = IO.Path.GetTempFileName()
   ' The tmp file will have a ".tmp" extension
   ' The media player uses the extension to identify the proper codec to use to decode the file
   ' I used a wma video, so I will change the extension to that
   tmppath = tmppath.Replace(".tmp", ".wma")
   ' Create the file and write the resource array to it
   Dim tmp As IO.Stream = IO.File.Create(tmppath)
   ' Amanda is the name of my file
   tmp.Write(My.Resources.Amanda, 0, My.Resources.Amanda.Length)

   'Save a reference to tmp file so that you can delete it on the Form.Closing event

   ' tell the player to play the file
   WMP1.currentMedia = WMP1.newMedia(tmppath)

End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
   For Each file As String In TmpFiles
      Catch ex As Exception
      End Try
End Sub

Hi TnTinMN Your code works fine but when I go to debug I get this message. 'Error 1 Unable to write to output file 'C:\Users\Bill\documents\visual studio 2010\Projects\resources test 2\resources test 2\obj\x86\Debug\resources test 2.exe': System Error &H8007000e& resources test 2'
My project name is resources test 2
I was wondering if this error is generated because of the total file sizes being around half a gig and or the amount of files I have added to the resources which would total around 35.
Any idea would be helpful, thanks.

This article has been dead for over six months. Start a new discussion instead.