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