Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » APEG issues

This thread is locked; no one can reply to it. rss feed Print
APEG issues
Matt Kindy
Member #7,331
June 2006
avatar

I am having a problem with APEG, I'm wondering if anyone can help me out. I made a function that uses apeg_play_mpg, but it won't move on to the next thing until I hit a button. Does anybody know what could be happening?

EDIT: There is no readkey() or ureadkey() or anything of the sort in it

Zaphos
Member #1,468
August 2001

It might help us help you if you could post the function. I'm not deeply familiar with apeg, but it's probably going to be hard to figure out your problem without seeing the relevant code.

Matt Kindy
Member #7,331
June 2006
avatar

1int mpeg2screen(char *filename, int screen_x_offset, int screen_y_offset){
2
3 int ret=0;
4 int width=0, height=0;
5
6 APEG_STREAM *movie; // For getting info about the movie
7 BITMAP *box; // the sandbox for the movie
8
9 // Find out the screen size of the movie
10 movie = apeg_open_stream(filename);
11 width = movie->w;
12 height = movie->h;
13 apeg_close_stream(movie);
14 free(movie);
15
16 // SCREEN_W and SCREEN_H are globals set-up by Allegro
17 if (width<=SCREEN_W && height<=SCREEN_H) {
18
19 // Make a nice sandbox for the movie
20 box = create_sub_bitmap(screen, screen_x_offset, screen_y_offset, width, height);
21
22
23
24 // Play the movie in the sandbox
25 ret = apeg_play_mpg(filename, box,0, NULL);
26
27
28 // Note that you don't have to show the video
29 //ret = apeg_play_mpg(filename, NULL, 0, NULL);
30 
31
32
33 //free up the movie
34 apeg_close_stream(apeg_stream);
35 free(apeg_stream);
36
37 clear_bitmap(box);
38 free(box);
39 clear_bitmap(screen);
40 
41 destroy_bitmap(box);
42 clear_to_color(screen, makecol(0, 0, 0));
43 
44 // Error handling
45 if(ret == APEG_ERROR)
46 {
47 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
48 allegro_message("APEG Error: %s\n", apeg_error);
49 }
50
51}
52
53 else {
54
55 //Movie too big for screen
56 ret = -999;
57
58 }
59
60 return ret;
61
62} // end of mpeg2screen()

EDIT: Everything after the apeg_play_mpg is ignored, at least until a key is pressed, then it will display, but you still have to press a key... it basically is doing the effects of a readkey(), without the readkey()???!

Kitty Cat
Member #2,815
October 2002
avatar

That function looks a bit convoluted, and you're free'ing streams after they're already closed, and closing the internal stream handle. apeg_close_stream invalidates the pointer (meaning it frees it for you, just like apeg_open_stream creates it for you. And you should never do anything to apeg_stream except use it for reference it in the callback to apeg_play_mpg.

That said, there does seem to be a bug in the apeg_play_mpg function that causes it to not quit when it hits the end of the stream (though it'll still run the callback, which if none is specified, causes it to quit when a key is pressed). Since you're Already using the stream functions, why bother with the blocking play function? Something like this would work:

1int mpeg2screen(char *filename, int screen_x_offset, int screen_y_offset){
2
3 int ret;
4 int width, height;
5
6 APEG_STREAM *movie; // For getting info about the movie
7
8 // Find out the screen size of the movie
9 movie = apeg_open_stream(filename);
10 // Video may need to be stretched to the proper aspect ratio
11 // This gives the full size to stretch to
12 apeg_get_video_area(&width, &height);
13 
14 while((ret=apeg_advance_stream(movie, FALSE)) == APEG_OK && !keypressed())
15 {
16 if(movie->frame_updated > 0)
17 stretch_blit(movie->bitmap, screen, 0, 0, movie->w, movie->h, screen_x_offset, screen_y_offset, width, height);
18 else if(movie->frame_updated < 0 && !movie->audio.flushed)
19 rest(1);
20 }
21 
22 apeg_close_stream(movie);
23 
24 if(ret != APEG_OK)
25 alert("Video Error", "", apeg_error, "Ok", NULL, 0, 0);
26 
27 return ret!=APEG_OK; /* return 0 = ok, non-0 = bad */
28}

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Marco Radaelli
Member #3,028
December 2002
avatar

simulate_keypress() perhaps?

Matt Kindy
Member #7,331
June 2006
avatar

I get a linker error to apeg_get_video_area...

simulate_keypress() would probably work, except for the fact that it would not execute until a key is pressed(paradox)...the movie isn't closing, so no code is executed, and I wouldn't want the closing code to execute while this was running...the blocking way would work, but only if the movie closed(like it's supposed to).

Kitty Cat
Member #2,815
October 2002
avatar

It's apeg_get_video_size, sorry.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Go to: