VBScript: Check if video is playing OR pause script?

This forum is meant for posting anything related to Adventure Maker that doesn't fit in the other forums.Please post technical questions in the Technical Support Forum!

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

VBScript: Check if video is playing OR pause script?

Postby CBSection31 » Fri Apr 24, 2009 8:25 am

Hi everyone,

I need to play a series of videos one after the other in AM, which is easy to do...except that the order in which the videos play needs to be random.

So I've created a sub with all the required code to randomly choose what videos to play and in what order. The problem is, predictably, that - when I call the sub - only the last video in the sub plays, because the code doesn't pause until each video completes.

So my question is, would there be a way of checking if a video is playing using VBScript? That way I can do something such as this:

PlayVideo "video1.avi"
While Video 1 is playing, wait/loop
PlayVideo "video2.avi"

Video 2 will not begin until Video 1 ends.

As an alternative to this, is there a way of pausing the code for a set number of seconds? That way, I can do this:

PlayVideo "video1.avi"
Pause for the length of video 1
PlayVideo "video2.avi"

Either would work for me. I'm hoping someone here can help me. Thanks in advance, everyone! :)
CBSection31
Code Master
 
Posts: 564
Joined: Tue Jun 10, 2003 4:00 am

Postby juhuwoorps » Fri Apr 24, 2009 8:33 am

You have to create a timed event between the PlayVideo commands with the time of the length from the video
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby ShadowHunter » Fri Apr 24, 2009 10:01 am

Hi,

The timed event is not the best solution as the timer in AM is far from perfect... it varies per computer and workload... so don't use it for the lenght of the clip...

First check out link for all available options for the Media Player control:

http://www.w3schools.com/media/media_playerref.asp

Next you can use a timed event to check if the movie has ended and start another one, you can be off only by 0.1 second that way :D

This should help you start going :wink:

With best regards,

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

Postby Lyberodoggy » Fri Apr 24, 2009 10:33 am

Hey guys!
Would it be possible to create a video playlist with random order and load it to the object?
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby ShadowHunter » Fri Apr 24, 2009 2:01 pm

Should be perfectly possible :D

In EZTalk I check for the end of the sound file (question) to automatically start the (answer) :D

With best regards,

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

Postby CBSection31 » Fri Apr 24, 2009 7:18 pm

Thanks, Shadowhunter. That helps a LOT!!!

ShadowHunter wrote:Hi,

The timed event is not the best solution as the timer in AM is far from perfect... it varies per computer and workload... so don't use it for the lenght of the clip...


Wow, I didn't know this. Is the "jump to another frame after # seconds" tickbox feature of AM inaccurate, as well? If so, by how much? Will it ever jump to the next frame prematurely, or is the only danger that it delays the jump? I think I'm going to have to go and change some existing code now... LOL
CBSection31
Code Master
 
Posts: 564
Joined: Tue Jun 10, 2003 4:00 am

Postby CBSection31 » Fri Apr 24, 2009 8:50 pm

Sorry for the double post, but I've been playing around with various options from the link Shadowhunter posted, and I cannot seem to figure out a way to determine if the video has ended playing. Everything I do freezes the AM window... I'm not very well trained in programming, as you can see, so I'm hoping someone can guide me as to the actual code to use here. Thanks!
CBSection31
Code Master
 
Posts: 564
Joined: Tue Jun 10, 2003 4:00 am

Re: VBScript: Check if video is playing OR pause script?

Postby 3dgamer » Sat Apr 25, 2009 10:16 am

CBSection31 wrote:So I've created a sub with all the required code to randomly choose what videos to play and in what order. The problem is, predictably, that - when I call the sub - only the last video in the sub plays, because the code doesn't pause until each video completes.


Is there a way we can have a look at your original code? It would make it a bit easier to see what might be the situation. I'm new at VB myself, but I use videos in my games, too. I have a random video code that works, but may or may not contain the solution you are looking for.

Take care.
3DGamer
User avatar
3dgamer
Expert Member
 
Posts: 301
Joined: Mon Dec 15, 2008 7:12 am

Postby CBSection31 » Sat Apr 25, 2009 7:48 pm

Sure. I'll post a simplified version of it below, because the full code is too long and complicate to be relevent here. The problem I'm having isn't with the randomization of the videos, it is solely with having a pause between videos.

