1 |
package Frey::Web::FLVPlayer; |
2 |
use Moose; |
3 |
|
4 |
=head1 SEE ALSO |
5 |
|
6 |
L<http://flv-player.net/> |
7 |
|
8 |
=cut |
9 |
|
10 |
extends 'Frey'; |
11 |
with 'Frey::Web'; |
12 |
#with 'Frey::Storage'; |
13 |
with 'Frey::File::FLV'; |
14 |
|
15 |
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', |
31 |
isa => 'Str', |
32 |
required => 1, |
33 |
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 { |
44 |
my ($self) = @_; |
45 |
|
46 |
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{meta_width}; |
57 |
my $height = $info{meta_height}; |
58 |
|
59 |
push @{ $self->FlashVars }, "flv=$url"; |
60 |
|
61 |
my $subtitles = $self->subtitles_as_markup; |
62 |
|
63 |
push @{ $self->FlashVars }, 'title=' . $self->title if $self->title; |
64 |
|
65 |
my $FlashVars = join('&', @{ $self->FlashVars }); |
66 |
|
67 |
qq| |
68 |
<object type="application/x-shockwave-flash" data="$swf" width="$width" height="$height"> |
69 |
<param name="movie" value="$swf" /> |
70 |
<param name="FlashVars" value="$FlashVars" /> |
71 |
</object> |
72 |
$subtitles |
73 |
|; |
74 |
|
75 |
} |
76 |
|
77 |
sub subtitles_as_markup { |
78 |
my ( $self ) = @_; |
79 |
|
80 |
my $srt = $self->path; |
81 |
$srt =~ s{\.flv}{.srt}; |
82 |
my $html = ''; |
83 |
|
84 |
if ( -e $srt ) { |
85 |
push @{ $self->FlashVars }, 'srt=1'; |
86 |
|
87 |
my $callback = sub { |
88 |
my $data = shift; |
89 |
$html .= qq|<tr><td> $data->{start_time} </td><td> $data->{end_time} </td><td> $data->{text} </td></tr>|; |
90 |
}; |
91 |
|
92 |
my $subtitle = Video::Subtitle::SRT->new($callback); |
93 |
$subtitle->debug(1); |
94 |
$subtitle->parse( $srt ); |
95 |
|
96 |
$html = qq| |
97 |
<table class="html"> |
98 |
<thead> |
99 |
<tr><th>from</th><th>to</th><th>subtitle</th></tr> |
100 |
</thead> |
101 |
<tbody> |
102 |
$html |
103 |
<tbody> |
104 |
</table> |
105 |
|; |
106 |
} |
107 |
|
108 |
return $html; |
109 |
} |
110 |
|
111 |
1; |