Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Play video file that is embedded to resources 1

Status
Not open for further replies.

ZmrAbdulla

Technical User
Apr 22, 2003
4,364
AE
Is that possible to play a video (avi/mpg/wmv) that is added to the resources? I have inserted a "AxWindowsMediaPlayer" on the form. It can play video file from the hard disk using the following code.
[tt]AxWindowsMediaPlayer1.URL = "C:\test.wmv"[/tt]

not from resources.
Any help? Thanks

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Yes it is possible and you will need a stream and I know it was covered in this forum before, a long long time ago. I see if I can find anything.

Christiaan Baes
Belgium

"My new site" - Me
 
Thanks chrissie.. I will have a try on that.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Thanks..I have tried both... still no success..

The one that Chrissie had suggested shows an image. I having trouble to convert it to video.

Also tried Prashant's link. It gives me an error.
Code:
System.Runtime.InteropServices.COMException was unhandled
  ErrorCode=-2147467259
  Message="Error HRESULT E_FAIL has been returned from a call to a COM component."
  Source="Interop.MediaPlayer"
  StackTrace:
       at MediaPlayer.IMediaPlayer2.Play()
       at AxMediaPlayer.AxMediaPlayer.Play()
       at testssaver.Form1.Button1_Click(Object sender, EventArgs e) in C:\My Documents\Visual Studio 2005\Projects\testssaver\testssaver\Form1.vb:line 26
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at testssaver.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Thanks for any help

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Can you post some part of the code?
The code where the embedded resource is read...
Which references are you using?


Sharing the best from my side...

--Prashant--
 
Code:
Imports System.IO
Imports AxMediaPlayer
'----------------------------------------
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim MyStream As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("testsaver.WJB.mpg")
        Dim MyFileStream As New System.IO.FileStream("TempFile.mpg", IO.FileMode.Create)
        Dim MyBinaryWriter As New IO.BinaryWriter(MyFileStream)

        Try
            Dim MyByte As Byte = MyStream.ReadByte
            While Not MyByte = -1
                MyBinaryWriter.Write(MyByte)
                MyByte = MyStream.ReadByte
            End While
        Catch ex As Exception
        Finally
            MyFileStream.Close()
        End Try
        Me.AxMediaPlayer1.FileName = "TempFile.mpg"
        [COLOR=red]Me.AxMediaPlayer1.Play()[/color]
    End Sub
The error is at the red line.
For references I am using Window Media Player from COM objects(msdxm.ocx , wmp.dll)
Do I need any more references?

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
I think you missed something...
- Check whether you get 'MyStream'?

I used following code on my system.
Code:
Imports System.IO
Imports System.Reflection
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myStream As Stream
        myStream = Assembly.GetExecutingAssembly.GetManifestResourceStream("WindowsApplication1.Job1.wmv")
        Dim myFileStream As New FileStream("Job1.wmv", 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
        m1.settings.autoStart = True
        m1.URL = Path.Combine('Your Application Root', "\bin\Debug\Job1.wmv"
    End Sub
End Class

Sharing the best from my side...

--Prashant--
 
Sorry...Some remaining part...
You can get the path as:
Code:
        Dim aPath As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly.GetModules()(0).FullyQualifiedName)
and use this path to make a url as:
Code:
m1.URL = Path.Combine(aPath, "Job1.wmv")

Sharing the best from my side...

--Prashant--
 
Still not working. I didn't get enough time to look into that... I will try again.

BTW..
Can I become a fool for a moment?

The files that are embedded into the resources is compiled into the exe.. am I right?

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Thanks for the "Yes and yes"
Ofcourse for becoming a matching friend[wink]

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Success!! with a small problem...
It is working, also throwing an error.

"A first chance exception of type 'System.OverflowException' occurred in NewSaver.exe"



________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Ditto... Prashant's code
Code:
Imports System.IO
Imports System.Reflection

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim aPath As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly.GetModules()(0).FullyQualifiedName)
                Dim myStream As Stream
        myStream = Assembly.GetExecutingAssembly.GetManifestResourceStream("NewSaver.WJB.mpg")
        Dim myFileStream As New FileStream("WJB.mpg", 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, "WJB.mpg")
        AxWindowsMediaPlayer1.settings.autoStart = True
    End Sub
End Class


________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Nice to see that you got your problem solved...Happy ending.
[2thumbsup]


Sharing the best from my side...

--Prashant--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top