/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 855 - (hide annotations)
Mon Dec 15 21:40:28 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2151 byte(s)
- use width and height from video_ instead of meta_ which might be missing
- add autoload to have smooth playback
- show file info
1 dpavlin 844 package Frey::Web::FLVPlayer;
2 dpavlin 809 use Moose;
3    
4     =head1 SEE ALSO
5    
6 dpavlin 846 L<http://flv-player.net/>
7 dpavlin 809
8     =cut
9    
10     extends 'Frey';
11     with 'Frey::Web';
12     #with 'Frey::Storage';
13 dpavlin 823 with 'Frey::File::FLV';
14 dpavlin 809
15 dpavlin 850 use Video::Subtitle::SRT;
16    
17 dpavlin 847 has title => (
18     is => 'rw',
19     isa => 'Str',
20     );
21    
22 dpavlin 823 has path => (
23 dpavlin 809 is => 'rw',
24     isa => 'Str',
25     required => 1,
26 dpavlin 825 default => 'var/flv/codeswarm.flv',
27 dpavlin 809 );
28    
29 dpavlin 846 has player_swf => (
30 dpavlin 814 is => 'rw',
31     isa => 'Str',
32     required => 1,
33 dpavlin 846 default => 'http://flv-player.net/medias/player_flv_maxi.swf',
34 dpavlin 814 );
35    
36 dpavlin 850 has FlashVars => (
37     is => 'rw',
38     isa => 'ArrayRef[Str]',
39     default => sub { [] },
40     lazy => 1, # hide it from user
41     );
42    
43 dpavlin 809 sub as_markup {
44     my ($self) = @_;
45    
46 dpavlin 823 my $path = $self->path;
47     die "can't find $path" unless -e $path;
48 dpavlin 809
49 dpavlin 823 my $url = "http://localhost:3000/$path"; # FIXME
50 dpavlin 814
51 dpavlin 846 my $swf = $self->player_swf;
52 dpavlin 814
53 dpavlin 823 my %info = $self->flv_info;
54     warn "# info ", $self->dump( \%info );
55    
56 dpavlin 855 my $width = $info{video_width};
57     my $height = $info{video_height};
58 dpavlin 823
59 dpavlin 855 $self->FlashVars( [ "flv=$url", "autoload=1", "showtime=1" ] );
60 dpavlin 847
61 dpavlin 855 push @{ $self->FlashVars }, 'showvolume=1' if $info{audio_count} > 0;
62    
63 dpavlin 850 my $subtitles = $self->subtitles_as_markup;
64 dpavlin 847
65 dpavlin 850 push @{ $self->FlashVars }, 'title=' . $self->title if $self->title;
66 dpavlin 847
67 dpavlin 850 my $FlashVars = join('&amp;', @{ $self->FlashVars });
68 dpavlin 847
69 dpavlin 855 my $info = $self->dropdown( $self->path, \%info );
70 dpavlin 809 qq|
71 dpavlin 846 <object type="application/x-shockwave-flash" data="$swf" width="$width" height="$height">
72     <param name="movie" value="$swf" />
73 dpavlin 847 <param name="FlashVars" value="$FlashVars" />
74 dpavlin 846 </object>
75 dpavlin 855 <div>$info</div>
76 dpavlin 850 $subtitles
77 dpavlin 809 |;
78    
79     }
80    
81 dpavlin 850 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 dpavlin 809 1;

  ViewVC Help
Powered by ViewVC 1.1.26