I know pictures can be added to picture boxes and backgrounds by using the "Properties" and adding something to "Picture". But I want to know how I can actually get the program to display an animation or picture say, after inputting something into an inputbox, or say after a particular msgbox has been clicked "ok" and then for the picture or animation to show up...Something within the code itself I'm figuring, something that will be triggered after the user has begun the program and started doing stuff, not by clicking a button specifically. Can anyone understand me and better yet help me out?

Recommended Answers

All 10 Replies

Member Avatar for AlanC

Hi again..

Sounds like you want to play a video or animation - such as an mpeg or avi or so on.. the trigger event isn't the difficult bit, it's how to play it that might be...

There's several ways to do what you want. The easy way is to use the mediaplayer activex control that comes with DirectX. This is different to the one that media player upgrades install (wmp.dll), which is not as flexible for us VB types. In your Windows/system folder (or system32 if you're on win2K or XP) look for the file msdxm.ocx. If it's not there, go to Microsoft's web site and download and install DirectX. If it is, on VB go to Project -> Components; in the list find Windows Media Player and tick it, and click Apply & Close.

On your control toolbar you should now see the 'old' media player icon (like a clapperboard) Click this, and add it to your form. If you drag it out to a reasonable size, you'll see it is actually a mediaplayer with a display area and controls. You can remove the controls by setting the ShowControls property to false; you might want to play with these properties to get what you want.

Now to control it programmatically, you need to open a file, and then play it.

For a quick demo add a command button and paste this code:

Private Sub Command1_Click()
   MediaPlayer1.FileName = "c:\creamedgates.mpeg"
   MediaPlayer1.play
End Sub

You'll get a more instant response if you load the file at some time before you want to play it.

(see http://www.bitstorm.org/gates/ for this video clip :cheesy: )

Hope this helps
Alan :cool:

for just pictures, you can add textbox or variable values to the picture object to load a new picture if you use the correct format.

image1.picture =loadpicture("c:\vbrox.bmp")
image1.picture =loadpicture(text1.text)
image1.picture =loadpicture(strImage)

Yet to try shepherds tip, but alan I can get the thing to work. I added the command button and the WMP thingy/console onto the form, and put the code, but when i play and click the button it just says

"Run-Time Error '424':
Object Required"

Okay So Sorry. I just realised my lame and stupid mistake of the Object Required. Have now changed the objects name in the code that you provided. However if I want to get the path of my own movie file correct I'm not sure what to type...I've tried alot but nothing works...

Member Avatar for AlanC

OK so if I'd read your original post properly... for loading a still image into an image control jwshepherds code will work fine. But back to the movies!

Now if you had to change the object name, you might have used the new mediaplayer. No problem if it works for you in your application.

Getting the path right is something you need to be aware of when developing in VB, and it's best to explicitly set it. Two useful things are the App.Path property which returns the path of the application as a string... just type in the 'immediate' window of your VB editor:

print app.path

Hit enter and you should see:
C:\Program Files\Microsoft Visual Studio\VB98\MyApp
or similar. The other useful thing is the ChDir command, which sets the current directory. The 'current directory' is where VB will look for any file you specify without the full path. You'll probably want to use the directory the app runs out of for any associated files, so you can use the following statement to change the directory to the application's:

'change directory to the application's
ChDir App.Path
'load the file
mediaplayer1.filename="intro.mpg"

You can also use the App.Path property together with a filename like these examples:

mediaplayer1.filename=app.path & "\intro.mpg"
'when the files dir is a sub-dir of the application's
mediaplayer1.filename=app.path & "\music\background.mp3"

Note that the backslash has to be provided as the path doesn't include this. Beware of hard-coding paths into your program- if the user installs it somewhere else, they'll get an error when the app tries to load the file; so the method shown above is good practice.

cheers
Alan

Member Avatar for AlanC

Or, do you want to be able to select a file at runtime using the standard Windows 'open file' dialog?

No, the user get not control whatsoever. Heh... ok now here's the new problem. I get evrything done like you said, but when I run it, I get another runtime error:

"Run-Time Error '438':
Object doesn't support this property or method."

I got that with your previous tips as well. Then to debug it it highlights :

WindowsMediaPlayer1.FileName = App.Path & "\car.mpg"

which is the file I am trying to play. I actually moved the car.mpg file into my vb directory that was shown. hehe coz I didn't know how to change it in this... "VB editor". Whats that? I just opened a form and askde the program to "Print App.Path" from a command button.

Member Avatar for AlanC

Right. Sounds like you're using the 'wrong' mediaplayer. That explains the previous error you got as well! That's why I went on about msdxm.ocx; if you followed what I said in the very first reply you should be able to find this file (From Project menu -> components, click the browse button and look in either Windows/System or Windows/System32 for the file msdxm.ocx or msdxmp.ocx. When you've found it click 'open'. You may have two 'Windows Media Player' entries in the components list now. You need to select the one that, when highlighted, gives a line similar to:
c:\windows\system\msdxm.ocx
in the frame below the components list. When you check it and click Apply, it should look like a little film clapperboard in the object panel on the left of your screen. When you add it to your form, it's default name will be 'MediaPlayer1' This has loads more properties than the WMP.DLL one, which calls itself WindowsMediaPlayer1.

What version of VB are you using?

By the Editor I meant the VB IDE- the project design screen; if you don't have a window called 'immediate' then click View on the menu and then Immediate and it should appear. You can use this to test VB commands, and also get your program to print diagnostic info to it using statements like 'debug.print <variable>'.

Let me know how you get on.

Cheers
Alan

Okay this is not easy. I put my file into my project application path and when I do that :mediaplayer1.filename="intro.mpg i still get "Object ruquired" Runtime error 424... So sorry for the trouble. Lemme try again dont reply yet.

mediaplayer1.filename="intro.mpg
should be changed to
mediaplayer1.filename=app.path & "\" & "intro.mpg"

I ctually tried it. It might be my version of windows media player, but this did not work. There is no filename method.

Mine works with :
mediaplayer1.url=app.path & "\intro.mpg"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.