Originally, I was just going to go to a new frame for each video, and have the frame delay for the number of seconds of the video before going to a new frame...but according to Shadowhunter, the AM timer isn't perfect. :(

Code: Select all
Sub Puzzle

PlayVideo GetPath(2) + "Puzzlestart.avi", 0, 0, 1024, 768, False

' Need to add delay code here!

Pos1=1
Pos2=2
Pos3=3
Times=0
randomize
ChosenNum=int(rnd*(3))+1
randomize
Movement=int(rnd*(3))+1

Do Until Times = 5
If Movement=1 Then
   PosTemp=Pos1
   Pos1=Pos2
   Pos2=PosTemp
   PlayVideo GetPath(2) + "puzzleswitch1and2.avi", 0, 0, 1024, 768, False
End If
If Movement=2 Then
   PosTemp=Pos2
   Pos2=Pos3
   Pos3=PosTemp
   PlayVideo GetPath(2) + "puzzleswitch2and3.avi", 0, 0, 1024, 768, False
End If
If Movement=3 Then
   PosTemp=Pos1
   Pos1=Pos3
   Pos3=PosTemp
   PlayVideo GetPath(2) + "puzzleswitch1and3.avi", 0, 0, 1024, 768, False
End If

' Need to add delay code here!

Times=Times+1
Loop
PlayVideo GetPath(2) + "puzzleend.avi", 0, 0, 1024, 768, False

' Need to add delay code here!

Action.GoToFrame "PuzzleEnd"

End Sub
CBSection31
Code Master
 
Posts: 564
Joined: Tue Jun 10, 2003 4:00 am

Postby Lyberodoggy » Sat Apr 25, 2009 8:06 pm

I 'd suggest going for your original idea.

First of all create one frame for each video.
Go to actions-> play a video - > before frame loads

Then set the frame timer to 0.1

Ready... No timer problems because the video will play before the frame is loaded
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby CBSection31 » Sat Apr 25, 2009 10:00 pm

The only problem I foresee is whether or not having a sub jump to a frame when that sub is called in the Frame Properties will cause a crash. I'll give it a try and report back here. :)
CBSection31
Code Master
 
Posts: 564
Joined: Tue Jun 10, 2003 4:00 am

Postby CBSection31 » Sat Apr 25, 2009 10:29 pm

Okay, I've just tested it, and yes--there is a problem. If I call a subroutine via VBScript at the start of a frame, and the subroutine tells the engine to go to a new frame, then the engine doesn't comply. :?

I'll keep playing around to see if I can find a workaround.

EDIT - Found a solution!!!

I created one frame for each video, as was suggested by Lyberodoggy, with each video playing before the frame begins. I then have each of those frames going to a frame I labelled "PUZZLE MAIN" after 0.1 seconds.

In PUZZLE MAIN, when I called the subroutine, it wouldn't work, since AM won't go to a new frame when a frame has just been loaded. So what I did instead was created a timed event that calls the subroutine after 0.1 seconds. Then it worked!

In effect, for X number of times, PUZZLE MAIN will randomly go to one of several frames, which then go back to PUZZLE MAIN. It works perfectly, and since I am not relying on the timer for the videos, I don't have to worry about any time issues on different computers.

Thanks, everyone!!! :)
CBSection31
Code Master
 
Posts: 564
Joined: Tue Jun 10, 2003 4:00 am

Postby 3dgamer » Sun Apr 26, 2009 5:38 am

That's great to hear that you got it resolved, CBSection31! :)

Hope all continues to go well with your game and love to see it when you are finished.

Take care!
3DGamer
User avatar
3dgamer
Expert Member
 
Posts: 301
Joined: Mon Dec 15, 2008 7:12 am

Postby CBSection31 » Sun Apr 26, 2009 5:52 am

Thanks, 3dgamer. I'll definitely post here when my game's done. It'll be a few months, though. I'm only done with 4 out of the 35 puzzles in the game. ;)
CBSection31
Code Master
 
Posts: 564
Joined: Tue Jun 10, 2003 4:00 am

Postby Lyberodoggy » Sun Apr 26, 2009 10:33 am

Best luck with it.
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens


Return to Adventure Maker General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron