• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

LoneWolff's video player

chamaeleon

Member
Yeah its in a step, w hy?
Oops, my mistake this time, I assume it goes to the room because the comparison is true so only one output. So.. Your assignment, should you choose to accept it, is to determine why video_get_duration() returns 0 instead of the length of the video (unless it's a trivial case of calling it before you have loaded a video..)
 
L

Lonewolff

Guest
I tried clicking the support link and it gave me an option to email him through the site. I have done so, several times, and he hasn't gotten back to me.
I have in fact sent two emails to you so far, responding to your questions. You might want to check your inbox and possibly spam folder for the 18th of this month.

The first email was relating to your project not working, which was due to a non existent variable that you were trying to reference, which was unrelated to the extension.

Variable GrtassObject.game(100848, -2147483648) not set before reading it.
And the second email was with regards to the functions, with which @rIKmAN pointed out, are described in full in the example object (obj_video).


Because video_get_duration() returns the amount of video played so far.
video_get_duration() returns the length of the video. It will return 0 if the file could not be found though. If it is returning 0, I'd make sure that that path and filenames are correct. (Note: it may take two or three step events for this to become non-zero as this is dependent on the initial retrieval from your HDD).
video_get_current_time() will return the current playback time.
 
If I do this:

Code:
if (time_diff > video_get_duration())
{
    room_goto(FirstLevel);
}
IT loads the first level, skipping the video, and plays the animations back super fast

IF I DO THIS:

Code:
if (time_diff > video_get_duration())
{
    room_goto(FirstLevel);
}
it plays but ultimately stops without going to the first level.
 

chamaeleon

Member
If I do this:

Code:
if (time_diff > video_get_duration())
{
    room_goto(FirstLevel);
}
IT loads the first level, skipping the video, and plays the animations back super fast

IF I DO THIS:

Code:
if (time_diff > video_get_duration())
{
    room_goto(FirstLevel);
}
it plays but ultimately stops without going to the first level.
1. You don't show how you calculate time_diff
2. You should only need to compare the total duration and the current time for the video (and given @Lonewolff's comment, don't jump to the next room while the duration call returns 0)
3. You posted the same code snippet twice
 
L

Lonewolff

Guest
Hi Ted.

Because the video initially gets loaded during the step event, the video may not have loaded yet when you are doing the comparison. It may take two or three steps before you get a correct duration value.

Code:
// Progress to first level after video has finished playing

if(video_get_current_time() > video_get_duration())
{
     room_goto(FirstLevel)
}

BTW - I just uploaded a new version to the marketplace that has a PDF manual included. Hopefully this will help.
 
Ok. When it goes to the first level everything is sped up a lot. The clouds and characters move really fast.

This is the condition test I did:
Code:
//if (time_diff > video_get_duration())
if(video_get_current_time() > video_get_duration() && video_get_duration >= 0)
{
     room_goto(FirstLevel)

}
 
L

Lonewolff

Guest
And you don't need this

Code:
 && video_get_duration >= 0
as video_get_current_time() has to be greater than zero anyway if the video is playing in the first place.

If the video hasn't loaded yet you are effectively doing this with your code

Code:
if(0 > 0 && 0 >= 0)
Which will make your code do exactly what you don't want it to do.

The code snippet I provided should suffice. I tested it before posting it to make sure it works.
 
Last edited:
L

Lonewolff

Guest
@Lonewolff It says 30 like it should be, right? Afterwards its 9999.Its from setting the room_speed in the create event. If I comment that out though it doesn't load the first level.
The demo runs at 9999 just to show off the performance and even says that in the code.

Code:
// Unlock room speed and disable application surface. 
// This is optional and purely for optimisation/benchmark purposes.
room_speed = 9999;
application_surface_enable(false);
These lines are not a requirement and the extension will run fine if you comment these out. Once again, I have just tested this and all is well.

I'd suggest the root cause is probably to do with your 'time_diff' variable you are using.

Can you post more code?

At bare minimum, this is what you need to do.

Code:
/// Create Event

video_init(window_device());
video_load("your_video_filename.xxx");
Code:
/// Draw Event

if(video_get_current_time() > video_get_duration())
    room_goto(FirstLevel);

video_draw();
As I said, that's the absolute minimum you need. But, I'd add the surface portion from the demo code so you can handle scaling, positioning, and so on.
 
The demo runs at 9999 just to show off the performance and even says that in the code.

Code:
// Unlock room speed and disable application surface.
// This is optional and purely for optimisation/benchmark purposes.
room_speed = 9999;
application_surface_enable(false);
These lines are not a requirement and the extension will run fine if you comment these out. Once again, I have just tested this and all is well.

I'd suggest the root cause is probably to do with your 'time_diff' variable you are using.

Can you post more code?

At bare minimum, this is what you need to do.

Code:
/// Create Event

video_init(window_device());
video_load("your_video_filename.xxx");
Code:
/// Draw Event

if(video_get_current_time() > video_get_duration())
    room_goto(FirstLevel);

video_draw();
As I said, that's the absolute minimum you need. But, I'd add the surface portion from the demo code so you can handle scaling, positioning, and so on.

No it has nothing to do with that time_diff variable. It isn't even being used now, it was when I was trying to get the video to stop. ITs not used anymore.

Here is some more code:

Create:'

Code:
/// @description Initialisation


// Unlock room speed and disable application surface.
// This is optional and purely for optimisation/benchmark purposes.
room_speed = 9999;
application_surface_enable(false);


// Initialise the video system. Only required to ever call this only once in the application.
result_init = video_init(window_device());


// Load a video from 'Included files'.
result_load = video_load("game.mp4");

// Example of how to load video using anywhere in the windows file system.
// video_load("c:\\b.mp4");


// Create placeholder for the video surface and draw result variable.
video_surface = 0;
result_draw = 0;


start_time = video_get_current_time;
Step:

Code:
/// @description Example functionality

///video get duration is 41.43
///rhs eventually g4ets to duration

show_debug_message("Duration = " + string(video_get_duration()) + ", Current = " + string(video_get_current_time()));

curr_time = video_get_current_time();

time_diff = curr_time - start_time;


//if (time_diff > video_get_duration())
if(video_get_current_time() > video_get_duration())
{
     room_goto(FirstLevel)
}
Draw:

Code:
/// @description Example draw usage


// Only create the surface once the video has loaded.
// As we wont nessesarily know its dimensions before this time.
if(!surface_exists(video_surface) && video_get_duration() > 0)
{
    //video_surface = surface_create(video_get_width(), video_get_height());
    video_surface = surface_create(1024, 768);
    video_draw();    // Pre-draw sets up internal texture mapping after video has confirmed to have started.
}


// Once the surface exists and video is playing, set the surface as the render
// target and draw the video to it. Then we can draw back to the screen.
if(surface_exists(video_surface))
{
    surface_set_target(video_surface)
    result_draw = video_draw();
    surface_reset_target();
    draw_surface_ext(video_surface, 0, 0, 1.0, 1.0, 0, c_white, 1);
}
That's about all there is to it. It just seems strange that the performance 9999s room speed is the same as the room_speed I got from
the fast room.
 
L

Lonewolff

Guest
At first glance, this won't help
Code:
start_time = video_get_current_time;
You have made the same mistake that @FrostyCat already pointed out. By rights though, GMS shouldn't allow this anyway (but that is something I don't have control over). Internally it is probably giving a reference to a pointer.

