|
Video control
#468771
10/18/17 07:14
10/18/17 07:14
|
Joined: Nov 2016
Posts: 31
middleagechinese
OP
Newbie
|
OP
Newbie
Joined: Nov 2016
Posts: 31
|
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?
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?
Last edited by middleagechinese; 10/18/17 07:17.
Hello, it is me,
Middleagedchineseman!
Note: Not actually Chinese, nor middle age
|
|
|
Re: Video control
[Re: Turrican]
#468778
10/18/17 17:25
10/18/17 17:25
|
Joined: Jul 2014
Posts: 72
DriftWood
Junior Member
|
Junior Member
Joined: Jul 2014
Posts: 72
|
As is pointed out by @Turrican the video handle will continue to have a value. So this...
while(handle_intro_played){wait(1);}
...will continue forever.
while(media_playing(handle_intro_played)) {wait(1);}
This is pointless...
media_stop(handle_intro_played);
...as the media_play function is self terminating at end of file. Try this..
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.
Last edited by DriftWood; 10/18/17 17:38.
|
|
|
Re: Video control
[Re: DriftWood]
#468782
10/19/17 08:49
10/19/17 08:49
|
Joined: Nov 2016
Posts: 31
middleagechinese
OP
Newbie
|
OP
Newbie
Joined: Nov 2016
Posts: 31
|
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!
Hello, it is me,
Middleagedchineseman!
Note: Not actually Chinese, nor middle age
|
|
|
Re: Video control
[Re: middleagechinese]
#468801
10/20/17 13:10
10/20/17 13:10
|
Joined: Nov 2016
Posts: 31
middleagechinese
OP
Newbie
|
OP
Newbie
Joined: Nov 2016
Posts: 31
|
Say, is there a way to pause an video at an specific frame and then start an new video?
Hello, it is me,
Middleagedchineseman!
Note: Not actually Chinese, nor middle age
|
|
|
Re: Video control
[Re: middleagechinese]
#468824
10/22/17 10:43
10/22/17 10:43
|
Joined: Apr 2002
Posts: 680 Germany
Turrican
User
|
User
Joined: Apr 2002
Posts: 680
Germany
|
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:
...
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
...
|
|
|
|