1 |
dpavlin |
844 |
package Frey::Web::FLVPlayer; |
2 |
dpavlin |
809 |
use Moose; |
3 |
|
|
|
4 |
dpavlin |
888 |
=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 |
dpavlin |
809 |
=head1 SEE ALSO |
19 |
|
|
|
20 |
dpavlin |
846 |
L<http://flv-player.net/> |
21 |
dpavlin |
809 |
|
22 |
|
|
=cut |
23 |
|
|
|
24 |
|
|
extends 'Frey'; |
25 |
dpavlin |
1133 |
with 'Frey::Web', 'Frey::File::FLV'; |
26 |
dpavlin |
809 |
|
27 |
dpavlin |
850 |
use Video::Subtitle::SRT; |
28 |
|
|
|
29 |
dpavlin |
847 |
has title => ( |
30 |
|
|
is => 'rw', |
31 |
|
|
isa => 'Str', |
32 |
|
|
); |
33 |
|
|
|
34 |
dpavlin |
823 |
has path => ( |
35 |
dpavlin |
809 |
is => 'rw', |
36 |
|
|
isa => 'Str', |
37 |
|
|
required => 1, |
38 |
dpavlin |
825 |
default => 'var/flv/codeswarm.flv', |
39 |
dpavlin |
809 |
); |
40 |
|
|
|
41 |
dpavlin |
846 |
has player_swf => ( |
42 |
dpavlin |
814 |
is => 'rw', |
43 |
|
|
isa => 'Str', |
44 |
|
|
required => 1, |
45 |
dpavlin |
846 |
default => 'http://flv-player.net/medias/player_flv_maxi.swf', |
46 |
dpavlin |
814 |
); |
47 |
|
|
|
48 |
dpavlin |
850 |
has FlashVars => ( |
49 |
|
|
is => 'rw', |
50 |
|
|
isa => 'ArrayRef[Str]', |
51 |
|
|
default => sub { [] }, |
52 |
|
|
lazy => 1, # hide it from user |
53 |
|
|
); |
54 |
|
|
|
55 |
dpavlin |
809 |
sub as_markup { |
56 |
|
|
my ($self) = @_; |
57 |
|
|
|
58 |
dpavlin |
823 |
my $path = $self->path; |
59 |
|
|
die "can't find $path" unless -e $path; |
60 |
dpavlin |
809 |
|
61 |
dpavlin |
823 |
my $url = "http://localhost:3000/$path"; # FIXME |
62 |
dpavlin |
814 |
|
63 |
dpavlin |
846 |
my $swf = $self->player_swf; |
64 |
dpavlin |
814 |
|
65 |
dpavlin |
823 |
my %info = $self->flv_info; |
66 |
|
|
warn "# info ", $self->dump( \%info ); |
67 |
|
|
|
68 |
dpavlin |
855 |
my $width = $info{video_width}; |
69 |
|
|
my $height = $info{video_height}; |
70 |
dpavlin |
823 |
|
71 |
dpavlin |
855 |
$self->FlashVars( [ "flv=$url", "autoload=1", "showtime=1" ] ); |
72 |
dpavlin |
847 |
|
73 |
dpavlin |
855 |
push @{ $self->FlashVars }, 'showvolume=1' if $info{audio_count} > 0; |
74 |
|
|
|
75 |
dpavlin |
850 |
my $subtitles = $self->subtitles_as_markup; |
76 |
dpavlin |
847 |
|
77 |
dpavlin |
850 |
push @{ $self->FlashVars }, 'title=' . $self->title if $self->title; |
78 |
dpavlin |
847 |
|
79 |
dpavlin |
850 |
my $FlashVars = join('&', @{ $self->FlashVars }); |
80 |
dpavlin |
847 |
|
81 |
dpavlin |
883 |
$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 = ' '; |
112 |
|
|
_subtitle_active = -1; |
113 |
|
|
} |
114 |
|
|
} |
115 |
|
|
|); |
116 |
|
|
|
117 |
dpavlin |
855 |
my $info = $self->dropdown( $self->path, \%info ); |
118 |
dpavlin |
809 |
qq| |
119 |
dpavlin |
880 |
<object id="flvplayer" type="application/x-shockwave-flash" data="$swf" width="$width" height="$height"> |
120 |
dpavlin |
846 |
<param name="movie" value="$swf" /> |
121 |
dpavlin |
847 |
<param name="FlashVars" value="$FlashVars" /> |
122 |
dpavlin |
883 |
<param name="AllowScriptAccess" value="always"> <!-- domain --> |
123 |
dpavlin |
846 |
</object> |
124 |
dpavlin |
883 |
<div id="subtitle"> <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 |
dpavlin |
855 |
<div>$info</div> |
131 |
dpavlin |
809 |
|; |
132 |
|
|
|
133 |
|
|
} |
134 |
|
|
|
135 |
dpavlin |
850 |
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 |
dpavlin |
883 |
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 |
dpavlin |
850 |
my $callback = sub { |
169 |
|
|
my $data = shift; |
170 |
dpavlin |
883 |
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 |
dpavlin |
850 |
}; |
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 |
dpavlin |
1133 |
__PACKAGE__->meta->make_immutable; |
196 |
|
|
no Moose; |
197 |
|
|
|
198 |
dpavlin |
809 |
1; |