Other than that, I see no reason why you cant comment out the room_speed line and even the application_surface line for that matter. They are not required.
 
When I comment out the 9999 the firstlevel goto doesn't work, it just freezes at the last frame. I also noticed if I left the 9999 (however 9s it is) and put a room=30 before the room goto it freezes at the last frame.Ot herwise it loads the super fast first level.
 
L

Lonewolff

Guest
When I comment out the 9999 the firstlevel goto doesn't work, it just freezes at the last frame. I also noticed if I left the 9999 (however 9s it is) and put a room=30 before the room goto it freezes at the last frame.Ot herwise it loads the super fast first level.
Ok, thanks for the additional info there. I can in-fact replicate that behaviour now. It's due to the low 30 FPS room speed. The difference between video_get_current_time() and video_get_duration() is indistinguishable at that speed so it seems.

I'll add a new function to detect when the video has ended and release an update on the Marketplace. Give us an hour or so. :)


[edit]
Done! :cool:

You can now do this.

Code:
if(video_get_playback_ended())
     room_goto_next();
 
Last edited:
I tried to update my library and this is what it got me

Resource 'video_player_pro' failed to import
Saving project to: C:\Users\ted_g\Documents\GameMakerStudio2\BatsVSBrainsPhantom33.7\BatsVSBrainsPhantom33.7.yyp
"cmd" /c subst W: /d
 
