Video control

Posted By: middleagechinese

Video control - 10/18/17 07:14

I made some mistake here, and I wasn't able to find it yet.
But after the first video plays, the loop, that is suppose to play afterwards does not play.
Can anybody give me an hint why that is?

Code:
function handle_videos()
{
	while(1)
	{
		if(intro_played == 1)
		{
			intro_played = 0;
			var handle_intro_played = media_play("demo.ogg",NULL,100); 
			while(handle_intro_played){wait(1);}
			media_stop(handle_intro_played);
			wait(1);
			start_loop1 = 1;
		}
		if(start_loop1 == 1)
		{
			start_loop1 = 0;
			var handle_start_loop1 = media_loop("demo.ogg",NULL,100); 
		}
		wait(1);
	}	
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

function start_into()
{
	intro_played = 1;
	start_loop1 = 0;
	start_choice1 = 0;
	start_choice2 = 0;
	intro_room1 = 0;
	room1_loop1 = 0;
	room1_choice1 = 0;
	room1_choice2 = 0;
	room1_action_loop = 0;
	room1_action_loop_fail = 0;
	room1_action_loop_win = 0;
	room1_exit = 0;
	intro_room2 = 0;
	room2_loop2 = 0;
	room2_choice1 = 0;
	room2_choice2 = 0;
	room2_action_loop = 0;
	room2_action_loop_fail = 0;
	room2_action_loop_win = 0;
	room2_exit = 0;
	intro_room3 = 0;
	room3_loop1 = 0;
	room3_choice1 = 0;
	room3_choice2 = 0;
	room3_action_loop = 0;
	room3_action_loop_fail = 0;
	room3_action_loop_win = 0;
	room3_exit = 0;
	intro_room4 = 0;
	room4_loop1 = 0;
	room4_choice1 = 0;
	room4_choice2 = 0;
	room4_action_loop = 0;
	room4_action_loop_fail = 0;
	room4_action_loop_win = 0;
	room4_exit = 0;
	intro_room1 = 0;
	room5_loop1 = 0;
	room5_choice1 = 0;
	room5_choice2 = 0;
	room5_choice3 = 0;
	room5_choice4 = 0;
	room5_choice5 = 0;
	room5_action_loop1 = 0;
	room5_action_loop1_fail = 0;
	room5_action_loop2 = 0;
	room5_action_loop2_fail = 0;
	room5_action_loop3 = 0;
	room5_action_loop3_fail = 0;
	room5_action_loop4 = 0;
	room5_action_loop4_fail = 0;
	room5_exit = 0;
	wait(1);
	handle_videos();
}



"MAIN" starts the function "start_into()" and the into video plays once just fine, however, I couldn't manage to let another Video (in this case the loop) play afterwards.

If "start_loop1" is 1, then that loop is suppose to play etc.
I attempted to do this in "handle_videos()".

What did I do wrong?
Posted By: Turrican

Re: Video control - 10/18/17 07:34

Have you tried media_playing(var handle) instead of your while(handle_intro_played) loop?
Posted By: DriftWood

Re: Video control - 10/18/17 17:25

As is pointed out by @Turrican the video handle will continue to have a value. So this...
Code:
while(handle_intro_played){wait(1);}


...will continue forever.
Code:
while(media_playing(handle_intro_played)) {wait(1);}


This is pointless...
Code:
media_stop(handle_intro_played);


...as the media_play function is self terminating at end of file.

Try this..
Code:
while(1)
	{
		if(intro_played == 1)
		{
			intro_played = 0;
			var handle_intro_played = media_play("demo.ogg",NULL,100); 
			while(media_playing(handle_intro_played)) {wait(1);}
			start_loop1 = 1;
		}
		if(start_loop1 == 1)
		{
			start_loop1 = 0;
			var handle_start_loop1 = media_loop("demo.ogg",NULL,100); 
		}
		wait(1);
	}



A handle is a reference to an engine object. Not the same but similar to a Pointer. A var set to a handle holds the same handle forever unless explicitly reset to some other value. i.e. var x= handle; x=NULL; --- Using a handler as a boolean value in a clause like WHILE or IF will always equal out to 1 unless the var holding has been reset.

Edit- One last point, you made the loop WHILE(1) ---> Does this loop really need to run forever? Isn't it better to terminate it at some point and save resources.
Posted By: middleagechinese

Re: Video control - 10/19/17 08:49

Works perfect, and thank you for the elaborate explanation.

It was suppose to be an infinity loop until input (dialog choice), however an time limit as an penalty and means to save resources is an good idea.
Thank you for the suggestion!
Posted By: middleagechinese

Re: Video control - 10/20/17 13:10

Say, is there a way to pause an video at an specific frame and then start an new video?
Posted By: Turrican

Re: Video control - 10/22/17 10:43

You can use media_playing(handle) to return the current frame of your stream, then pause it once it reached its target frame and then start the next one. Something like this should work:

Code:
...
var handle_intro_played = media_play("demo.ogg",NULL,100);			// play your stream
while(media_playing(handle_intro_played) < target_frame_number) { wait(1); }	// keep playing until target_frame_number has been reached
media_pause(handle_intro_played);						// pause the first stream
var handle_next_mediastream = media_play("demo2.ogg",NULL,100);			// start next one
...

© 2024 lite-C Forums