Play sounds and videos with VBScript

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Play sounds and videos with VBScript

Postby GM-Support » Thu Dec 29, 2005 8:18 pm

Hi,

To be able to play audio and video files from VBScript, simply copy/paste the following code into the "VBScript Global Procedures" window:



Code: Select all
Sub PlayVideo(FileName, Left, Top, Width, Height, Repeat)
   Action.LoadControl MediaPlayerObject(1)
   MediaPlayerObject(1).Move Left*ScreenObject.TwipsPerPixelX, Top*ScreenObject.TwipsPerPixelX, Width*ScreenObject.TwipsPerPixelY, Height*ScreenObject.TwipsPerPixelY
   MediaPlayerObject(1).FileName = FileName
   If Repeat = True Then
      MediaPlayerObject(1).PlayCount = 0
   Else
      MediaPlayerObject(1).PlayCount = 1
   End If
   MediaPlayerObject(1).Visible = True
   MediaPlayerObject(1).Play
End Sub
Sub PlaySound(FileName, Repeat)
   Action.LoadControl MediaPlayerObject(2)
   MediaPlayerObject(2).FileName = FileName
   If Repeat = True Then
      MediaPlayerObject(2).PlayCount = 0
   Else
      MediaPlayerObject(2).PlayCount = 1
   End If
   MediaPlayerObject(2).Play
End Sub
Sub StopVideo()
   MediaPlayerObject(1).Visible = False
   MediaPlayerObject(1).Stop
   MediaPlayerObject(1).FileName = ""
   Action.UnloadControl MediaPlayerObject(1)
End Sub
Sub StopSound()
   MediaPlayerObject(2).Stop
   MediaPlayerObject(2).FileName = ""
   Action.UnloadControl MediaPlayerObject(2)
End Sub




Then you can use the "PlayVideo", "StopVideo", "PlaySound" and "StopSound" function.

For example, to play a video full-screen, type:
Code: Select all
PlayVideo "c:\filename.avi", 0, 0, 640, 480, False


If the video is located in your "Frames" folder, use the "GetPath(5)" command:
Code: Select all
PlayVideo GetPath(5) + "filename.avi", 0, 0, 640, 480, False


To make the video loop forever, just replace "False" with "True" in the line above.

To stop the video, simply type:
Code: Select all
StopVideo


To play a sound, type:
Code: Select all
PlaySound "c:\filename.mp3", False


If the sound file is located in your "Areas" folder, use the "GetPath(4)" command:
Code: Select all
PlaySound GetPath(4) + "c:\filename.mp3", False


To make the sound loop forever, just replace "False" with "True" in the line above.

To stop the sound, simply type:
Code: Select all
StopSound



Please feel free to let me know if you have any questions.

Best regards,

GM-Support
Last edited by GM-Support on Fri Dec 30, 2005 9:55 am, edited 1 time in total.
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Re: Play sounds and videos with VBScript

Postby Skye » Fri Dec 30, 2005 5:20 am

GM-Support wrote:
If the sound file is located in your "Areas" folder, use the "GetPath(4)" command:
Code: Select all
PlayVideo GetPath(4) + "c:\filename.mp3", False




I believe you have a typo in the above piece of code. It should read:
Code: Select all
 PlaySound GetPath(4) + "c:\filename.mp3", False


Skye
Skye
Expert Member
 
Posts: 325
Joined: Sat Sep 13, 2003 4:19 pm
Location: British Columbia, Canada

Postby GM-Support » Fri Dec 30, 2005 9:56 am

Thanks a lot Skye!

Yes, there was a typo. I have just fixed it in the original post, so now it should be ok.

Thanks again!
GM-Support
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Postby ShadowHunter » Fri Dec 30, 2005 7:20 pm

Hi,

I might be wrong but files exention in the all the AM-folders except for the "External" folder will be scrambled. Hence the the file will not be found resulting in an "automation error"

So if you are using the above commands (like I do al the time :wink:) you need to place the video or audio files in the "External" folder to make it work.

It will work during design but not when compiled :wink:

Please correct me if I'm wrong !

Kind regards,

ShAdOwHuNtEr
User avatar
ShadowHunter
Forum Admin and Games Page admin
 
Posts: 1304
Joined: Fri Jun 06, 2003 10:37 pm
Location: Belgium

Postby GM-Support » Fri Dec 30, 2005 8:34 pm

You are right!

Thanks,
GM-Support
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Postby Candle » Sun Jan 01, 2006 5:03 am