L

Lonewolff

Guest
It probably is incomplete, LoneWolff was generally selfish, egotistic and mildly skilled with things that seem advanced
Nope, it's quite complete. Probably the most ambitious project I have ever worked on. I am quite proud of it.
 
L

Lvb440

Guest
Hi

I began to use Lonewolff's video player a few weeks ago, and it does exactly what I needed so far.

I still have questions, I hope I'm not hijacking this topic if I ask them here? According to the topic name, it seems appropriate.

First, I'd like to know if there are plans to release it for other platforms (mac and mobiles especially). I didn't find another player able to load so many formats, without importing codecs or converting the videos, and that works on surfaces, letting me add other surfaces where I can draw, and gui.
But my game would be really better on mobiles, and playing a video is at the heart of it (videos the user recorded on camera, like goPro or sony handycam, not videos I prepared and packaged in the game).

Question #2 : I added a «load video file from hard disk» option. The video is loaded and played well.
The window size isn't modified and shouldn't be, according to my design.
But if the new video size is bigger than the last, everything looks fine, while if the video size is smaller (as instance, I was playing a 800*600 video, then loaded a 640*480 video), the surface still displays the last frame of the old video in the remaining area. I can't find a way to set the whole surface to black, or erase it totally, then start playing the new video.
if I destroy the surface to recreate it, some steps fail because the video surface is needed in the draw.
Any idea how to simply reset the video surface when a new video is loaded?
Should I recreate the room from scratch with the new video path as input?
 
L

Lonewolff

Guest
Hi there!

Hi

I began to use Lonewolff's video player a few weeks ago, and it does exactly what I needed so far.

I still have questions, I hope I'm not hijacking this topic if I ask them here? According to the topic name, it seems appropriate.

First, I'd like to know if there are plans to release it for other platforms (mac and mobiles especially). I didn't find another player able to load so many formats, without importing codecs or converting the videos, and that works on surfaces, letting me add other surfaces where I can draw, and gui.
But my game would be really better on mobiles, and playing a video is at the heart of it (videos the user recorded on camera, like goPro or sony handycam, not videos I prepared and packaged in the game).
Not at this stage unfortunately.


Question #2 : I added a «load video file from hard disk» option. The video is loaded and played well.
The window size isn't modified and shouldn't be, according to my design.
But if the new video size is bigger than the last, everything looks fine, while if the video size is smaller (as instance, I was playing a 800*600 video, then loaded a 640*480 video), the surface still displays the last frame of the old video in the remaining area. I can't find a way to set the whole surface to black, or erase it totally, then start playing the new video.
if I destroy the surface to recreate it, some steps fail because the video surface is needed in the draw.
Any idea how to simply reset the video surface when a new video is loaded?
Should I recreate the room from scratch with the new video path as input?
Destroying and re-creating the surface is what you want to do.

You should be able to copy the surface creation section straight from the demo project. It does a test to ensure the video is loaded and returns the correct dimensions.
 
Top