lib/HTML/Object/DOM/Element/Media.pm

filter: Statementstmt 22.0% 32 / 145 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 12.3% 10 / 81 Podpod 66.1% 43 / 65 totaltotal 27.1% 85 / 313 CC 11 SCAR 12.2
CC
11
Cov
19%
init
12.0
addTextTrack
12.0
controlsList
12.0
CRAP 3.4
« blib/lib/HTML/Object/XPath/Boolean.pm ↑ Summary lib/HTML/Object/DOM/Element/IFrame.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Media.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/23
7 ## Modified 2022/09/18
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::DOM::Element::Media;
15 BEGIN
16 {
17 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use parent qw( HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use vars qw( @EXPORT_OK %EXPORT_TAGS $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ use HTML::Object::DOM::Element::Shared qw( :media );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶ use HTML::Object::DOM::TrackEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 use constant {
25 # For HTML::Object::DOM::Element::Media
26 # There is no data yet. Also, readyState is HAVE_NOTHING.
27 1 NETWORK_EMPTY => 0,
28 # HTMLMediaElement is active and has selected a resource, but is not using the network.
29 NETWORK_IDLE => 1,
30 # The browser is downloading HTMLMediaElement data.
31 NETWORK_LOADING => 2,
32 # No HTMLMediaElement src found.
33 NETWORK_NO_SOURCE => 3,
34 1 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 our @EXPORT_OK = qw( NETWORK_EMPTY NETWORK_IDLE NETWORK_LOADING NETWORK_NO_SOURCE );
36 1 our %EXPORT_TAGS = (
37 all => [qw( NETWORK_EMPTY NETWORK_IDLE NETWORK_LOADING NETWORK_NO_SOURCE )],
38 );
39 1 our $VERSION = 'v0.2.0';
40 };
41  
42 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 sub init
46 {
47 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
48 0 $self->{ended} = 0;
49 0 $self->{paused} = 1;
50 0 $self->{sinkid} = undef;
51 0 $self->{_init_strict_use_sub} = 1;
52 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
53 0 $self->{_callback_off} = 0;
54 0 $self->{_exception_class} = 'HTML::Object::MediaError';
55 0 ▶ $self->{tag} = 'media' if( !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length qq[$self->{"tag"}] 0 0 0
56 $self->_set_get_internal_attribute_callback( controlslist => sub
57 {
58 0 ▶ my( $this, $val ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
59 0 my $list;
60 0 ▶ return if( !( $list = $this->{_controlslist_list} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $list = $this->{"_controlslist_list"} 0 0 0
61 # $list->debug( $self->debug );
62 0 $list->update( $val );
63 0 });
64 0 return( $self );
65 }
66  
67 sub addTextTrack
68 {
69 0 ▶ my $self = shift( @_ );
Subroutine addTextTrack: not called CC=3 SCAR=24.8
Pod documented
70 0 my $list = $self->textTracks;
71 0 ▶ $self->_load_class( 'HTML::Object::DOM::TextTrack' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::TextTrack") or return $self->pass_error 0 0 0
72 0 ▶ my $new = HTML::Object::DOM::TextTrack->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::TextTrack'->new(@_) || (return $self->pass_error('HTML::Object::DOM::TextTrack'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::TextTrack'->new(@_) || (return $self->pass_error('HTML::Object::DOM::TextTrack'->error))
'HTML::Object::DOM::TextTrack'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::TextTrack'->new(@_)
Aresult
11
00
73 return( $self->pass_error( HTML::Object::DOM::TextTrack->error ) );
74 0 $list->push( $new );
75 # There is no parent, because a TextTrack parent is actually a HTML::Object::DOM::Element::Track object
76 # and here we only add a TextTrack object directly.
77 # $new->parent( $self );
78 0 return( $self );
79 }
80  
81 # Note: property
82 0 ▶sub audioTracks : lvalue { return( shift->_set_get_property( 'audiotracks', @_ ) ); }
Subroutine audioTracks: not called CC=1 SCAR=6.9
Pod documented
83  
84 # Note: property
85 0 ▶sub autoplay : lvalue { return( shift->_set_get_property( { attribute => 'autoplay', is_boolean => 1 }, @_ ) ); }
Subroutine autoplay: not called CC=1 SCAR=6.9
Pod documented
86  
87 # Note: property read-only
88 0 ▶sub buffered { return; }
Subroutine buffered: not called CC=1 SCAR=6.9
Pod documented
89  
90 0 ▶sub canPlayType { return; }
Subroutine canPlayType: not called CC=1 SCAR=6.9
Pod documented
91  
92 0 ▶sub captureStream { return; }
Subroutine captureStream: not called CC=1 SCAR=6.9
Pod documented
93  
94 # Note: property
95 0 ▶sub controller { return; }
Subroutine controller: not called CC=1 SCAR=6.9
Pod documented
96  
97 # Note: property
98 0 ▶sub controls : lvalue { return( shift->_set_get_property( { attribute => 'controls', is_boolean => 1 }, @_ ) ); }
Subroutine controls: not called CC=1 SCAR=6.9
Pod documented
99  
100 # Note: property read-only
101 sub controlsList
102 {
103 0 ▶ my $self = shift( @_ );
Subroutine controlsList: not called CC=3 SCAR=24.8
Pod documented
104 0 ▶ unless( $self->{_controlslist_list} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_controlslist_list"}) 0 0 0
105 {
106 0 my $controls = $self->attr( 'controlslist' );
107 0 require HTML::Object::TokenList;
108 0 ▶ $self->{_controlslist_list} = HTML::Object::TokenList->new( $controls, element => $self, attribute => 'controlslist', debug => $self->debug ) ||
Condition0%0/2
'HTML::Object::TokenList'->new($controls, 'element', $self, 'attribute', 'controlslist', 'debug', $self->debug) || (return $self->pass_error('HTML::Object::TokenList'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::TokenList'->new($controls, 'element', $self, 'attribute', 'controlslist', 'debug', $self->debug) || (return $self->pass_error('HTML::Object::TokenList'->error))
'HTML::Object::TokenList'->new($controls, 'element', $self, 'attribute', 'controlslist', 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTML::Object::TokenList'->new($controls, 'element', $self, 'attribute', 'controlslist', 'debug', $self->debug)
Aresult
11
00
109 return( $self->pass_error( HTML::Object::TokenList->error ) );
110 }
111 0 return( $self->{_controlslist_list} );
112 }
113  
114 # Note: property crossOrigin inherited
115  
116 # Note: property read-only currentSrc inherited
117  
118 # Note: property
119 sub currentTime : lvalue { return( shift->_set_get_number({
120 field => 'currentTime',
121 callbacks =>
122 {
123 0 ▶ add => sub{ shift->_trigger_event_for( timeupdate => 'HTML::Object::Event', bubbles => 0, cancellable => 0 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 }
125 0 ▶}, @_ ) ); }
Subroutine currentTime: not called CC=1 SCAR=6.9
Pod documented
126  
127 # Note: property
128 0 ▶sub defaultMuted : lvalue { return( shift->_set_get_property( { attribute => 'muted', is_boolean => 1 }, @_ ) ); }
Subroutine defaultMuted: not called CC=1 SCAR=6.9
Pod documented
129  
130 # Note: property
131 0 ▶sub defaultPlaybackRate : lvalue { return( shift->_set_get_number( 'defaultplaybackrate', @_ ) ); }
Subroutine defaultPlaybackRate: not called CC=1 SCAR=6.9
Pod documented
132  
133 # Note: property
134 0 ▶sub disableRemotePlayback : lvalue { return( shift->_set_get_property( { attribute => 'disableremoteplayback', is_boolean => 1 }, @_ ) ); }
Subroutine disableRemotePlayback: not called CC=1 SCAR=6.9
Pod documented
135  
136 # Note: property
137 sub duration : lvalue { return( shift->_set_get_number({
138 field => 'duration',
139 callbacks => {
140 0 ▶ add => sub{ shift->_trigger_event_for( durationchange => 'HTML::Object::Event', bubbles => 0, cancellable => 0 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
141 }
142 0 ▶}, @_ ) ); }
Subroutine duration: not called CC=1 SCAR=6.9
Pod documented
143  
144 # Note: property read-only
145 0 ▶sub ended : lvalue { return( shift->_set_get_boolean( 'ended', @_ ) ); }
Subroutine ended: not called CC=1 SCAR=6.9
Pod documented
146  
147 # Note: property read-only error is inherited from Module::Generic
148  
149 0 ▶sub fastSeek { return; }
Subroutine fastSeek: not called CC=1 SCAR=6.9
Pod documented
150  
151 # TODO: Maybe do some interesting stuff loading a new file? However, since we cannot do much with audio or video under perl, there is not uch prospect as far as I can tell.
152 0 ▶sub load { return; }
Subroutine load: not called CC=1 SCAR=6.9
Pod documented
153  
154 # Note: property
155 0 ▶sub loop : lvalue { return( shift->_set_get_property( { attribute => 'loop', is_boolean => 1 }, @_ ) ); }
Subroutine loop: not called CC=1 SCAR=6.9
Pod documented
156  
157 # Note: property read-only
158 0 ▶sub mediaKeys { return; }
Subroutine mediaKeys: not called CC=1 SCAR=6.9
Pod documented
159  
160 # Note: property
161 0 ▶sub muted : lvalue { return( shift->_set_get_boolean( 'muted', @_ ) ); }
Subroutine muted: not called CC=1 SCAR=6.9
Pod documented
162  
163 # Note: property read-only
164 0 ▶sub networkState : lvalue { return( shift->_set_get_number( 'networkstate', @_ ) ); }
Subroutine networkState: not called CC=1 SCAR=6.9
Pod documented
165  
166 0 ▶sub onabort : lvalue { return( shift->on( 'abort', @_ ) ); }
Subroutine onabort: not called CC=1 SCAR=6.9
Pod undocumented
167  
168 0 ▶sub oncanplay : lvalue { return( shift->on( 'canplay', @_ ) ); }
Subroutine oncanplay: not called CC=1 SCAR=6.9
Pod undocumented
169  
170 0 ▶sub oncanplaythrough : lvalue { return( shift->on( 'canplaythrough', @_ ) ); }
Subroutine oncanplaythrough: not called CC=1 SCAR=6.9
Pod undocumented
171  
172 0 ▶sub ondurationchange : lvalue { return( shift->on( 'durationchange', @_ ) ); }
Subroutine ondurationchange: not called CC=1 SCAR=6.9
Pod undocumented
173  
174 0 ▶sub onemptied : lvalue { return( shift->on( 'emptied', @_ ) ); }
Subroutine onemptied: not called CC=1 SCAR=6.9
Pod undocumented
175  
176 0 ▶sub onencrypted : lvalue { return( shift->on( 'encrypted', @_ ) ); }
Subroutine onencrypted: not called CC=1 SCAR=6.9
Pod documented
177  
178 0 ▶sub onended : lvalue { return( shift->on( 'ended', @_ ) ); }
Subroutine onended: not called CC=1 SCAR=6.9
Pod undocumented
179  
180 0 ▶sub onerror : lvalue { return( shift->on( 'error', @_ ) ); }
Subroutine onerror: not called CC=1 SCAR=6.9
Pod undocumented
181  
182 0 ▶sub onloadeddata : lvalue { return( shift->on( 'loadeddata', @_ ) ); }
Subroutine onloadeddata: not called CC=1 SCAR=6.9
Pod undocumented
183  
184 0 ▶sub onloadedmetadata : lvalue { return( shift->on( 'loadedmetadata', @_ ) ); }
Subroutine onloadedmetadata: not called CC=1 SCAR=6.9
Pod undocumented
185  
186 0 ▶sub onloadstart : lvalue { return( shift->on( 'loadstart', @_ ) ); }
Subroutine onloadstart: not called CC=1 SCAR=6.9
Pod undocumented
187  
188 0 ▶sub onpause : lvalue { return( shift->on( 'pause', @_ ) ); }
Subroutine onpause: not called CC=1 SCAR=6.9
Pod undocumented
189  
190 0 ▶sub onplay : lvalue { return( shift->on( 'play', @_ ) ); }
Subroutine onplay: not called CC=1 SCAR=6.9
Pod undocumented
191  
192 0 ▶sub onplaying : lvalue { return( shift->on( 'playing', @_ ) ); }
Subroutine onplaying: not called CC=1 SCAR=6.9
Pod undocumented
193  
194 0 ▶sub onprogress : lvalue { return( shift->on( 'progress', @_ ) ); }
Subroutine onprogress: not called CC=1 SCAR=6.9
Pod undocumented
195  
196 0 ▶sub onratechange : lvalue { return( shift->on( 'ratechange', @_ ) ); }
Subroutine onratechange: not called CC=1 SCAR=6.9
Pod undocumented
197  
198 0 ▶sub onseeked : lvalue { return( shift->on( 'seeked', @_ ) ); }
Subroutine onseeked: not called CC=1 SCAR=6.9
Pod undocumented
199  
200 0 ▶sub onseeking : lvalue { return( shift->on( 'seeking', @_ ) ); }
Subroutine onseeking: not called CC=1 SCAR=6.9
Pod undocumented
201  
202 0 ▶sub onstalled : lvalue { return( shift->on( 'stalled', @_ ) ); }
Subroutine onstalled: not called CC=1 SCAR=6.9
Pod undocumented
203  
204 0 ▶sub onsuspend : lvalue { return( shift->on( 'suspend', @_ ) ); }
Subroutine onsuspend: not called CC=1 SCAR=6.9
Pod undocumented
205  
206 0 ▶sub ontimeupdate : lvalue { return( shift->on( 'timeupdate', @_ ) ); }
Subroutine ontimeupdate: not called CC=1 SCAR=6.9
Pod undocumented
207  
208 0 ▶sub onvolumechange : lvalue { return( shift->on( 'volumechange', @_ ) ); }
Subroutine onvolumechange: not called CC=1 SCAR=6.9
Pod undocumented
209  
210 0 ▶sub onwaiting : lvalue { return( shift->on( 'waiting', @_ ) ); }
Subroutine onwaiting: not called CC=1 SCAR=6.9
Pod undocumented
211  
212 0 ▶sub onwaitingforkey : lvalue { return( shift->on( 'waitingforkey', @_ ) ); }
Subroutine onwaitingforkey: not called CC=1 SCAR=6.9
Pod documented
213  
214 sub pause
215 {
216 0 ▶ my $self = shift( @_ );
Subroutine pause: not called CC=1 SCAR=6.9
Pod documented
217 0 $self->{_callback_off} = 1;
218 0 $self->paused(1);
219 0 $self->{_callback_off} = 0;
220 0 $self->_trigger_event_for( pause => 'HTML::Object::Event', bubbles => 0, cancellable => 0 );
221 0 return( $self )
222 }
223  
224 # Note: property read-only
225 sub paused : lvalue { return( shift->_set_get_boolean({
226 field => 'paused',
227 callbacks => {
228 add => sub
229 {
230 0 ▶ my $self = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
231 0 ▶ return if( $self->{_callback_off} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_callback_off"} 0 0 0
232 0 $self->_trigger_event_for( paused => 'HTML::Object::Event', bubbles => 0, cancellable => 0 );
233 }
234 }
235 0 ▶}, @_ ) ); }
Subroutine paused: not called CC=1 SCAR=6.9
Pod documented
236  
237 sub play
238 {
239 0 ▶ my $self = shift( @_ );
Subroutine play: not called CC=1 SCAR=6.9
Pod documented
240 0 $self->{_callback_off} = 1;
241 0 $self->paused(0);
242 0 $self->{_callback_off} = 0;
243 0 $self->_trigger_event_for( play => 'HTML::Object::Event', bubbles => 0, cancellable => 0 );
244 0 return( $self );
245 }
246  
247 # Note: property
248 sub playbackRate : lvalue { return( shift->_set_get_number({
249 field => 'playbackrate',
250 callbacks =>
251 {
252 0 ▶ add => sub{ return( shift->_trigger_event_for( ratechange => 'HTML::Object::Event', bubbles => 0, cancellable => 0 ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
253 }
254 0 ▶}, @_ ) ); }
Subroutine playbackRate: not called CC=1 SCAR=6.9
Pod documented
255  
256 # Note: property read-only
257 0 ▶sub played { return; }
Subroutine played: not called CC=1 SCAR=6.9
Pod documented
258  
259 # Note: property
260 0 ▶sub preload : lvalue { return( shift->_set_get_property( 'preload', @_ ) ); }
Subroutine preload: not called CC=1 SCAR=6.9
Pod documented
261  
262 # Note: property
263 0 ▶sub preservesPitch : lvalue { return( shift->_set_get_boolean( 'preservespitch', @_ ) ); }
Subroutine preservesPitch: not called CC=1 SCAR=6.9
Pod documented
264  
265 # Note: property read-only
266 0 ▶sub readyState : lvalue { return( shift->_set_get_number( 'readystate', @_ ) ); }
Subroutine readyState: not called CC=1 SCAR=6.9
Pod documented
267  
268 # TODO: removeTextTrack
269 sub removeTextTrack
270 {
271 0 ▶ my $self = shift( @_ );
Subroutine removeTextTrack: not called CC=3 SCAR=24.8
Pod documented
272 0 my $obj = shift( @_ );
273 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($obj, "HTML::Object::DOM::TextTrack") 0 0 0
274 message => "Value provided is not a HTML::Object::DOM::TextTrack object.",
275 class => 'HTML::Object::TypeError',
276 }) ) if( !$self->_is_a( $obj => 'HTML::Object::DOM::TextTrack' ) );
277 0 my $list = $self->textTracks;
278 0 my $pos = $list->pos( $obj );
279 0 ▶ return if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
280 0 $list->splice( $pos, 1 );
281 # There is no parent, because a TextTrack parent is actually a HTML::Object::DOM::Element::Track object
282 # and here we only add or remove a TextTrack object directly.
283 # $obj->parent( undef );
284 0 return( $obj );
285 }
286  
287 # Note: property read-only
288 0 ▶sub seekable { return; }
Subroutine seekable: not called CC=1 SCAR=6.9
Pod documented
289  
290 # Note: property read-only
291 0 ▶sub seeking : lvalue { return( shift->_set_get_boolean( 'seeking', @_ ) ); }
Subroutine seeking: not called CC=1 SCAR=6.9
Pod documented
292  
293 0 ▶sub seekToNextFrame { return; }
Subroutine seekToNextFrame: not called CC=1 SCAR=6.9
Pod documented
294  
295 0 ▶sub setMediaKeys { return; }
Subroutine setMediaKeys: not called CC=1 SCAR=6.9
Pod documented
296  
297 0 ▶sub setSinkId { return( shift->_set_get_scalar_as_object( 'sinkid', @_ ) ); }
Subroutine setSinkId: not called CC=1 SCAR=6.9
Pod documented
298  
299 # Note: property read-only
300 0 ▶sub sinkId : lvalue { return( shift->_set_get_scalar_as_object( 'sinkid', @_ ) ); }
Subroutine sinkId: not called CC=1 SCAR=6.9
Pod documented
301  
302 # Note: property src inherited
303  
304 # Note: property
305 0 ▶sub srcObject { return; }
Subroutine srcObject: not called CC=1 SCAR=6.9
Pod documented
306  
307 # Note: property read-only
308 0 ▶sub textTracks { return( shift->_set_get_object( 'textTracks', 'HTML::Object::DOM::TextTrackList', @_ ) ); }
Subroutine textTracks: not called CC=1 SCAR=6.9
Pod documented
309  
310 # Note: property read-only
311 0 ▶sub videoTracks { return( shift->_set_get_object( 'textTracks', 'HTML::Object::DOM::VideoTrackList', @_ ) ); }
Subroutine videoTracks: not called CC=1 SCAR=6.9
Pod documented
312  
313 # Note: property
314 sub volume : lvalue { return( shift->_set_get_number({
315 field => 'volume',
316 callbacks =>
317 {
318 0 ▶ add => sub{ shift->_trigger_event_for( volumechange => 'HTML::Object::Event', bubbles => 0, cancellable => 0 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
319 }
320 0 ▶}, @_ ) ); }
Subroutine volume: not called CC=1 SCAR=6.9
Pod documented
321  
322 1 1;
323 # NOTE: POD
324 __END__
325  
326 =encoding utf-8
327  
328 =head1 NAME
329  
330 HTML::Object::DOM::Element::Media - HTML Object DOM Media Class
331  
332 =head1 SYNOPSIS
333  
334 use HTML::Object::DOM::Element::Media;
335 my $media = HTML::Object::DOM::Element::Media->new ||
336 die( HTML::Object::DOM::Element::Media->error, "\n" );
337  
338 =head1 VERSION
339  
340 v0.2.0
341  
342 =head1 DESCRIPTION
343  
344 This interface adds to L<HTML::Object::DOM::Element> the properties and methods needed to support basic media-related capabilities that are common to L<audio|HTML::Object::DOM::Element::Audio> and L<video|HTML::Object::DOM::Element::Video>.
345  
346 =head1 INHERITANCE
347  
348 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
349 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Media |
350 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
351  
352 =head1 PROPERTIES
353  
354 Inherits properties from its parent L<HTML::Object::DOM::Element>
355  
356 =head2 audioTracks
357  
358 A AudioTrackList that lists the AudioTrack objects contained in the element.
359  
360 Example:
361  
362 my $video = $doc->getElementById("video");
363  
364 for( my $i = 0; $i < $video->audioTracks->length; $i += 1 )
365 {
366 $video->audioTracks->[$i]->enabled = 0; # false
367 }
368  
369 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/audioTracks>
370  
371 =head2 autoplay
372  
373 A boolean value that reflects the C<autoplay> HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption.
374  
375 Note: Automatically playing audio when the user does not expect or desire it is a poor user experience and should be avoided in most cases, though there are exceptions. See the L<Mozilla Autoplay guide for media and Web Audio APIs|https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide> for more information. Keep in mind that browsers may ignore autoplay requests, so you should ensure that your code is not dependent on C<autoplay> working.
376  
377 Example:
378  
379 <video id="video" autoplay="" controls>
380 <source src="https://player.vimeo.com/external/250688977.sd.mp4?s=d14b1f1a971dde13c79d6e436b88a6a928dfe26b&profile_id=165">
381 </video>
382  
383 # *** Disable autoplay (recommended) ***
384 # false is the default value
385 $doc->querySelector('#video')->autoplay = 0; # false
386 # <video id="video" controls>
387  
388 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/autoplay>
389  
390 =head2 buffered
391  
392 This returns C<undef> under perl.
393  
394 Normally, under JavaScript, this returns a C<TimeRanges> object that indicates the ranges of the media source that the browser has buffered (if any) at the moment the buffered property is accessed.
395  
396 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/buffered>
397  
398 =head2 controller
399  
400 This returns C<undef> under perl.
401  
402 Normally, under JavaScript, this returns a C<MediaController> object that represents the media controller assigned to the element, or C<undef> if none is assigned.
403  
404 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/controller>
405  
406 =head2 controls
407  
408 Is a boolean that reflects the controls HTML attribute, indicating whether user interface items for controlling the resource should be displayed.
409  
410 Example:
411  
412 my $obj = $doc->createElement('video');
413 $obj->controls = 1; # true
414  
415 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/controls>
416  
417 =head2 controlsList
418  
419 Returns a L<HTML::Object::TokenList> that helps the user agent select what controls to show on the media element whenever the user agent shows its own set of controls. The L<HTML::Object::TokenList> takes one or more of three possible values: C<nodownload>, C<nofullscreen>, and C<noremoteplayback>.
420  
421 Example:
422  
423 To disable the dowload button for HTML5 audio and video player:
424  
425 <audio controls controlsList="nodownload"><source src="song.mp3" type="audio/mpeg"></audio>
426  
427 <video controls controlsList="nodownload"><source src="video.mp4" type="video/mp4"></video>
428  
429 Another example:
430  
431 <video controls controlsList="nofullscreen nodownload noremoteplayback"></video>
432  
433 Using code:
434  
435 my $video = $doc->querySelector('video');
436 $video->controls; # true
437 $video->controlsList; # ["nofullscreen", "nodownload", "noremoteplayback"]
438 $video->controlsList->remove('noremoteplayback');
439 $video->controlsList; # ["nofullscreen", "nodownload"]
440 $video->getAttribute('controlsList'); # "nofullscreen nodownload"
441  
442 # Actually, under perl, 'supports' always returns true
443 $video->controlsList->supports('foo'); # false
444 $video->controlsList->supports('noremoteplayback'); # true
445  
446 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/controlsList>, L<Chromium documentation|https://developers.google.com/web/updates/2017/03/chrome-58-media-updates>
447  
448 =head2 crossOrigin
449  
450 A string indicating the CORS setting for this media element.
451  
452 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/crossOrigin>
453  
454 =head2 currentSrc
455  
456 Returns a string with the absolute URL of the chosen media resource.
457  
458 Example:
459  
460 my $obj = $doc->createElement('video');
461 say($obj->currentSrc); # ""
462  
463 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/currentSrc>
464  
465 =head2 currentTime
466  
467 This returns whatever number you set it to under perl, as a L<Module::Generic::Number> object.
468  
469 Normally, under JavaScript, this returns a double-precision floating-point value indicating the current playback time in seconds; if the media has not started to play and has not been seeked, this value is the media's initial playback time. Setting this value seeks the media to the new time. The time is specified relative to the media's timeline.
470  
471 Example:
472  
473 my $video = $doc->createElement('$video');
474 say( $video->currentTime );
475 $vide->currentTime = 35;
476  
477 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/currentTime>
478  
479 =head2 defaultMuted
480  
481 A Boolean that reflects the C<muted> HTML attribute, which indicates whether the media element's audio output should be muted by default.
482  
483 Example:
484  
485 my $video = $doc->createElement('video');
486 $video->defaultMuted = 1; # true
487 say( $video->outerHTML ); # <video muted=""></video>
488  
489 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/defaultMuted>
490  
491 =head2 defaultPlaybackRate
492  
493 This returns whatever number you set it to under perl, as a L<Module::Generic::Number> object.
494  
495 Normally, under JavaScript, this returns a double indicating the default playback rate for the media.
496  
497 Example:
498  
499 my $obj = $doc->createElement('video');
500 say($obj->defaultPlaybackRate); # 1
501  
502 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/defaultPlaybackRate>
503  
504 =head2 disableRemotePlayback
505  
506 A boolean that sets or returns the remote playback state of the HTML attribute, indicating whether the media element is allowed to have a remote playback UI.
507  
508 Example:
509  
510 my $obj = $doc->createElement('audio');
511 # <audio></audio>
512 $obj->disableRemotePlayback = 1; # true
513 # <audio disableremoteplayback=""></audio>
514  
515 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/disableRemotePlayback>
516  
517 =head2 duration
518  
519 This returns whatever number you set it to under perl, as a L<Module::Generic::Number> object.
520  
521 Normally, under JavaScript, this returns a read-only double-precision floating-point value indicating the total duration of the media in seconds. If no media data is available, the returned value is C<NaN>. If the media is of indefinite length (such as streamed live media, a WebRTC call's media, or similar), the value is C<+Infinity>.
522  
523 Example:
524  
525 my $obj = $doc->createElement('video');
526 say( $obj->duration ); # NaN
527  
528 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration>
529  
530 =head2 ended
531  
532 Returns a Boolean that indicates whether the media element has finished playing.
533  
534 Example:
535  
536 my $obj = $doc->createElement('video');
537 say($obj->ended); # false
538  
539 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/ended>
540  
541 =head2 error
542  
543 Read-only.
544  
545 This returns a L<HTML::Object::MediaError> object for the most recent error, or C<undef> if there has not been an error.
546  
547 Example:
548  
549 my $video = $doc->createElement('video');
550 $video->onerror = sub
551 {
552 say( "Error " . $video->error->code . "; details: " . $video->error->message );
553 }
554 $video->src = 'https://example.org/badvideo.mp4';
555  
556 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/error>
557  
558 =head2 loop
559  
560 A Boolean that reflects the C<loop> HTML attribute, which indicates whether the media element should start over when it reaches the end.
561  
562 Example:
563  
564 my $obj = $doc->createElement('video');
565 $obj->loop = 1; # true
566  
567 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loop>
568  
569 =head2 mediaKeys
570  
571 This always returns C<undef> under perl.
572  
573 Normally, under JavaScript, this returns a L<MediaKeys object|https://developer.mozilla.org/en-US/docs/Web/API/MediaKeys> or C<undef>. L<MediaKeys|https://developer.mozilla.org/en-US/docs/Web/API/MediaKeys> is a set of keys that an associated L<HTML::Object::DOM::Element::Media> can use for decryption of media data during playback.
574  
575 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/mediaKeys>
576  
577 =head2 muted
578  
579 Is a boolean that determines whether audio is muted. true if the audio is muted and false otherwise. This does not affect the DOM.
580  
581 Example:
582  
583 my $obj = $doc->createElement('video');
584 say( $obj->muted ); # false
585  
586 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/muted>
587  
588 =head2 networkState
589  
590 Set or get an integer (enumeration) indicating the current state of fetching the media over the network.
591  
592 Example:
593  
594 <audio id="example" preload="auto">
595 <source src="sound.ogg" type="audio/ogg" />
596 </audio>
597  
598 # Export constants
599 use HTML::Object::DOM::Element::Media qw( :all );
600 my $obj = $doc->getElementById('example');
601 $obj->addEventListener( playing => sub
602 {
603 if( $obj->networkState == NETWORK_LOADING )
604 {
605 # Still loading...
606 }
607 });
608  
609 See L</CONSTANTS> below for the constants that can be exported and used.
610  
611 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/networkState>
612  
613 =head2 paused
614  
615 Returns a boolean that indicates whether the media element is paused. This is set to true if you use the L</pause> method and set to false when you use the L</play> method.
616  
617 Example:
618  
619 my $obj = $doc->createElement('video');
620 say( $obj->paused ); # true
621  
622 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/paused>
623  
624 =head2 playbackRate
625  
626 This only sets or gets a number under perl environment.
627  
628 Normally, under JavaScript, this is a double that indicates the rate at which the media is being played back.
629  
630 Example:
631  
632 my $obj = $doc->createElement('video');
633 say( $obj->playbackRate ); # Expected Output: 1
634  
635 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playbackRate>
636  
637 =head2 played
638  
639 This always returns C<undef> under perl.
640  
641 Normally, under JavaScript, this returns a L<TimeRanges object|https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges> that contains the ranges of the media source that the browser has played, if any.
642  
643 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/played>
644  
645 =head2 preload
646  
647 Is a string that reflects the C<preload> HTML attribute, indicating what data should be preloaded, if any. Possible values are: C<none>, C<metadata>, C<auto>.
648  
649 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/preload>
650  
651 =head2 preservesPitch
652  
653 Under perl environment, this is just a boolean value you can set or get.
654  
655 Under JavaScript environment, this is a boolean that determines if the pitch of the sound will be preserved. If set to false, the pitch will adjust to the speed of the audio. This is implemented with prefixes in Firefox (C<mozPreservesPitch>) and WebKit (C<webkitPreservesPitch>).
656  
657 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/preservesPitch>
658  
659 =head2 readyState
660  
661 Set or get an integer (enumeration) indicating the readiness state of the media.
662  
663 Example:
664  
665 <audio id="example" preload="auto">
666 <source src="sound.ogg" type="audio/ogg" />
667 </audio>
668  
669 use HTML::Object::DOM::Element::Media qw( :all );
670 my $obj = $doc->getElementById('example');
671 $obj->addEventListener( loadeddata => sub
672 {
673 if( $obj->readyState >= NETWORK_LOADING )
674 {
675 $obj->play();
676 }
677 });
678  
679 See L</CONSTANTS> for the constants that can be exported and used.
680  
681 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/readyState>
682  
683 =head2 seekable
684  
685 This always returns C<undef> under perl.
686  
687 Normally, under JavaScript, this returns a L<TimeRanges object|https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges> that contains the time ranges that the user is able to seek to, if any.
688  
689 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/seekable>
690  
691 =head2 seeking
692  
693 Under perl environment, this is just a boolean value you can set or get.
694  
695 Under JavaScript environment, this is a boolean that indicates whether the media is in the process of seeking to a new position.
696  
697 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/seeking>
698  
699 =head2 sinkId
700  
701 This returns C<undef> by default under perl. You can set a value using L</setSinkId>.
702  
703 Normally, under JavaScript, this returns a string that is the unique ID of the audio device delivering output, or an empty string if it is using the user agent default. This ID should be one of the C<MediaDeviceInfo.deviceid> values returned from C<MediaDevices.enumerateDevices()>, id-multimedia, or id-communications.
704  
705 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/sinkId>
706  
707 =head2 src
708  
709 Is a string that reflects the C<src> HTML attribute, which contains the URL of a media resource to use.
710  
711 Example:
712  
713 my $obj = $doc->createElement('video');
714 say( $obj->src ); # ""
715  
716 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/src>
717  
718 =head2 srcObject
719  
720 This always returns C<undef> under perl.
721  
722 Normally, under JavaScript, this is a L<MediaStream|https://developer.mozilla.org/en-US/docs/Web/API/MediaStream> representing the media to play or that has played in the current L<HTML::Object::DOM::Element::Media>, or C<undef> if not assigned.
723  
724 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject>
725  
726 =head2 textTracks
727  
728 Read-only.
729  
730 Returns the list of L<TextTrack|HTML::Object::DOM::TextTrack> objects contained in the element.
731  
732 Example:
733  
734 <video controls poster="/images/sample.gif">
735 <source src="sample.mp4" type="video/mp4">
736 <source src="sample.ogv" type="video/ogv">
737 <track kind="captions" src="sampleCaptions.vtt" srclang="en">
738 <track kind="descriptions" src="sampleDescriptions.vtt" srclang="en">
739 <track kind="chapters" src="sampleChapters.vtt" srclang="en">
740 <track kind="subtitles" src="sampleSubtitles_de.vtt" srclang="de">
741 <track kind="subtitles" src="sampleSubtitles_en.vtt" srclang="en">
742 <track kind="subtitles" src="sampleSubtitles_ja.vtt" srclang="ja">
743 <track kind="subtitles" src="sampleSubtitles_oz.vtt" srclang="oz">
744 <track kind="metadata" src="keyStage1.vtt" srclang="en" label="Key Stage 1">
745 <track kind="metadata" src="keyStage2.vtt" srclang="en" label="Key Stage 2">
746 <track kind="metadata" src="keyStage3.vtt" srclang="en" label="Key Stage 3">
747 </video>
748  
749 my $tracks = $doc->querySelector('video')->textTracks;
750  
751 # $tracks->length == 10
752 for( my $i = 0, $L = $tracks->length; $i < $L; $i++ )
753 {
754 if( $tracks->[$i]->language eq 'en' )
755 {
756 say( $tracks->[$i] );
757 }
758 }
759  
760 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/textTracks>
761  
762 =head2 videoTracks
763  
764 Read-only.
765  
766 Returns the list of L<VideoTrack|HTML::Object::DOM::VideoTrack> objects contained in the element.
767  
768 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/videoTracks>
769  
770 =head2 volume
771  
772 Is a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest).
773  
774 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/volume>
775  
776 =head1 METHODS
777  
778 Inherits methods from its parent L<HTML::Object::DOM::Element>
779  
780 =head2 addTextTrack
781  
782 Adds a L<text track|HTML::Object::DOM::TextTrack> (such as a track for subtitles) to a media element.
783  
784 This takes a track C<kind>, C<label> and C<language> and returns a new L<HTML::Object::DOM::TextTrack> object.
785  
786 Possible values for C<kind> are:
787  
788 =over 4
789  
790 =item caption
791  
792 =item chapters
793  
794 =item descriptions
795  
796 =item metadata
797  
798 =item subtitles
799  
800 =back
801  
802 C<label> is a string specifying the label for the text track. Is used to identify the text track for the users.
803  
804 C<language> in iso 639 format (e.g. C<en-US> or C<ja-JP>).
805  
806 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/addTextTrack>
807  
808 =head2 canPlayType
809  
810 This always returns C<undef> under perl.
811  
812 Normally, under JavaScript, given a string specifying a MIME media type (potentially with the codecs parameter included), C<canPlayType>() returns the string probably if the media should be playable, maybe if there's not enough information to determine whether the media will play or not, or an empty string if the media cannot be played.
813  
814 Example:
815  
816 my $obj = $doc->createElement('video');
817 say( $obj->canPlayType('video/mp4') ); # "maybe"
818  
819 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType>
820  
821 =head2 captureStream
822  
823 This always returns C<undef> under perl.
824  
825 Normally, under JavaScript, this returns C<MediaStream>, captures a stream of the media content.
826  
827 Example:
828  
829 $doc->querySelector('.playAndRecord')->addEventListener( click => sub
830 {
831 my $playbackElement = $doc->getElementById("playback");
832 my $captureStream = $playbackElement->captureStream();
833 $playbackElement->play();
834 });
835  
836 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/captureStream>
837  
838 =head2 fastSeek
839  
840 This always returns C<undef> under perl.
841  
842 Normally, under JavaScript, this quickly seeks to the given time with low precision.
843  
844 Example:
845  
846 my $myVideo = $doc->getElementById("myVideoElement");
847  
848 $myVideo->fastSeek(20);
849  
850 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/fastSeek>
851  
852 =head2 load
853  
854 This always returns C<undef> under perl.
855  
856 Normally, under JavaScript, this resets the media to the beginning and selects the best available source from the sources provided using the src attribute or the <source> element.
857  
858 Example:
859  
860 my $mediaElem = $doc->querySelector("video");
861 $mediaElem->load();
862  
863 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/load>
864  
865 =head2 pause
866  
867 Under perl, this does not do anything particular except setting the L</paused> boolean value to true.
868  
869 Pauses the media playback.
870  
871 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause>
872  
873 =head2 play
874  
875 This does not do anything in particular under perl, except setting the C<paused> boolean value to false.
876  
877 Normally, under JavaScript, this begins playback of the media.
878  
879 Example:
880  
881 use Nice::Try;
882 my $videoElem = $doc->getElementById( 'video' );
883 my $playButton = $doc->getElementById( 'playbutton' );
884  
885 $playButton->addEventListener( 'click', \&handlePlayButton, { capture => 0 });
886 playVideo();
887  
888 sub playVideo
889 {
890 try
891 {
892 $videoElem->play();
893 $playButton->classList->add( 'playing' );
894 }
895 catch($err)
896 {
897 $playButton->classList->remove( 'playing' );
898 }
899 }
900  
901 sub handlePlayButton
902 {
903 if( $videoElem->paused )
904 {
905 playVideo();
906 }
907 else
908 {
909 $videoElem->pause();
910 $playButton->classList->remove( 'playing' );
911 }
912 }
913  
914 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play>
915  
916 =head2 removeTextTrack
917  
918 Provided with a L<HTML::Object::DOM::TextTrack> object and this will remove it.
919  
920 It returns the L<HTML::Object::DOM::TextTrack> object upon success, or if it cannot be found, it returns C<undef>
921  
922 =head2 seekToNextFrame
923  
924 This always returns C<undef> under perl.
925  
926 Normally, under JavaScript, this seeks to the next frame in the media. This non-standard, experimental method makes it possible to manually drive reading and rendering of media at a custom speed, or to move through the media frame-by-frame to perform filtering or other operations.
927  
928 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/seekToNextFrame>
929  
930 =head2 setMediaKeys
931  
932 This always returns C<undef> under perl.
933  
934 Normally, under JavaScript, this returns Promise. Sets the MediaKeys keys to use when decrypting media during playback.
935  
936 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setMediaKeys>
937  
938 =head2 setSinkId
939  
940 This does not do anything particular under perl, except setting the value of L</sinkid>.
941  
942 Normally, under JavaScript, this sets the ID of the audio device to use for output and returns a Promise. This only works when the application is authorized to use the specified device.
943  
944 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId>
945  
946 =head1 EVENTS
947  
948 =head2 abort
949  
950 This is not used under perl, but you can trigger that event yourself.
951  
952 Under JavaScript, this is fired when the resource was not fully loaded, but not as the result of an error.
953  
954 Example:
955  
956 my $video = $doc->querySelector('video');
957 my $videoSrc = 'https://example.org/path/to/video.webm';
958  
959 $video->addEventListener( abort => sub
960 {
961 say( "Abort loading: ", $videoSrc );
962 });
963  
964 my $source = $doc->createElement('source');
965 $source->setAttribute( src => $videoSrc );
966 $source->setAttribute( type => 'video/webm' );
967  
968 $video->appendChild( $source );
969  
970 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/abort_event>
971  
972 =head2 canplay
973  
974 This is not used under perl, but you can trigger that event yourself.
975  
976 Under JavaScript, this is fired when the user agent can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content
977  
978 Example:
979  
980 my $video = $doc->querySelector( 'video' );
981  
982 $video->addEventListener( canplay => sub
983 {
984 my $event = shift( @_ );
985 say( 'Video can start, but not sure it will play through.' );
986 });
987  
988 my $video = $doc->querySelector( 'video' );
989 $video->oncanplay = sub
990 {
991 my $event = shift( @_ );
992 say( 'Video can start, but not sure it will play through.' );
993 };
994  
995 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canplay_event>
996  
997 =head2 canplaythrough
998  
999 This is not used under perl, but you can trigger that event yourself.
1000  
1001 Under JavaScript, this is fired when the user agent can play the media, and estimates that enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
1002  
1003 Example:
1004  
1005 my $video = $doc->querySelector( 'video' );
1006  
1007 $video->addEventListener( canplaythrough => sub
1008 {
1009 my $event = shift( @_ );
1010 say( "I think I can play through the entire video without ever having to stop to buffer." );
1011 });
1012  
1013 my $video = $doc->querySelector( 'video' );
1014  
1015 $video->oncanplaythrough = sub
1016 {
1017 my $event = shift( @_ );
1018 say( "I think I can play through the entire video without ever having to stop to buffer." );
1019 };
1020  
1021 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canplaythrough_event>
1022  
1023 =head2 durationchange
1024  
1025 This is fired when the duration property has been updated.
1026  
1027 Example:
1028  
1029 my $video = $doc->querySelector('video');
1030 $video->addEventListener( durationchange => sub
1031 {
1032 say( 'Not sure why, but the duration of the $video has changed.' );
1033 });
1034  
1035 my $video = $doc->querySelector('video');
1036  
1037 $video->ondurationchange = sub
1038 {
1039 say( 'Not sure why, but the duration of the video has changed.' );
1040 };
1041  
1042 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/durationchange_event>
1043  
1044 =head2 emptied
1045  
1046 This is not used under perl, but you can trigger that event yourself.
1047  
1048 Under JavaScript, this is fired when the media has become empty; for example, when the media has already been loaded (or partially loaded), and the L<HTML::Object::DOM::Element::Media/load> method is called to reload it.
1049  
1050 Example:
1051  
1052 my $video = $doc->querySelector('video');
1053  
1054 $video->addEventListener( emptied => sub
1055 {
1056 say( 'Uh oh. The media is empty. Did you call load()?' );
1057 });
1058  
1059 my $video = $doc->querySelector('video');
1060  
1061 $video->onemptied = sub
1062 {
1063 say( 'Uh oh. The media is empty. Did you call load()?' );
1064 };
1065  
1066 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/emptied_event>
1067  
1068 =head2 ended
1069  
1070 This is not used under perl, but you can trigger that event yourself.
1071  
1072 Under JavaScript, this is fired when playback stops when end of the media (<audio> or <video>) is reached or because no further data is available.
1073  
1074 Example:
1075  
1076 my $obj = $doc->createElement('video');
1077 say( $obj->ended ); # false
1078  
1079 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/ended_event>
1080  
1081 =head2 error
1082  
1083 Fired when the resource could not be loaded due to an error.
1084  
1085 Example:
1086  
1087 my $videoElement = $doc->createElement( 'video' );
1088 $videoElement->onerror = sub
1089 {
1090 say( "Error " . $videoElement->error->code . "; details: " . $videoElement->error->message );
1091 }
1092 $videoElement->src = "https://example.org/bogusvideo.mp4";
1093  
1094 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/error_event>
1095  
1096 =head2 loadeddata
1097  
1098 This is not used under perl, but you can trigger that event yourself.
1099  
1100 Under JavaScript, this is fired when the first frame of the media has finished loading.
1101  
1102 Example:
1103  
1104 my $video = $doc->querySelector('video');
1105  
1106 $video->addEventListener( loadeddata => sub
1107 {
1108 say( 'Yay! The readyState just increased to HAVE_CURRENT_DATA or greater for the first time.' );
1109 });
1110  
1111 my $video = $doc->querySelector('video');
1112  
1113 $video->onloadeddata = sub
1114 {
1115 say( 'Yay! The readyState just increased to HAVE_CURRENT_DATA or greater for the first time.' );
1116 };
1117  
1118 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loadeddata_event>
1119  
1120 =head2 loadedmetadata
1121  
1122 This is not used under perl, but you can trigger that event yourself.
1123  
1124 Under JavaScript, this is fired when the metadata has been loaded
1125  
1126 Example:
1127  
1128 my $video = $doc->querySelector('video');
1129  
1130 $video->addEventListener( loadedmetadata => sub
1131 {
1132 say( 'The duration and dimensions of the media and tracks are now known.' );
1133 });
1134  
1135 my $video = $doc->querySelector('video');
1136  
1137 $video->onloadedmetadata = sub
1138 {
1139 say( 'The duration and dimensions of the media and tracks are now known.' );
1140 };
1141  
1142 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loadedmetadata_event>
1143  
1144 =head2 loadstart
1145  
1146 This is not used under perl, but you can trigger that event yourself.
1147  
1148 Under JavaScript, this is fired when the browser has started to load a resource.
1149  
1150 Example:
1151  
1152 <div class="example">
1153 <button type="button">Load video</button>
1154 <video controls width="250"></video>
1155  
1156 <div class="event-log">
1157 <label>Event log:</label>
1158 <textarea readonly class="event-log-contents"></textarea>
1159 </div>
1160 </div>
1161  
1162 use feature 'signatures';
1163 my $loadVideo = $doc->querySelector('button');
1164 my $video = $doc->querySelector('video');
1165 my $eventLog = $doc->querySelector('.event-log-contents');
1166 my $source;
1167  
1168 sub handleEvent( $event )
1169 {
1170 $eventLog->textContent = $eventLog->textContent . $event->type . "\n";
1171 }
1172  
1173 $video->addEventListener( 'loadstart', \&handleEvent);
1174 $video->addEventListener( 'progress', \&handleEvent);
1175 $video->addEventListener( 'canplay', \&handleEvent);
1176 $video->addEventListener( 'canplaythrough', \&handleEvent);
1177  
1178 $loadVideo->addEventListener( click => sub
1179 {
1180 if( $source )
1181 {
1182 $doc->location->reload();
1183 }
1184 else
1185 {
1186 $loadVideo->textContent = "Reset example";
1187 $source = $doc->createElement( 'source' );
1188 $source->setAttribute( 'src', 'https://example.org/some/where/media/examples/video.webm' );
1189 $source->setAttribute( 'type', 'video/webm' );
1190 $video->appendChild( $source );
1191 }
1192 });
1193  
1194 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loadstart_event>
1195  
1196 =head2 pause
1197  
1198 Fired when a request to pause play is handled and the activity has entered its paused state, most commonly occurring when the media's L<HTML::Object::DOM::Element::Media/pause> method is called.
1199  
1200 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause_event>
1201  
1202 =head2 play
1203  
1204 Fired when the paused property is changed from true to false, as a result of the L<HTML::Object::DOM::Element::Media/play> method, or the autoplay attribute
1205  
1206 Example:
1207  
1208 use Nice::Try; # for the try{}catch block
1209 my $videoElem = $doc->getElementById( 'video' );
1210 my $playButton = $doc->getElementById( 'playbutton' );
1211  
1212 $playButton->addEventListener( click => \&handlePlayButton, { capture => 0 });
1213 playVideo();
1214  
1215 sub playVideo
1216 {
1217 try {
1218 $videoElem->play();
1219 $playButton->classList->add( 'playing' );
1220 } catch( $err ) {
1221 $playButton->classList->remove( 'playing' );
1222 }
1223 }
1224  
1225 sub handlePlayButton
1226 {
1227 if( $videoElem->paused )
1228 {
1229 playVideo();
1230 }
1231 else
1232 {
1233 $videoElem->pause();
1234 $playButton->classList->remove( 'playing' );
1235 }
1236 }
1237  
1238 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play_event>
1239  
1240 =head2 playing
1241  
1242 This is not used under perl, but you can trigger that event yourself.
1243  
1244 Under JavaScript, this is fired when playback is ready to start after having been paused or delayed due to lack of data
1245  
1246 Example:
1247  
1248 my $video = $doc->querySelector('video');
1249  
1250 $video->addEventListener( playing =>sub
1251 {
1252 say( 'Video is no longer paused' );
1253 });
1254  
1255 my $video = $doc->querySelector('video');
1256  
1257 $video->onplaying = sub
1258 {
1259 say( 'Video is no longer paused.' );
1260 };
1261  
1262 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playing_event>
1263  
1264 =head2 progress
1265  
1266 This is not used under perl, but you can trigger that event yourself.
1267  
1268 Under JavaScript, this is fired periodically as the browser loads a resource.
1269  
1270 Example:
1271  
1272 <div class="example">
1273 <button type="button">Load video</button>
1274 <video controls width="250"></video>
1275  
1276 <div class="event-log">
1277 <label>Event log:</label>
1278 <textarea readonly class="event-log-contents"></textarea>
1279 </div>
1280 </div>
1281  
1282 use feature 'signatures';
1283 my $loadVideo = $doc->querySelector('button');
1284 my $video = $doc->querySelector('video');
1285 my $eventLog = $doc->querySelector('.event-log-contents');
1286 my $source;
1287  
1288 sub handleEvent( $event )
1289 {
1290 $eventLog->textContent = $eventLog->textContent . $event->type . "\n";
1291 }
1292  
1293 $video->addEventListener( 'loadstart', \&handleEvent );
1294 $video->addEventListener( 'progress', \&handleEvent );
1295 $video->addEventListener( 'canplay', \&handleEvent );
1296 $video->addEventListener( 'canplaythrough', \&handleEvent );
1297  
1298 $loadVideo->addEventListener( click => sub
1299 {
1300 if( $source )
1301 {
1302 $doc->location->reload();
1303 }
1304 else
1305 {
1306 $loadVideo->textContent = "Reset example";
1307 $source = $doc->createElement('source');
1308 $source->setAttribute( 'src', 'https://example.org/some/where/video.mp4' );
1309 $source->setAttribute( 'type', 'video/mp4' );
1310 $video->appendChild( $source );
1311 }
1312 });
1313  
1314 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/progress_event>
1315  
1316 =head2 ratechange
1317  
1318 This is fired when the playback rate has changed, i.e. when the property L</playbackRate> is changed.
1319  
1320 Example:
1321  
1322 my $video = $doc->querySelector( 'video' );
1323  
1324 $video->addEventListener( 'ratechange' => sub
1325 {
1326 say( 'The playback rate changed.' );
1327 });
1328  
1329 my $video = $doc->querySelector('video');
1330  
1331 $video->onratechange = sub
1332 {
1333 say( 'The playback rate changed.' );
1334 };
1335  
1336 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/ratechange_event>
1337  
1338 =head2 seeked
1339  
1340 This is not used under perl, but you can trigger that event yourself.
1341  
1342 Under JavaScript, this is fired when a seek operation completes
1343  
1344 Example:
1345  
1346 my $video = $doc->querySelector('video');
1347 $video->addEventListener( seeked => sub
1348 {
1349 say( 'Video found the playback position it was looking for.' );
1350 });
1351 my $video = $doc->querySelector( 'video' );
1352 $video->onseeked = sub
1353 {
1354 say( 'Video found the playback position it was looking for.' );
1355 };
1356  
1357 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/seeked_event>
1358  
1359 =head2 seeking
1360  
1361 This is not used under perl, but you can trigger that event yourself.
1362  
1363 Under JavaScript, this is fired when a seek operation begins
1364  
1365 Example:
1366  
1367 my $video = $doc->querySelector( 'video' );
1368 $video->addEventListener( seeking => sub
1369 {
1370 say( 'Video is seeking a new position.' );
1371 });
1372 my $video = $doc->querySelector( 'video' );
1373 $video->onseeking = sub
1374 {
1375 say( 'Video is seeking a new position.' );
1376 };
1377  
1378 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/seeking_event>
1379  
1380 =head2 stalled
1381  
1382 This is not used under perl, but you can trigger that event yourself.
1383  
1384 Under JavaScript, this is fired when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
1385  
1386 Example:
1387  
1388 my $video = $doc->querySelector('video');
1389  
1390 $video->addEventListener( stalled => sub
1391 {
1392 say( 'Failed to fetch data, but trying.' );
1393 });
1394  
1395 my $video = $doc->querySelector('video');
1396  
1397 $video->onstalled = sub
1398 {
1399 say( 'Failed to fetch data, but trying.' );
1400 };
1401  
1402 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/stalled_event>
1403  
1404 =head2 suspend
1405  
1406 This is not used under perl, but you can trigger that event yourself.
1407  
1408 Under JavaScript, this is fired when the media data loading has been suspended.
1409  
1410 Example:
1411  
1412 my $video = $doc->querySelector('video');
1413  
1414 $video->addEventListener( suspend => sub
1415 {
1416 say( 'Data loading has been suspended.' );
1417 });
1418  
1419 my $video = $doc->querySelector( 'video' );
1420  
1421 $video->onsuspend = sub
1422 {
1423 say( 'Data loading has been suspended.' );
1424 };
1425  
1426 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/suspend_event>
1427  
1428 =head2 timeupdate
1429  
1430 Fired when the time indicated by the L</currentTime> property has been updated.
1431  
1432 Example:
1433  
1434 my $video = $doc->querySelector('video');
1435  
1436 $video->addEventListener( timeupdate => sub
1437 {
1438 say( 'The currentTime attribute has been updated. Again.' );
1439 });
1440  
1441 my $video = $doc->querySelector('video');
1442  
1443 $video->ontimeupdate = sub
1444 {
1445 say( 'The currentTime attribute has been updated. Again.' );
1446 };
1447  
1448 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/timeupdate_event>
1449  
1450 =head2 volumechange
1451  
1452 Fired when the volume has changed, i.e. when the value for the L</volume> property has changed.
1453  
1454 Example:
1455  
1456 my $video = $doc->querySelector('video');
1457  
1458 $video->addEventListener( volumechange => sub
1459 {
1460 say( 'The volume changed.' );
1461 });
1462  
1463 my $video = $doc->querySelector('video');
1464 $video->onvolumechange = sub
1465 {
1466 say( 'The volume changed.' );
1467 };
1468  
1469 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/volumechange_event>
1470  
1471 =head2 waiting
1472  
1473 This is not used under perl, but you can trigger that event yourself.
1474  
1475 Under JavaScript, this is fired when playback has stopped because of a temporary lack of data.
1476  
1477 Example:
1478  
1479 my $video = $doc->querySelector('video');
1480  
1481 $video->addEventListener( waiting => sub
1482 {
1483 say( 'Video is waiting for more data.' );
1484 });
1485  
1486 my $video = $doc->querySelector('video');
1487 $video->onwaiting = sub
1488 {
1489 say( 'Video is waiting for more data.' );
1490 };
1491  
1492 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/waiting_event>
1493  
1494 =head1 EVENT HANDLERS
1495  
1496 =head2 onencrypted
1497  
1498 Sets the event handler called when the media is encrypted.
1499  
1500 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/onencrypted>
1501  
1502 =head2 onwaitingforkey
1503  
1504 Sets the event handler called when playback is blocked while waiting for an encryption key.
1505  
1506 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/onwaitingforkey>
1507  
1508 =head1 CONSTANTS
1509  
1510 The following constants can be exported and used, such as:
1511  
1512 use HTML::Object::DOM::Element::Media qw( :all );
1513 # or directly from HTML::Object::DOM
1514 use HTML::Object::DOM qw( :media );
1515  
1516 =over 4
1517  
1518 =item NETWORK_EMPTY (0)
1519  
1520 There is no data yet. Also, readyState is HAVE_NOTHING.
1521  
1522 =item NETWORK_IDLE (1)
1523  
1524 L<Media element|HTML::Object::DOM::Element::Media> is active and has selected a resource, but is not using the network.
1525  
1526 =item NETWORK_LOADING (2)
1527  
1528 The browser is downloading L<HTML::Object::DOM::Element::Media> data.
1529  
1530 =item NETWORK_NO_SOURCE (3)
1531  
1532 No L<HTML::Object::DOM::Element::Media> src found.
1533  
1534 =back
1535  
1536 =head1 AUTHOR
1537  
1538 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
1539  
1540 =head1 SEE ALSO
1541  
1542 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement>, L<Mozilla documentation on audio element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio>, L<Mozilla documentation on video element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video>, L<W3C specifications|https://html.spec.whatwg.org/multipage/media.html>
1543  
1544 =head1 COPYRIGHT & LICENSE
1545  
1546 Copyright(c) 2021 DEGUEST Pte. Ltd.
1547  
1548 All rights reserved
1549  
1550 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1551  
1552 =cut
« blib/lib/HTML/Object/XPath/Boolean.pm ↑ Summary lib/HTML/Object/DOM/Element/IFrame.pm »