Play avi from resource vb 10 RRS feed

  • Question

  • I uploaded a file in the resources of Visual Basic 2010 and I do not know how to play it, I do not have the very least udea, Help me!!!
    Saturday, August 25, 2018 4:22 PM

All replies

  • It is not clear exactly what you mean.

    Are you using You mean you have an avi file in your resources for your single vb project?

    I am not sure if you can play the video from resources you may have to save it to disk.

    This example shows how to play an .avi file in windows media player from the hard drive.

    Public Class Form6
        Private WithEvents Player As New WMPLib.WindowsMediaPlayer
        Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
            'shows in media player
        End Sub
    End Class

    Saturday, August 25, 2018 5:14 PM
  • It can be played directly from resources with Media Foundation

    (with MFCreateMFByteStreamOnStream)

    (tested on Windows 10, VS 2015, .NET 4.5.2)

    But it needs a lot of code for all the Interfaces declarations...

    Sunday, August 26, 2018 1:02 PM
  •  You would be further ahead and make your life easier if you just write the avi file back to the hard drive from your resources and then just supply it's filename to the player of your choice.  You could write it to the Temp folder for temporary use or to the App Data folder if it is needed on every run of your application.

     As a side note,  I would not recommend embedding large avi files into your application resources,  I would just keep them in a relative folder to the application's exe and set up your application's installer to include the folder with the installation of your application.

     Here is a short example of writing an avi file to the Temp folder,  playing it,  and then deleting it when the form closes.

    Imports System.IO
    Public Class Form1
        Private tempfilename As String = Path.Combine(Path.GetTempPath, "MyAviFile.avi")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If Not File.Exists(tempfilename) Then
                File.WriteAllBytes(tempfilename, My.Resources.MyVideo)
            End If
            AxWindowsMediaPlayer1.settings.autoStart = False
            AxWindowsMediaPlayer1.URL = tempfilename
        End Sub
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            If File.Exists(tempfilename) Then
            End If
        End Sub
    End Class

    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, August 26, 2018 11:24 PM
    Sunday, August 26, 2018 2:22 PM
  • Hi,

    Try the following code to import the file into your local disk.

    Dim b() As Byte = My.Resources.Resource1._11
            Dim s As IO.Stream = File.Create("1.avi")
            s.Write(b, 0, b.Length)

    Remember to delete the file

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, August 29, 2018 6:03 AM