/[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 880 - (show annotations)
Fri Dec 19 14:01:01 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 2166 byte(s)
 r972@eeepy:  dpavlin | 2008-12-19 15:00:32 +0100
 added id to flash object

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{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('&amp;', @{ $self->FlashVars });
68
69 my $info = $self->dropdown( $self->path, \%info );
70 qq|
71 <object id="flvplayer" type="application/x-shockwave-flash" data="$swf" width="$width" height="$height">
72 <param name="movie" value="$swf" />
73 <param name="FlashVars" value="$FlashVars" />
74 </object>
75 <div>$info</div>
76 $subtitles
77 |;
78
79 }
80
81 sub subtitles_as_markup {
82 my ( $self ) = @_;
83
84 my $srt = $self->path;
85 $srt =~ s{\.flv}{.srt};
86 my $html = '';
87
88 if ( -e $srt ) {
89 push @{ $self->FlashVars }, 'srt=1';
90
91 my $callback = sub {
92 my $data = shift;
93 $html .= qq|<tr><td> $data->{start_time} </td><td> $data->{end_time} </td><td> $data->{text} </td></tr>|;
94 };
95
96 my $subtitle = Video::Subtitle::SRT->new($callback);
97 $subtitle->debug(1);
98 $subtitle->parse( $srt );
99
100 $html = qq|
101 <table class="html">
102 <thead>
103 <tr><th>from</th><th>to</th><th>subtitle</th></tr>
104 </thead>
105 <tbody>
106 $html
107 <tbody>
108 </table>
109 |;
110 }
111
112 return $html;
113 }
114
115 1;

  ViewVC Help
Powered by ViewVC 1.1.26