What would the path be if you use the External folder?
Please don't PM me questions, ask here in the forums!
``````````````
Between grand theft and a legal fee, there only stands a law degree.
User avatar
Candle
Administrator
 
Posts: 3057
Joined: Sat Feb 07, 2004 2:21 am
Location: Rudy's Bar

Postby GM-Support » Sun Jan 01, 2006 11:34 am

It would be GetPath(2)

The list of all the paths is available at:
http://www.adventuremaker.com/help/vbsc ... erence.htm
(look at the description of the GetPath function)

Best regards,
GM-Support
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Postby Candle » Sun Jan 01, 2006 6:15 pm

Thanks , for anyone else :

GetPath Returns the path that corresponds to the "External" sub-folder of the project folder.

To return the path of a different folder, call the GetPath function with one of the following arguments:

0 : location of the project folder
1: location of the "Root" sub-folder (in the compiled version of the project, it corresponds to the project folder)
2: location of the "External" sub-folder (default)
3: location of the "Config" sub-folder
4: location of the "Areas" sub-folder
5: location of the "Frames" sub-folder
6: location of the "FramesData" sub-folder
7: location of the "Icons" sub-folder
Please don't PM me questions, ask here in the forums!
``````````````
Between grand theft and a legal fee, there only stands a law degree.
User avatar
Candle
Administrator
 
Posts: 3057
Joined: Sat Feb 07, 2004 2:21 am
Location: Rudy's Bar

Postby Skye » Mon Jan 02, 2006 5:43 am

ShadowHunter wrote:Hi,

I might be wrong but files exention in the all the AM-folders except for the "External" folder will be scrambled. Hence the the file will not be found resulting in an "automation error"

So if you are using the above commands (like I do al the time :wink:) you need to place the video or audio files in the "External" folder to make it work.

It will work during design but not when compiled :wink:

Please correct me if I'm wrong !

Kind regards,

ShAdOwHuNtEr


Thanks heaps for this tidbit of information. I usually test my game in the debug mode of AM and it never occurred to me that there could be a problem.

Skye
Skye
Expert Member
 
Posts: 325
Joined: Sat Sep 13, 2003 4:19 pm
Location: British Columbia, Canada

Re: Play sounds and videos with VBScript

Postby cpkspikyhair » Sat Aug 09, 2008 2:55 pm

PlaySound GetPath(4) + "c:\filename.mp3", False


I believe that during the GetPath function you cannot add the drive name, so the correct code if the file is in the External folder would be:

Code: Select all
PlaySound GetPath + "filename.mp3", False
PSPPC GameMaker!! Where you can find PSP and PC games up for download!
User avatar
cpkspikyhair
Games Page Administrator
 
Posts: 425
Joined: Thu Jun 28, 2007 1:49 pm
Location: On Mars (Yes There Is Water :) )

Postby Mystery » Sat Aug 09, 2008 2:58 pm

Code: Select all
PlaySound GetPath(2) + "filename.mp3", False


Path 2 is the External Folder.
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby cpkspikyhair » Sat Aug 09, 2008 2:59 pm

Mystery wrote:
Code: Select all
PlaySound GetPath(2) + "filename.mp3", False


That isn't needed because GetPath returns to the External subfolder.
PSPPC GameMaker!! Where you can find PSP and PC games up for download!
User avatar
cpkspikyhair
Games Page Administrator
 
Posts: 425
Joined: Thu Jun 28, 2007 1:49 pm
Location: On Mars (Yes There Is Water :) )

Postby Mystery » Sat Aug 09, 2008 3:03 pm

Right, both work :D
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby MikeTn1 » Fri Dec 11, 2009 3:33 pm

I loaded the code for the sub PlayVideo. When I tried it out, it started windows media player (just as though I was starting it from my desktop) and NOT AS part of the game I am creating. Is it supposed to do this?

I used the following code inside the program (substituting the proper file name and path):

PlayVideo "c:\filename.avi", 0, 0, 640, 480, False

Is it supposed to start media player to play the video? I want to insert it seamlessly into the openning frame of my game.
User avatar
MikeTn1
Member
 
Posts: 49
Joined: Fri Dec 11, 2009 3:25 pm

Postby reneuend » Fri Dec 11, 2009 5:23 pm

See my reply in the other thread you had posted about this.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2718
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby MikeTn1 » Mon Dec 14, 2009 3:39 pm

thanks for your reply. It turns out that I was able to fix the problem over the weekend. Thanks again.
User avatar
MikeTn1
Member
 
Posts: 49
Joined: Fri Dec 11, 2009 3:25 pm


Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron