/[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 888 - (hide annotations)
Wed Dec 24 20:05:14 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 4167 byte(s)
checkout upstream, patch and compile modified flv-player
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     with 'Frey::Web';
26     #with 'Frey::Storage';
27 dpavlin 823 with 'Frey::File::FLV';
28 dpavlin 809
29 dpavlin 850 use Video::Subtitle::SRT;
30    
31 dpavlin 847 has title => (
32     is => 'rw',
33     isa => 'Str',
34     );
35    
36 dpavlin 823 has path => (
37 dpavlin 809 is => 'rw',
38     isa => 'Str',
39     required => 1,
40 dpavlin 825 default => 'var/flv/codeswarm.flv',
41 dpavlin 809 );
42    
43 dpavlin 846 has player_swf => (
44 dpavlin 814 is => 'rw',
45     isa => 'Str',
46     required => 1,
47 dpavlin 846 default => 'http://flv-player.net/medias/player_flv_maxi.swf',
48 dpavlin 814 );
49    
50 dpavlin 850 has FlashVars => (
51     is => 'rw',
52     isa => 'ArrayRef[Str]',
53     default => sub { [] },
54     lazy => 1, # hide it from user
55     );
56    
57 dpavlin 809 sub as_markup {
58     my ($self) = @_;
59    
60 dpavlin 823 my $path = $self->path;
61     die "can't find $path" unless -e $path;
62 dpavlin 809
63 dpavlin 823 my $url = "http://localhost:3000/$path"; # FIXME
64 dpavlin 814
65 dpavlin 846 my $swf = $self->player_swf;
66 dpavlin 814
67 dpavlin 823 my %info = $self->flv_info;
68     warn "# info ", $self->dump( \%info );
69    
70 dpavlin 855 my $width = $info{video_width};
71     my $height = $info{video_height};
72 dpavlin 823
73 dpavlin 855 $self->FlashVars( [ "flv=$url", "autoload=1", "showtime=1" ] );
74 dpavlin 847
75 dpavlin 855 push @{ $self->FlashVars }, 'showvolume=1' if $info{audio_count} > 0;
76    
77 dpavlin 850 my $subtitles = $self->subtitles_as_markup;
78 dpavlin 847
79 dpavlin 850 push @{ $self->FlashVars }, 'title=' . $self->title if $self->title;
80 dpavlin 847
81 dpavlin 850 my $FlashVars = join('&amp;', @{ $self->FlashVars });
82 dpavlin 847
83 dpavlin 883 $self->add_css(q|
84     #subtitle small {
85     color: #888;
86     }
87     |);
88    
89     $self->add_js(q|
90     var _subtitle_active = -1;
91    
92     function flv_subtitle(subtitle,nr) {
93    
94     // remove current subtitle
95     if ( _subtitle_active >= 0 ) {
96     document.getElementById('subtitle-' + _subtitle_active).style.background = '#fff';
97     }
98    
99     var s = document.getElementById('subtitle');
100     if ( subtitle.message ) {
101     s.innerHTML = ''
102     + subtitle.message
103     + ' <small>'
104     + nr + ' ' +
105     + subtitle.timeStart
106     + ' ... '
107     + subtitle.timeEnd
108     + '</small>'
109     ;
110     document.getElementById('subtitle-' + nr).style.background = '#ff0';
111     _subtitle_active = nr;
112     } else {
113     s.innerHTML = '&nbsp;';
114     _subtitle_active = -1;
115     }
116     }
117     |);
118    
119 dpavlin 855 my $info = $self->dropdown( $self->path, \%info );
120 dpavlin 809 qq|
121 dpavlin 880 <object id="flvplayer" type="application/x-shockwave-flash" data="$swf" width="$width" height="$height">
122 dpavlin 846 <param name="movie" value="$swf" />
123 dpavlin 847 <param name="FlashVars" value="$FlashVars" />
124 dpavlin 883 <param name="AllowScriptAccess" value="always"> <!-- domain -->
125 dpavlin 846 </object>
126 dpavlin 883 <div id="subtitle">&nbsp;<small>no subtitle</small></div>
127     <div style="border: 1px slashed #888;">
128     <input type="button" onclick="document.getElementById('flvplayer').SetVariable('player:jsPlay', '');" value="Play" >
129     <input type="button" onclick="alert(document.getElementById('flvplayer').GetVariable('method:getPosition'))" value="getPosition" >
130     </div>
131     $subtitles
132 dpavlin 855 <div>$info</div>
133 dpavlin 809 |;
134    
135     }
136    
137 dpavlin 850 sub subtitles_as_markup {
138     my ( $self ) = @_;
139    
140     my $srt = $self->path;
141     $srt =~ s{\.flv}{.srt};
142     my $html = '';
143    
144     if ( -e $srt ) {
145     push @{ $self->FlashVars }, 'srt=1';
146    
147 dpavlin 883 my $nr = 0;
148    
149     $self->add_js(qq|
150     function play_from(position) {
151     var p = document.getElementById('flvplayer');
152     p.SetVariable('player:jsSetPosition', position);
153     p.SetVariable('player:jsPlay','');
154     return false;
155     }
156     |);
157    
158     sub jump_to {
159     my $t = shift;
160     my $position =
161     $1 * 60 * 60 +
162     $2 * 60 +
163     $3
164     if ( $t =~ m/(\d\d):(\d\d):(\d\d),\d/ );
165     ;
166    
167     qq|<a href="#$t" onclick="return play_from($position);">$t</a>|;
168     }
169    
170 dpavlin 850 my $callback = sub {
171     my $data = shift;
172 dpavlin 883 my $s = jump_to( $data->{start_time} );
173     my $e = jump_to( $data->{end_time} );
174     $html .= qq|<tr id="subtitle-$nr"><td>$s</td><td>$e</td><td> $data->{text} </td></tr>|;
175     $nr++;
176 dpavlin 850 };
177    
178     my $subtitle = Video::Subtitle::SRT->new($callback);
179     $subtitle->debug(1);
180     $subtitle->parse( $srt );
181    
182     $html = qq|
183     <table class="html">
184     <thead>
185     <tr><th>from</th><th>to</th><th>subtitle</th></tr>
186     </thead>
187     <tbody>
188     $html
189     <tbody>
190     </table>
191     |;
192     }
193    
194     return $html;
195     }
196    
197 dpavlin 809 1;

  ViewVC Help
Powered by ViewVC 1.1.26