Solved

Play Resource AVI in MediaPlayer

Posted on 2004-04-26
15
881 Views
Last Modified: 2011-10-03
Hi.

I've got a form, onto which I have placed a MediaPlayer object.  I have created an RC file and compiled this into a RES file.  This RES file now holds an AVI file that I want to play with the MediaPlayer.

I've seen some solutions to this that involve saving the file so that you can open it directly from disk, or other solutions that can play a resource file as if using the windows "OPEN" command (opening the AVI in a seperate window - the associated AVI player), and neither of these solutions are any good to me.

I've been a Delphi programmer for many years now and am quite suprised by how difficult this task seems to be - surely I'm mistaken!

If I were to perform this task in Delphi, I would simply use the ResID or ResName property of the MediaPlayer (TAnimate, in the case of Delphi), and everything else is automatically done.

How can I play a compiled AVI resource, with a MediaPlayer on the form?

Example code would be appreciated.

Many thanks,

MoonCalf.
0
Comment
Question by:MoonCalf
  • 10
  • 5
15 Comments
 
LVL 27

Expert Comment

by:Ark
Comment Utility
Hi

For external resources I used:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long

Private Const WM_USER = &H400
Private Const ACM_OPEN = (WM_USER + 100)
Private Const ACM_PLAY = (WM_USER + 101)
Private Const ACM_STOP = (WM_USER + 102)
Dim hModule As Long

Private Sub Command1_Click()
   hModule = LoadLibrary("shell32.dll")
   Call SendMessage(Animation1.hWnd, ACM_OPEN, hModule, ByVal 150&)
   Call SendMessage(Animation1.hWnd, ACM_PLAY, -1, ByVal 0&)
End Sub

Private Sub Command2_Click()
   Call SendMessage(Animation1.hWnd, ACM_STOP, 0, ByVal 0&)
   Call SendMessage(Animation1.hWnd, ACM_OPEN, 0, ByVal 0&)
   FreeLibrary hModule
End Sub

Private Sub Form_UnLoad()
   Call SendMessage(Animation1.hWnd, ACM_STOP, 0, ByVal 0&)
   Call SendMessage(Animation1.hWnd, ACM_OPEN, 0, ByVal 0&)
   FreeLibrary hModule
End Sub
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Hi Ark.

Firstly, I'm not using an external resource (DLL or such) - I'm compiling the RES file into the executable.

Secondly, how does the use of "Animation1" relate to the use of a MediaPlayer component dropped onto a form?

Could you please make this comment relevant to the question.

Thank you,

MoonCalf.
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
Sorry if I misunderstood your question, but AFAIK TAnimate(Delphi) = Animation control (VB, MS Common control 2)
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
I'll give that a go.

Ta.
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Ark - thanks for that, but it's not made a spot of difference.  I still don't know how to assign a resource to the control.  I've created an OCX version of the Delphi TAnimate control and I'm about to test that in VB.

I'll let you know how I get on.  (I'll obviously want to delete this question if this is the solution.)

Thanks again,

MoonCalf.
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Bugger.

That didn't work.  Still need an answer to the question.

Thanks,

MoonCalf.
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Bugger.

That didn't work.  Still need an answer to the question.

Thanks,

MoonCalf.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Bugger.

That didn't work.  Still need an answer to the question.

Thanks,

MoonCalf.
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Bugger.

That didn't work.  Still need an answer to the question.

Thanks,

MoonCalf.
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Oops!
0
 
LVL 27

Accepted Solution

by:
Ark earned 250 total points
Comment Utility
Hi
Did you try

   Call SendMessage(Animation1.hWnd, ACM_OPEN, App.hInstance, ByVal 101&) 'where 101 is ResID
   Call SendMessage(Animation1.hWnd, ACM_PLAY, -1, ByVal 0&)
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
PS
You can have a look on my sample at http://www.freevbcode.com/ShowCode.Asp?ID=3185 for playing AVI without controls.
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Thanks Ark, but I'm having problems getting this to work.  I know this is going to change things, but I think the reason I'm having problems is that the animation component seems unhappy with WMV files.  (It was an AVI but was about 1/2 a gig in size - compressing to a WMV makes it about 2.5 meg!)

Any ideas?

MoonCalf.
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Is that a no?

MoonCalf.
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
Sorry, I still can not get it worked with compressed AVI :(
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now