/[Frey]/trunk/lib/Frey/Web/FLVPlayer.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/Web/FLVPlayer.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1133 - (show annotations)
Tue Jun 30 15:10:55 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 4185 byte(s)
make classes immutable and remove moose droppings to make Perl::Critic::Moose happy
1 package Frey::Web::FLVPlayer;
2 use Moose;
3
4 =head1 SCRIPTS
5
6 =head2 bin/flvplayer-checkout.sh
7
8 Checkout source code and install required tools to compile modified player
9
10 =head2 bin/flvplayer-build.sh
11
12 patch and build modified C<player_flv_maxi.swf> player
13
14 =head2 bin/flvplayer-diff.sh
15
16 generate C<patch/flvplayer.diff> diff of local changes
17
18 =head1 SEE ALSO
19
20 L<http://flv-player.net/>
21
22 =cut
23
24 extends 'Frey';
25 with 'Frey::Web', 'Frey::File::FLV';
26
27 use Video::Subtitle::SRT;
28
29 has title => (
30 is => 'rw',
31 isa => 'Str',
32 );
33
34 has path => (
35 is => 'rw',
36 isa => 'Str',
37 required => 1,
38 default => 'var/flv/codeswarm.flv',
39 );
40
41 has player_swf => (
42 is => 'rw',
43 isa => 'Str',
44 required => 1,
45 default => 'http://flv-player.net/medias/player_flv_maxi.swf',
46 );
47
48 has FlashVars => (
49 is => 'rw',
50 isa => 'ArrayRef[Str]',
51 default => sub { [] },
52 lazy => 1, # hide it from user
53 );
54
55 sub as_markup {
56 my ($self) = @_;
57
58 my $path = $self->path;
59 die "can't find $path" unless -e $path;
60
61 my $url = "http://localhost:3000/$path"; # FIXME
62
63 my $swf = $self->player_swf;
64
65 my %info = $self->flv_info;
66 warn "# info ", $self->dump( \%info );
67
68 my $width = $info{video_width};
69 my $height = $info{video_height};
70
71 $self->FlashVars( [ "flv=$url", "autoload=1", "showtime=1" ] );
72
73 push @{ $self->FlashVars }, 'showvolume=1' if $info{audio_count} > 0;
74
75 my $subtitles = $self->subtitles_as_markup;
76
77 push @{ $self->FlashVars }, 'title=' . $self->title if $self->title;
78
79 my $FlashVars = join('&amp;', @{ $self->FlashVars });
80
81 $self->add_css(q|
82 #subtitle small {
83 color: #888;
84 }
85 |);
86
87 $self->add_js(q|
88 var _subtitle_active = -1;
89
90 function flv_subtitle(subtitle,nr) {
91
92 // remove current subtitle
93 if ( _subtitle_active >= 0 ) {
94 document.getElementById('subtitle-' + _subtitle_active).style.background = '#fff';
95 }
96
97 var s = document.getElementById('subtitle');
98 if ( subtitle.message ) {
99 s.innerHTML = ''
100 + subtitle.message
101 + ' <small>'
102 + nr + ' ' +
103 + subtitle.timeStart
104 + ' ... '
105 + subtitle.timeEnd
106 + '</small>'
107 ;
108 document.getElementById('subtitle-' + nr).style.background = '#ff0';
109 _subtitle_active = nr;
110 } else {
111 s.innerHTML = '&nbsp;';
112 _subtitle_active = -1;
113 }
114 }
115 |);
116
117 my $info = $self->dropdown( $self->path, \%info );
118 qq|
119 <object id="flvplayer" type="application/x-shockwave-flash" data="$swf" width="$width" height="$height">
120 <param name="movie" value="$swf" />
121 <param name="FlashVars" value="$FlashVars" />
122 <param name="AllowScriptAccess" value="always"> <!-- domain -->
123 </object>
124 <div id="subtitle">&nbsp;<small>no subtitle</small></div>
125 <div style="border: 1px slashed #888;">
126 <input type="button" onclick="document.getElementById('flvplayer').SetVariable('player:jsPlay', '');" value="Play" >
127 <input type="button" onclick="alert(document.getElementById('flvplayer').GetVariable('method:getPosition'))" value="getPosition" >
128 </div>
129 $subtitles
130 <div>$info</div>
131 |;
132
133 }
134
135 sub subtitles_as_markup {
136 my ( $self ) = @_;
137
138 my $srt = $self->path;
139 $srt =~ s{\.flv}{.srt};
140 my $html = '';
141
142 if ( -e $srt ) {
143 push @{ $self->FlashVars }, 'srt=1';
144
145 my $nr = 0;
146
147 $self->add_js(qq|
148 function play_from(position) {
149 var p = document.getElementById('flvplayer');
150 p.SetVariable('player:jsSetPosition', position);
151 p.SetVariable('player:jsPlay','');
152 return false;
153 }
154 |);
155
156 sub jump_to {
157 my $t = shift;
158 my $position =
159 $1 * 60 * 60 +
160 $2 * 60 +
161 $3
162 if ( $t =~ m/(\d\d):(\d\d):(\d\d),\d/ );
163 ;
164
165 qq|<a href="#$t" onclick="return play_from($position);">$t</a>|;
166 }
167
168 my $callback = sub {
169 my $data = shift;
170 my $s = jump_to( $data->{start_time} );
171 my $e = jump_to( $data->{end_time} );
172 $html .= qq|<tr id="subtitle-$nr"><td>$s</td><td>$e</td><td> $data->{text} </td></tr>|;
173 $nr++;
174 };
175
176 my $subtitle = Video::Subtitle::SRT->new($callback);
177 $subtitle->debug(1);
178 $subtitle->parse( $srt );
179
180 $html = qq|
181 <table class="html">
182 <thead>
183 <tr><th>from</th><th>to</th><th>subtitle</th></tr>
184 </thead>
185 <tbody>
186 $html
187 <tbody>
188 </table>
189 |;
190 }
191
192 return $html;
193 }
194
195 __PACKAGE__->meta->make_immutable;
196 no Moose;
197
198 1;

  ViewVC Help
Powered by ViewVC 1.1.26