Reputation: 1541
I am developing vb.net Windows application for playing the video file.
I have added a video file in embedded resource this way:
Project->Properties. Then select the "Resources" tab. Next Select "Add Rersource"->"From Existing File".
I am trying to play the file, buts its giving run time error on the line
Dim myByte As Byte = myStream.ReadByte
Error : Object reference not set to an instance of an object.
Here is the code...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim aPath As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly.GetModules()(0).FullyQualifiedName)
Dim myStream As Stream
myStream = Assembly.GetExecutingAssembly.GetManifestResourceStream("111.mp4")
Dim myFileStream As New FileStream("111.mp4", FileMode.Create)
Dim myFileBinary As New BinaryWriter(myFileStream)
Try
Dim myByte As Byte = myStream.ReadByte
While Not myByte = -1
myFileBinary.Write(myByte)
myByte = myStream.ReadByte
End While
Catch ex As Exception
Finally
myFileStream.Close()
End Try
AxWindowsMediaPlayer1.URL = Path.Combine(aPath, "111.mp4")
AxWindowsMediaPlayer1.settings.autoStart = True
End Sub
am I missing any step ?
Upvotes: 1
Views: 280
Reputation: 125197
In fact you are using My.Resources
. So you don't need to read the resource from assembly.
You can simply read and use it this way:
Dim FilePath = Path.Combine(Application.StartupPath, "video.wmv")
If (Not File.Exists(FilePath)) Then
File.WriteAllBytes(FilePath, My.Resources.video)
End If
AxWindowsMediaPlayer1.URL = FilePath
AxWindowsMediaPlayer1.Ctlcontrols.play()
The if part is to check if the file exists and extracted before so we don't need to extract it again.
Upvotes: 1