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