Fixed tests. Now installable
[sdlgit/SDL_perl.git] / lib / SDL / Video.pm
CommitLineData
8fde61e3 1#
2# Video.pm
3#
4# A package for manipulating MPEG video
5#
6# Copyright (C) 2004 David J. Goehrig
7
8package SDL::Video;
9
10use strict;
11use SDL;
12use SDL::Surface;
13use SDL::MPEG;
14
15sub new {
16 my $proto = shift;
17 my $class = ref($proto) || $proto;
18 my %options = @_;
19
20 verify (%options, qw/ -name -audio / ) if $SDL::DEBUG;
21
22 my $n = $options{-name} || die "SDL::Video must supply a filename to SDL::Video::new\n";
23 my $a = $options{'-audio'} ? 1 : 0;
24 my $info = new SDL::MPEG();
25
26 my $self = \SDL::NewSMPEG($n,$$info,$a);
27 bless $self,$class;
28 $self->audio(1);
29 $self->video(1);
30 return $self, $info;
31}
32
33sub DESTROY {
34 SDL::FreeSMPEG(${$_[0]});
35}
36
37sub error {
38 SDL::SMPEGError(${$_[0]});
39}
40
41sub audio {
42 SDL::SMPEGEnableAudio( ${$_[0]}, $_[1]);
43}
44
45sub video {
46 SDL::SMPEGEnableVideo( ${$_[0]}, $_[1]);
47}
48
49sub volume {
50 SDL::SMPEGSetVolume( ${$_[0]}, $_[1] );
51}
52
53sub display {
54 die "SDL::Video::Display requires a SDL::Surface\n" unless $_[1]->isa('SDL::Surface');
55 SDL::SMPEGSetDisplay( ${$_[0]}, ${$_[1]}, 0);
56}
57
58sub scale {
59 return SDL::SMPEGScaleXY(${$_[0]},$_[1],$_[2]) if (@_ == 3 );
60 return SDL::SMPEGScaleXY(${$_[0]},$_[1]->width(),$_[1]->height()) if $_[1]->isa('SDL::Surface');
61 SDL::SMPEGScale(${$_[0]},$_[1]);
62}
63
64sub play {
65 SDL::SMPEGPlay(${$_[0]});
66}
67
68sub pause {
69 SDL::SMPEGPause(${$_[0]});
70}
71
72sub stop {
73 SDL::SMPEGStop(${$_[0]});
74}
75
76sub rewind {
77 SDL::SMPEGRewind(${$_[0]});
78}
79
80sub seek {
81 SDL::SMPEGSeek(${$_[0]},$_[1]);
82}
83
84sub skip {
85 SDL::SMPEGSkip(${$_[0]},$_[1]);
86}
87
88sub loop {
89 SDL::SMPEGLoop(${$_[0]},$_[1]);
90}
91
92sub region {
93 die "SDL::Video::region requires a SDL::Rect\n" unless $_[1]->isa('SDL::Rect');
94 SDL::SMPEGDisplayRegion(${$_[0]},${$_[1]});
95}
96
97sub frame {
98 SDL::SMPEGRenderFrame(${$_[0]},$_[1]);
99}
100
101sub info {
102 new SDL::MPEG -from => $_[0];
103}
104
105sub status {
106 SDL::SMPEGStatus(${$_[0]});
107}
108
1091;
110
111__END__;
112
113=pod
114
115
116=head1 NAME
117
118SDL::Video - a SDL perl extension
119
120=head1 SYNOPSIS
121
122 $video = new SDL::Video ( -name => 'pr0n.mpg' );
123
124=head1 DESCRIPTION
125
126C<SDL::Video> adds support for MPEG video to your
127SDL Perl application. Videos are objects bound to
128surfaces, whose playback is controled through the
129object's interface.
130
131=head2 METHODS
132
133
134=over 4
135
136=item *
137
138C<SDL::Video::error()> returns any error messages associated with playback
139
140=item *
141
142C<SDL::Video::audio(bool)> enables or disables audio playback, (on by default)
143
144=item *
145
146C<SDL::Video::video(bool)> enables or disable video playback, (on by default)
147
148=item *
149
150C<SDL::Video::loop(bool)> enables or disable playback looping (off by default)
151
152=item *
153
154C<SDL::Video::volume(int)> set the volume as per the mixer volume
155
156=item *
157
158C<SDL::Video:display(surface)> binds the clip to a display surface
159
160=item *
161
162C<SDL::Video::scale([x,y]|[surface]|int)> scales the clip by either x,y
163factors, scales to the image dimensions, or a single scalar.
164
165=item *
166
167C<SDL::Video::play()> plays the video clip, call C<SDL::Video::display()> before playing
168
169=item *
170
171C<SDL::Video::pause()> pauses video playback
172
173=item *
174
175C<SDL::Video::stop()> stops video playback
176
177=item *
178
179C<SDL::Video::rewind()> resets the clip to the beginning
180
181=item *
182
183C<SDL::Video::seek(offset)> seeks to a particular byte offset
184
185=item *
186
187C<SDL::Video::skip(time)> skips to a particular time
188
189=item *
190
191C<SDL::Video::region(rect)> takes a SDL::Rect and defines the display area
192
193=item *
194
195C<SDL::Video::frame(int)> renders a specific frame to the screen
196
197=item *
198
199C<SDL::Video::info()> returns a new C<SDL::MPEG> object reflecting the current status
200
201=item *
202
203C<SDL::Video::status()> returns either SMPEG_PLAYING or SMPEG_STOPPED or SMPEG_ERROR
204
205=back
206
207=head1 AUTHOR
208
209David J. Goehrig
210
211=head1 SEE ALSO
212
213perl(1) SDL::Surface(3) SDL::MPEG(3)
214
215=cut
216