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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/lib/Frey/Web/Flowplayer.pm revision 823 by dpavlin, Fri Dec 12 19:34:42 2008 UTC trunk/lib/Frey/Web/FLVPlayer.pm revision 883 by dpavlin, Tue Dec 23 21:00:14 2008 UTC
# Line 1  Line 1 
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    
# Line 12  with 'Frey::Web'; Line 12  with 'Frey::Web';
12  #with 'Frey::Storage';  #with 'Frey::Storage';
13  with 'Frey::File::FLV';  with 'Frey::File::FLV';
14    
15  has path => (  use Video::Subtitle::SRT;
16    
17    has title => (
18          is => 'rw',          is => 'rw',
19          isa => 'Str',          isa => 'Str',
         required => 1,  
         default => 'var/flv/strix-2005-2008-codeswarm.flv',  
20  );  );
21    
22  has flowplayer_js => (  has path => (
23          is => 'rw',          is => 'rw',
24          isa => 'Str',          isa => 'Str',
25          required => 1,          required => 1,
26          default => 'http://static.flowplayer.org/js/flowplayer-3.0.1.min.js',          default => 'var/flv/codeswarm.flv',
27  );  );
28    
29  has flowplayer_swf => (  has player_swf => (
30          is => 'rw',          is => 'rw',
31          isa => 'Str',          isa => 'Str',
32          required => 1,          required => 1,
33          default => 'http://static.flowplayer.org/swf/flowplayer-3.0.1.swf',          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 {
# Line 41  sub as_markup { Line 48  sub as_markup {
48    
49          my $url = "http://localhost:3000/$path"; # FIXME          my $url = "http://localhost:3000/$path"; # FIXME
50    
51          $self->add_js( $self->flowplayer_js );          my $swf = $self->player_swf;
         my $swf = $self->flowplayer_swf;  
52    
53          my %info = $self->flv_info;          my %info = $self->flv_info;
54          warn "# info ", $self->dump( \%info );          warn "# info ", $self->dump( \%info );
55    
56          my $width  = $info{meta_width};          my $width  = $info{video_width};
57          my $height = $info{meta_height};          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            $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 = '&nbsp;';
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  <!--                    <param name="AllowScriptAccess" value="always"> <!-- domain -->
111     Setup player with standard HTML syntax                  </object>
112        * movie file is specified in "href" attribute                    <div id="subtitle">&nbsp;<small>no subtitle</small></div>
113        * player dimensions are defined with CSS                    <div style="border: 1px slashed #888;">
114  -->                  <input type="button" onclick="document.getElementById('flvplayer').SetVariable('player:jsPlay', '');" value="Play" >
115  <a                    <input type="button" onclick="alert(document.getElementById('flvplayer').GetVariable('method:getPosition'))" value="getPosition" >
116      href="$url"                  </div>
117      style="display:block;width:${width}px;height:${height}px;"                    $subtitles
118      id="player">                  <div>$info</div>
 </a>  
   
 <!-- this script block will install Flowplayer inside previous anchor tag -->  
 <script language="JavaScript">  
     flowplayer("player", "$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;

Legend:
Removed from v.823  
changed lines
  Added in v.883

  ViewVC Help
Powered by ViewVC 1.1.26