/[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 880 by dpavlin, Fri Dec 19 14:01:01 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            my $info = $self->dropdown( $self->path, \%info );
70          qq|          qq|
71  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                  <object id="flvplayer" type="application/x-shockwave-flash" data="$swf" width="$width" height="$height">
72      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">                  <param name="movie" value="$swf" />
73                    <param name="FlashVars" value="$FlashVars" />
74  <!--                    </object>
75     Setup player with standard HTML syntax                  <div>$info</div>
76        * movie file is specified in "href" attribute                    $subtitles
       * player dimensions are defined with CSS    
 -->  
 <a    
     href="$url"  
     style="display:block;width:${width}px;height:${height}px;"    
     id="player">  
 </a>  
   
 <!-- this script block will install Flowplayer inside previous anchor tag -->  
 <script language="JavaScript">  
     flowplayer("player", "$swf");  
 </script>  
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;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26