--- trunk/lib/Frey/Web/FLVPlayer.pm 2008/12/15 18:57:04 847 +++ trunk/lib/Frey/Web/FLVPlayer.pm 2008/12/15 19:41:35 850 @@ -12,6 +12,8 @@ #with 'Frey::Storage'; with 'Frey::File::FLV'; +use Video::Subtitle::SRT; + has title => ( is => 'rw', isa => 'Str', @@ -31,6 +33,13 @@ default => 'http://flv-player.net/medias/player_flv_maxi.swf', ); +has FlashVars => ( + is => 'rw', + isa => 'ArrayRef[Str]', + default => sub { [] }, + lazy => 1, # hide it from user +); + sub as_markup { my ($self) = @_; @@ -47,25 +56,56 @@ my $width = $info{meta_width}; my $height = $info{meta_height}; - my @var = ( "flv=$url" ); + push @{ $self->FlashVars }, "flv=$url"; - my $srt = $path; - $srt =~ s{\.flv}{.srt}; - if ( -e $srt ) { - push @var, "srt=1"; - } + my $subtitles = $self->subtitles_as_markup; - push @var, 'title=' . $self->title if $self->title; + push @{ $self->FlashVars }, 'title=' . $self->title if $self->title; - my $FlashVars = join('&', @var); + my $FlashVars = join('&', @{ $self->FlashVars }); qq| + $subtitles |; } +sub subtitles_as_markup { + my ( $self ) = @_; + + my $srt = $self->path; + $srt =~ s{\.flv}{.srt}; + my $html = ''; + + if ( -e $srt ) { + push @{ $self->FlashVars }, 'srt=1'; + + my $callback = sub { + my $data = shift; + $html .= qq| $data->{start_time} $data->{end_time} $data->{text} |; + }; + + my $subtitle = Video::Subtitle::SRT->new($callback); + $subtitle->debug(1); + $subtitle->parse( $srt ); + + $html = qq| + + + + + + $html + +
fromtosubtitle
+ |; + } + + return $html; +} + 1;