1 |
package Frey::Web::Flowplayer; |
package Frey::Web::FLVPlayer; |
2 |
use Moose; |
use Moose; |
3 |
|
|
4 |
=head1 SEE ALSO |
=head1 SEE ALSO |
5 |
|
|
6 |
L<http://flowplayer.org/documentation/installation.html> |
L<http://flv-player.net/> |
7 |
|
|
8 |
=cut |
=cut |
9 |
|
|
10 |
extends 'Frey'; |
extends 'Frey'; |
11 |
with 'Frey::Web'; |
with 'Frey::Web'; |
12 |
#with 'Frey::Storage'; |
#with 'Frey::Storage'; |
13 |
|
with 'Frey::File::FLV'; |
14 |
|
|
15 |
has skeleton => ( |
use Video::Subtitle::SRT; |
16 |
|
|
17 |
|
has title => ( |
18 |
|
is => 'rw', |
19 |
|
isa => 'Str', |
20 |
|
); |
21 |
|
|
22 |
|
has path => ( |
23 |
|
is => 'rw', |
24 |
|
isa => 'Str', |
25 |
|
required => 1, |
26 |
|
default => 'var/flv/codeswarm.flv', |
27 |
|
); |
28 |
|
|
29 |
|
has player_swf => ( |
30 |
is => 'rw', |
is => 'rw', |
31 |
isa => 'Str', |
isa => 'Str', |
32 |
required => 1, |
required => 1, |
33 |
default => 'skeleton', |
default => 'http://flv-player.net/medias/player_flv_maxi.swf', |
34 |
|
); |
35 |
|
|
36 |
|
has FlashVars => ( |
37 |
|
is => 'rw', |
38 |
|
isa => 'ArrayRef[Str]', |
39 |
|
default => sub { [] }, |
40 |
|
lazy => 1, # hide it from user |
41 |
); |
); |
42 |
|
|
43 |
sub as_markup { |
sub as_markup { |
44 |
my ($self) = @_; |
my ($self) = @_; |
45 |
|
|
46 |
warn $self->skeleton; |
my $path = $self->path; |
47 |
|
die "can't find $path" unless -e $path; |
48 |
|
|
49 |
|
my $url = "http://localhost:3000/$path"; # FIXME |
50 |
|
|
51 |
|
my $swf = $self->player_swf; |
52 |
|
|
53 |
|
my %info = $self->flv_info; |
54 |
|
warn "# info ", $self->dump( \%info ); |
55 |
|
|
56 |
|
my $width = $info{video_width}; |
57 |
|
my $height = $info{video_height}; |
58 |
|
|
59 |
|
$self->FlashVars( [ "flv=$url", "autoload=1", "showtime=1" ] ); |
60 |
|
|
61 |
|
push @{ $self->FlashVars }, 'showvolume=1' if $info{audio_count} > 0; |
62 |
|
|
63 |
|
my $subtitles = $self->subtitles_as_markup; |
64 |
|
|
65 |
|
push @{ $self->FlashVars }, 'title=' . $self->title if $self->title; |
66 |
|
|
67 |
|
my $FlashVars = join('&', @{ $self->FlashVars }); |
68 |
|
|
69 |
|
$self->add_css(q| |
70 |
|
#subtitle small { |
71 |
|
color: #888; |
72 |
|
} |
73 |
|
|); |
74 |
|
|
75 |
|
$self->add_js(q| |
76 |
|
var _subtitle_active = -1; |
77 |
|
|
78 |
|
function flv_subtitle(subtitle,nr) { |
79 |
|
|
80 |
|
// remove current subtitle |
81 |
|
if ( _subtitle_active >= 0 ) { |
82 |
|
document.getElementById('subtitle-' + _subtitle_active).style.background = '#fff'; |
83 |
|
} |
84 |
|
|
85 |
|
var s = document.getElementById('subtitle'); |
86 |
|
if ( subtitle.message ) { |
87 |
|
s.innerHTML = '' |
88 |
|
+ subtitle.message |
89 |
|
+ ' <small>' |
90 |
|
+ nr + ' ' + |
91 |
|
+ subtitle.timeStart |
92 |
|
+ ' ... ' |
93 |
|
+ subtitle.timeEnd |
94 |
|
+ '</small>' |
95 |
|
; |
96 |
|
document.getElementById('subtitle-' + nr).style.background = '#ff0'; |
97 |
|
_subtitle_active = nr; |
98 |
|
} else { |
99 |
|
s.innerHTML = ' '; |
100 |
|
_subtitle_active = -1; |
101 |
|
} |
102 |
|
} |
103 |
|
|); |
104 |
|
|
105 |
|
my $info = $self->dropdown( $self->path, \%info ); |
106 |
qq| |
qq| |
107 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
<object id="flvplayer" type="application/x-shockwave-flash" data="$swf" width="$width" height="$height"> |
108 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<param name="movie" value="$swf" /> |
109 |
|
<param name="FlashVars" value="$FlashVars" /> |
110 |
<!-- include the only required JavaScript file --> |
<param name="AllowScriptAccess" value="always"> <!-- domain --> |
111 |
<script src="http://static.flowplayer.org/js/flowplayer-3.0.1.min.js"></script> |
</object> |
112 |
|
<div id="subtitle"> <small>no subtitle</small></div> |
113 |
<!-- |
<div style="border: 1px slashed #888;"> |
114 |
Setup player with standard HTML syntax |
<input type="button" onclick="document.getElementById('flvplayer').SetVariable('player:jsPlay', '');" value="Play" > |
115 |
* movie file is specified in "href" attribute |
<input type="button" onclick="alert(document.getElementById('flvplayer').GetVariable('method:getPosition'))" value="getPosition" > |
116 |
* player dimensions are defined with CSS |
</div> |
117 |
--> |
$subtitles |
118 |
<a |
<div>$info</div> |
|
href="http://blip.tv/file/get/KimAronson-TwentySeconds4461.flv" |
|
|
style="display:block;width:425px;height:300px;" |
|
|
id="player"> |
|
|
</a> |
|
|
|
|
|
<!-- this script block will install Flowplayer inside previous anchor tag --> |
|
|
<script language="JavaScript"> |
|
|
flowplayer("player", "http://static.flowplayer.org/swf/flowplayer-3.0.1.swf"); |
|
|
</script> |
|
119 |
|; |
|; |
120 |
|
|
121 |
} |
} |
122 |
|
|
123 |
|
sub subtitles_as_markup { |
124 |
|
my ( $self ) = @_; |
125 |
|
|
126 |
|
my $srt = $self->path; |
127 |
|
$srt =~ s{\.flv}{.srt}; |
128 |
|
my $html = ''; |
129 |
|
|
130 |
|
if ( -e $srt ) { |
131 |
|
push @{ $self->FlashVars }, 'srt=1'; |
132 |
|
|
133 |
|
my $nr = 0; |
134 |
|
|
135 |
|
$self->add_js(qq| |
136 |
|
function play_from(position) { |
137 |
|
var p = document.getElementById('flvplayer'); |
138 |
|
p.SetVariable('player:jsSetPosition', position); |
139 |
|
p.SetVariable('player:jsPlay',''); |
140 |
|
return false; |
141 |
|
} |
142 |
|
|); |
143 |
|
|
144 |
|
sub jump_to { |
145 |
|
my $t = shift; |
146 |
|
my $position = |
147 |
|
$1 * 60 * 60 + |
148 |
|
$2 * 60 + |
149 |
|
$3 |
150 |
|
if ( $t =~ m/(\d\d):(\d\d):(\d\d),\d/ ); |
151 |
|
; |
152 |
|
|
153 |
|
qq|<a href="#$t" onclick="return play_from($position);">$t</a>|; |
154 |
|
} |
155 |
|
|
156 |
|
my $callback = sub { |
157 |
|
my $data = shift; |
158 |
|
my $s = jump_to( $data->{start_time} ); |
159 |
|
my $e = jump_to( $data->{end_time} ); |
160 |
|
$html .= qq|<tr id="subtitle-$nr"><td>$s</td><td>$e</td><td> $data->{text} </td></tr>|; |
161 |
|
$nr++; |
162 |
|
}; |
163 |
|
|
164 |
|
my $subtitle = Video::Subtitle::SRT->new($callback); |
165 |
|
$subtitle->debug(1); |
166 |
|
$subtitle->parse( $srt ); |
167 |
|
|
168 |
|
$html = qq| |
169 |
|
<table class="html"> |
170 |
|
<thead> |
171 |
|
<tr><th>from</th><th>to</th><th>subtitle</th></tr> |
172 |
|
</thead> |
173 |
|
<tbody> |
174 |
|
$html |
175 |
|
<tbody> |
176 |
|
</table> |
177 |
|
|; |
178 |
|
} |
179 |
|
|
180 |
|
return $html; |
181 |
|
} |
182 |
|
|
183 |
1; |
1; |