Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^4: awanti Perl not playing video with vlc plugin

by Anonymous Monk
on Dec 29, 2015 at 20:18 UTC ( #1151407=note: print w/replies, xml ) Need Help??


in reply to Re^3: awanti Perl not playing video with vlc plugin
in thread Perl not playing video with vlc plugin

static html page has no header..

every time you make a http request headers are sent before the content

a static html page on your local harddrive does not test how http works

Anyway, this works for me

#!/usr/bin/perl -- use CGI::Carp qw/ fatalsToBrowser /; use strict; use warnings; use IO::Handle; use CGI; use autodie qw/ open /; Main( @ARGV ); exit( 0 ); sub Main { STDOUT->autoflush; my $cgi = CGI->new; PrintHeadersAndContent ( $cgi ); } sub PrintHeadersAndContent { use autodie qw/ open /; my( $cgi ) = @_; my $filename = q{/harcoded/path/to/one/file}; open my($fh),'<:raw', $filename; ## or die by autodie my $attachment = 'Juice.mp4'; my $size = -s $filename; my $begin = 0; my $end = $size; if( my $httprange = $cgi->http('range') ){ if( $httprange =~ /bytes=(\d+)(?:-(\d*))?/i ){ my $from = $1; my $to = $2; $from and $begin = $from; $to and $end = $to; } } my $range = "$begin-$size/$size"; print $cgi->header( -nph => 1, -type => "application/x-vlc-plugin", -attachment => $attachment, -Accept_Ranges => 'bytes', -Content_Length => $size, -Content_Range => $range, -Content_Transfer_Encoding => 'binary', ); my $numbytes = 1024*16;; seek $fh, $begin, 0; my $curr = $begin; while(not eof $fh) { my $readed = read $fh, my($data) , $numbytes; print STDOUT $data; $readed == $numbytes or warn "Only read($readed) but wanted($numbytes): $! ## $ +^E "; $curr += $numbytes; if( $curr + $numbytes > $size ){ $numbytes = $size - $curr; } } close $fh; } __END__

Replies are listed 'Best First'.
Re^5: awanti Perl not playing video with vlc plugin
by awanti (Acolyte) on Dec 30, 2015 at 03:09 UTC
    Not working.. it is giving error like
    [Wed Dec 30 08:35:48.905876 2015] [cgid:error] [pid 1149:tid 303456544 +0] [client 127.0.0.1:51456] malformed header from script 'download.cg +i': Bad header: HTTP/1.1 200 OK
    i think the problem is with http headers.
        Well the http headers are in correct form only.. But can you please tell me why this error again?..and there is nothing wrong in syntax also...
      Whats the message in log before that one?
        In the error log for your code is writing like this
        [Wed Dec 30 10:51:28 2015] [error] [client 127.0.0.1] malformed header + from script. Bad header=HTTP/1.1 200 OK: download.cgi

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1151407]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-08-13 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?