Commit | Line | Data |
bfd90409 |
1 | #!/usr/bin/env perl |
2 | # |
3 | # Video.pm |
4 | # |
5 | # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org> |
6 | # |
7 | # ------------------------------------------------------------------------------ |
8 | # |
9 | # This library is free software; you can redistribute it and/or |
10 | # modify it under the terms of the GNU Lesser General Public |
11 | # License as published by the Free Software Foundation; either |
12 | # version 2.1 of the License, or (at your option) any later version. |
13 | # |
14 | # This library is distributed in the hope that it will be useful, |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | # Lesser General Public License for more details. |
18 | # |
19 | # You should have received a copy of the GNU Lesser General Public |
20 | # License along with this library; if not, write to the Free Software |
21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | # |
23 | # ------------------------------------------------------------------------------ |
24 | # |
25 | # Please feel free to send questions, suggestions or improvements to: |
26 | # |
27 | # David J. Goehrig |
28 | # dgoehrig@cpan.org |
29 | # |
30 | |
31 | package SDL::Video; |
32 | |
33 | use strict; |
084b921f |
34 | use warnings; |
35 | use Carp; |
bfd90409 |
36 | use SDL; |
37 | use SDL::Surface; |
38 | use SDL::MPEG; |
39 | |
40 | sub new { |
41 | my $proto = shift; |
42 | my $class = ref($proto) || $proto; |
43 | my %options = @_; |
44 | |
45 | verify (%options, qw/ -name -audio / ) if $SDL::DEBUG; |
46 | |
47 | my $n = $options{-name} || die "SDL::Video must supply a filename to SDL::Video::new\n"; |
48 | my $a = $options{'-audio'} ? 1 : 0; |
49 | my $info = new SDL::MPEG(); |
50 | |
51 | my $self = \SDL::NewSMPEG($n,$$info,$a); |
cc6d0c7c |
52 | croak SDL::GetError() unless $$self; |
bfd90409 |
53 | bless $self,$class; |
54 | $self->audio(1); |
55 | $self->video(1); |
56 | return $self, $info; |
57 | } |
58 | |
59 | sub DESTROY { |
60 | SDL::FreeSMPEG(${$_[0]}); |
61 | } |
62 | |
63 | sub error { |
64 | SDL::SMPEGError(${$_[0]}); |
65 | } |
66 | |
67 | sub audio { |
68 | SDL::SMPEGEnableAudio( ${$_[0]}, $_[1]); |
69 | } |
70 | |
71 | sub video { |
72 | SDL::SMPEGEnableVideo( ${$_[0]}, $_[1]); |
73 | } |
74 | |
75 | sub volume { |
76 | SDL::SMPEGSetVolume( ${$_[0]}, $_[1] ); |
77 | } |
78 | |
79 | sub display { |
084b921f |
80 | croak "SDL::Video::Display requires a SDL::Surface\n" unless $_[1]->isa('SDL::Surface'); |
bfd90409 |
81 | SDL::SMPEGSetDisplay( ${$_[0]}, ${$_[1]}, 0); |
82 | } |
83 | |
84 | sub scale { |
85 | return SDL::SMPEGScaleXY(${$_[0]},$_[1],$_[2]) if (@_ == 3 ); |
86 | return SDL::SMPEGScaleXY(${$_[0]},$_[1]->width(),$_[1]->height()) if $_[1]->isa('SDL::Surface'); |
87 | SDL::SMPEGScale(${$_[0]},$_[1]); |
88 | } |
89 | |
90 | sub play { |
91 | SDL::SMPEGPlay(${$_[0]}); |
92 | } |
93 | |
94 | sub pause { |
95 | SDL::SMPEGPause(${$_[0]}); |
96 | } |
97 | |
98 | sub stop { |
99 | SDL::SMPEGStop(${$_[0]}); |
100 | } |
101 | |
102 | sub rewind { |
103 | SDL::SMPEGRewind(${$_[0]}); |
104 | } |
105 | |
106 | sub seek { |
107 | SDL::SMPEGSeek(${$_[0]},$_[1]); |
108 | } |
109 | |
110 | sub skip { |
111 | SDL::SMPEGSkip(${$_[0]},$_[1]); |
112 | } |
113 | |
114 | sub loop { |
115 | SDL::SMPEGLoop(${$_[0]},$_[1]); |
116 | } |
117 | |
118 | sub region { |
084b921f |
119 | croak "SDL::Video::region requires a SDL::Rect\n" unless $_[1]->isa('SDL::Rect'); |
bfd90409 |
120 | SDL::SMPEGDisplayRegion(${$_[0]},${$_[1]}); |
121 | } |
122 | |
123 | sub frame { |
124 | SDL::SMPEGRenderFrame(${$_[0]},$_[1]); |
125 | } |
126 | |
127 | sub info { |
128 | new SDL::MPEG -from => $_[0]; |
129 | } |
130 | |
131 | sub status { |
132 | SDL::SMPEGStatus(${$_[0]}); |
133 | } |
134 | |
135 | 1; |
136 | |
137 | __END__; |
138 | |
139 | =pod |
140 | |
141 | |
142 | =head1 NAME |
143 | |
144 | SDL::Video - a SDL perl extension |
145 | |
146 | =head1 SYNOPSIS |
147 | |
148 | $video = new SDL::Video ( -name => 'pr0n.mpg' ); |
149 | |
150 | =head1 DESCRIPTION |
151 | |
152 | C<SDL::Video> adds support for MPEG video to your |
153 | SDL Perl application. Videos are objects bound to |
154 | surfaces, whose playback is controled through the |
155 | object's interface. |
156 | |
157 | =head2 METHODS |
158 | |
159 | |
160 | =over 4 |
161 | |
162 | =item * |
163 | |
164 | C<SDL::Video::error()> returns any error messages associated with playback |
165 | |
166 | =item * |
167 | |
168 | C<SDL::Video::audio(bool)> enables or disables audio playback, (on by default) |
169 | |
170 | =item * |
171 | |
172 | C<SDL::Video::video(bool)> enables or disable video playback, (on by default) |
173 | |
174 | =item * |
175 | |
176 | C<SDL::Video::loop(bool)> enables or disable playback looping (off by default) |
177 | |
178 | =item * |
179 | |
180 | C<SDL::Video::volume(int)> set the volume as per the mixer volume |
181 | |
182 | =item * |
183 | |
184 | C<SDL::Video:display(surface)> binds the clip to a display surface |
185 | |
186 | =item * |
187 | |
188 | C<SDL::Video::scale([x,y]|[surface]|int)> scales the clip by either x,y |
189 | factors, scales to the image dimensions, or a single scalar. |
190 | |
191 | =item * |
192 | |
193 | C<SDL::Video::play()> plays the video clip, call C<SDL::Video::display()> before playing |
194 | |
195 | =item * |
196 | |
197 | C<SDL::Video::pause()> pauses video playback |
198 | |
199 | =item * |
200 | |
201 | C<SDL::Video::stop()> stops video playback |
202 | |
203 | =item * |
204 | |
205 | C<SDL::Video::rewind()> resets the clip to the beginning |
206 | |
207 | =item * |
208 | |
209 | C<SDL::Video::seek(offset)> seeks to a particular byte offset |
210 | |
211 | =item * |
212 | |
213 | C<SDL::Video::skip(time)> skips to a particular time |
214 | |
215 | =item * |
216 | |
217 | C<SDL::Video::region(rect)> takes a SDL::Rect and defines the display area |
218 | |
219 | =item * |
220 | |
221 | C<SDL::Video::frame(int)> renders a specific frame to the screen |
222 | |
223 | =item * |
224 | |
225 | C<SDL::Video::info()> returns a new C<SDL::MPEG> object reflecting the current status |
226 | |
227 | =item * |
228 | |
229 | C<SDL::Video::status()> returns either SMPEG_PLAYING or SMPEG_STOPPED or SMPEG_ERROR |
230 | |
231 | =back |
232 | |
233 | =head1 AUTHOR |
234 | |
235 | David J. Goehrig |
236 | |
237 | =head1 SEE ALSO |
238 | |
239 | perl(1) SDL::Surface(3) SDL::MPEG(3) |
240 | |
241 | =cut |
242 | |