Page 1 of 1

Play sounds and videos with VBScript

PostPosted: Thu Dec 29, 2005 8:18 pm
by GM-Support
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

Re: Play sounds and videos with VBScript

PostPosted: Fri Dec 30, 2005 5:20 am
by Skye
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

PostPosted: Fri Dec 30, 2005 9:56 am
by GM-Support
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

PostPosted: Fri Dec 30, 2005 7:20 pm
by ShadowHunter
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

PostPosted: Fri Dec 30, 2005 8:34 pm
by GM-Support
You are right!

Thanks,
GM-Support

PostPosted: Sun Jan 01, 2006 5:03 am
by Candle
What would the path be if you use the External folder?

PostPosted: Sun Jan 01, 2006 11:34 am
by GM-Support
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

PostPosted: Sun Jan 01, 2006 6:15 pm
by Candle
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

PostPosted: Mon Jan 02, 2006 5:43 am
by Skye
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

Re: Play sounds and videos with VBScript

PostPosted: Sat Aug 09, 2008 2:55 pm
by cpkspikyhair
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

PostPosted: Sat Aug 09, 2008 2:58 pm
by Mystery
Code: Select all
PlaySound GetPath(2) + "filename.mp3", False


Path 2 is the External Folder.

PostPosted: Sat Aug 09, 2008 2:59 pm
by cpkspikyhair
Mystery wrote:
Code: Select all
PlaySound GetPath(2) + "filename.mp3", False


That isn't needed because GetPath returns to the External subfolder.

PostPosted: Sat Aug 09, 2008 3:03 pm
by Mystery
Right, both work :D

PostPosted: Fri Dec 11, 2009 3:33 pm
by MikeTn1
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.

PostPosted: Fri Dec 11, 2009 5:23 pm
by reneuend
See my reply in the other thread you had posted about this.

PostPosted: Mon Dec 14, 2009 3:39 pm
by MikeTn1
thanks for your reply. It turns out that I was able to fix the problem over the weekend. Thanks again.