¡¾ÊÓÆµ²¥·Å¡¿JplayerÊÓÆµ²¥·ÅÆ÷µÄʹÓÃ
Èç¹ûÄãÕýÔÚѰÕÒÒ»¸öÍøÒ³Éϲ¥·ÅÊÓÆµµÄ²å¼þ£¬»òÕßÄãÔÏÈÍøÒ³ÉÏÓõÄÊÓÆµ²å¼þ±»Ç½ÁË£¨±ÈÈçjwplayer£©£¬ÄÇô¾ÍÀ´¿´¿´ÏÂÃæµÄ½éÉܰÉ
µ±Â¥Ö÷µÃÖªÔÏÈÓõÄÊÓÆµ²å¼þjwplayerËù·ÃÎʵ½µÄÒ»¸öcdnµØÖ·Ê§Ð§ÁË£¬²¢ÇÒͨ¹ýÍøÉϵķ½·¨²¢²»ÄÜÐÞ¸´jwplayer£¬Ê¹ËüÄÜÕý³£²¥·ÅÊÓÆµ£¬Â¥Ö÷µÄÄÚÐÄÊDZÀÀ£µÄ¡£
µ«Êǵ±°ÑJplayerµ÷ÊÔÍê³Éºó£¬ÖÕÓÚÕÒµ½ÁËÒ»¿îºÃµÄÌæ´úµÄ²å¼þ¡£
1¡¢Ê×ÏÈJplayerµÄ¹ÙÍøÔÚÕâÀ
http://www.jplayer.org/
2¡¢Æä´Î£¬¶ÔÓÚÂ¥Ö÷¶øÑÔ£¬¿´Ò»¸öÊÓÆµ²å¼þÄܲ»ÄÜÓã¬ÓÐÒÔϼ¸²½£º
£¨1£©Óò»Í¬µÄä¯ÀÀÆ÷´ò¿ª¹ÙÍø£¬Í¨³£¹ÙÍøÊ×Ò³¶¼Ò»¸öչʾÓõÄÀý×Ó£¬Èç¹ûչʾµÄÀý×ÓÔÚ³£ÓÃä¯ÀÀÆ÷ÀïÎÞ·¨²¥·Å£¬ÄÇô¾Í²»¼ÌÐøÑо¿Õâ¸ö²¥·ÅÆ÷µÄʹÓ÷½·¨ÁË
£¨2£©½«¹ÙÍødemoÏÂÔØµ½±¾µØ£¬°ÑÀý×ÓÖеÄÊÓÆµÎļþÌæ»»³É±¾µØ×Ô¼ºµÄÎļþ£¨±ÈÈçij¸öMP4Îļþ£©£¬ÔÚ¸÷ÖÖä¯ÀÀÆ÷ÀïÃæ´ò¿ªdemo£¬Èç¹û±¾µØµÄ¾²Ì¬ÊÓÆµÔÚ³£ÓÃä¯ÀÀÆ÷ÀïÎÞ·¨²¥·Å£¬ÄÇôҲ¾Íµ½´Ë½áÊø
£¨3£©½«²½Ö裨2£©ÖеÄÎļþÌæ»»³Éͨ¹ý¶¯Ì¬¶ÁÈ¡·½Ê½£¬±ÈÈçphp¶ÁÈ¡±¾µØÄ³¸öÎļþµÄÁ÷£¬ÔÚ¸÷ÖÖä¯ÀÀÆ÷ÀïÃæ´ò¿ªdemo£¬Èç¹û±¾µØµÄ¾²Ì¬ÊÓÆµÔÚ³£ÓÃä¯ÀÀÆ÷ÀïÎÞ·¨²¥·Å£¬ÄÇôҲ¾Íµ½´Ë½áÊø
£¨4£©½«²½Ö裨3£©ÖеÄphp¶ÁÈ¡±¾µØÄ³¸öÎļþµÄÁ÷£¬Ìæ»»³ÉphpÒÔcurl·½Ê½¶ÁÈ¡ÎļþÁ÷£¬È»ºó²âÊÔÔÚ¸÷ä¯ÀÀÆ÷ÖеÄЧ¹û
P.S. Èç¹ûÖ»ÊDz¥·Å¾²Ì¬Îļþ£¬ÄÇô¿ÉÒÔÔÚ²½Ö裨2£©¾ÍµÃ³ö½áÂÛÁË
3¡¢Jplayer¸ù¾Ý2ÖеIJ½Ö裬£¨2£©ÖУ¬³ýÁËie7¡¢8ÎÞ·¨Ö§³ÖÍ⣬£¨3£©ºÍ£¨4£©µÄ¾ßÌåʵÏÖÈçÏ£º
Èç¹ûʹÓÃÒÔÏÂdemo£¬ÐèÏÂÔØ×ÊÔ´°üÒ»ÆðʹÓà demo
ǰ¶Ë²¿·Ö£º
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Demo</title> <link href="dist/skin/blue.monday/css/jplayer.blue.monday.min.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="lib/jquery.min.js"></script> <script type="text/javascript" src="dist/jplayer/jquery.jplayer.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#jquery_jplayer_1").jPlayer({ ready: function () { $(this).jPlayer("setMedia", { m4v: "test1.php" }); }, play: function() { // To avoid multiple jPlayers playing together. $(this).jPlayer("pauseOthers"); }, swfPath: "dist/jplayer", supplied: "m4v", globalVolume: true, useStateClassSkin: true, autoBlur: false, smoothPlayBar: true, keyEnabled: true }); }); </script> </head> <body> <div id="jp_container_1" class="jp-video jp-video-270p" role="application" aria-label="media player"> <div class="jp-type-single"> <div id="jquery_jplayer_1" class="jp-jplayer"></div> <div class="jp-gui"> <div class="jp-video-play"> <button class="jp-video-play-icon" role="button" tabindex="0">play</button> </div> <div class="jp-interface"> <div class="jp-progress"> <div class="jp-seek-bar"> <div class="jp-play-bar"></div> </div> </div> <div class="jp-current-time" role="timer" aria-label="time"> </div> <div class="jp-duration" role="timer" aria-label="duration"> </div> <div class="jp-controls-holder"> <div class="jp-controls"> <button class="jp-play" role="button" tabindex="0">play</button> <button class="jp-stop" role="button" tabindex="0">stop</button> </div> <div class="jp-volume-controls"> <button class="jp-mute" role="button" tabindex="0">mute</button> <button class="jp-volume-max" role="button" tabindex="0">max volume</button> <div class="jp-volume-bar"> <div class="jp-volume-bar-value"></div> </div> </div> <div class="jp-toggles"> <button class="jp-repeat" role="button" tabindex="0">repeat</button> <button class="jp-full-screen" role="button" tabindex="0">full screen</button> </div> </div> </div> </div> <div class="jp-no-solution"> <span>Update Required</span> To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>. </div> </div> </div> </body> </html>²½Ö裨3£©ÖÐphp¶ÁÈ¡±¾µØ¾²Ì¬ÎļþʾÀý£º£¨ÐèÒªÔÚǰ¶ËÎļþͬ¼¶½¨ÓÐvideoÎļþ¼Ð£¬²¢ÇÒÀïÃæ·ÅÒ»¸ö1.mp4Îļþ£©
<?php $video = 'video/1.mp4'; if (is_file($video)){ header("Content-type: video/mp4"); if (isset($_SERVER['HTTP_RANGE'])){ rangeDownload($video); } else { header("Content-length: " . filesize($video)); readfile($video); } } function rangeDownload($file){ $fp = @fopen($file, 'rb'); $size = filesize($file); // File size $length = $size; // Content length $start = 0; // Start byte $end = $size - 1; // End byte header('Accept-Ranges: bytes'); if (isset($_SERVER['HTTP_RANGE'])){ $c_start = $start; $c_end = $end; list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); if (strpos($range, ',') !== false){ header('HTTP/1.1 416 Requested Range Not Satisfiable'); header("Content-Range: bytes $start-$end/$size"); exit; } if ($range{0} == '-'){ $c_start = $size - substr($range, 1); } else { $range = explode('-', $range); $c_start = $range[0]; $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size; } $c_end = ($c_end > $end) ? $end : $c_end; if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size){ header('HTTP/1.1 416 Requested Range Not Satisfiable'); header("Content-Range: bytes $start-$end/$size"); exit; } $start = $c_start; $end = $c_end; $length = $end - $start + 1; fseek($fp, $start); header('HTTP/1.1 206 Partial Content'); } header("Content-Range: bytes $start-$end/$size"); header("Content-Length: $length"); $buffer = 1024 * 8; while(!feof($fp) && ($p = ftell($fp)) <= $end){ if ($p + $buffer > $end){ $buffer = $end - $p + 1; } set_time_limit(0); echo fread($fp, $buffer); flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit. } fclose($fp); } ?>
Ê×ÏÈÅжÏÍ·ÐÅÏ¢ÖÐÊÇ·ñÓÐ$_SERVER['HTTP_RANGE']£¬
Èç¹ûÓÐÔò°´ÕշֶζÁÈ¡µÄ·½Ê½£¬¸ù¾ÝÍ·ÐÅÏ¢ÖÐÇëÇóµÄ·¶Î§·µ»ØÎļþµÄÊý¾Ý£¬£¨ÐèÒªÔÚ·µ»ØµÄÍ·ÐÅÏ¢ÖÐÔö¼Ó·¶Î§£¬³¤¶È£¬ÎļþÁ÷ÀàÐÍÒÔ¼°206ÐÒ飩
·ñÔò¾Í½«Õû¸öÎļþÁ÷·µ»Ø£¨ÐèÒªÔÚ·µ»ØµÄÍ·ÐÅÏ¢ÖÐÔö¼ÓÎļþÁ÷ÀàÐÍ£©
²½Ö裨4£©ÖÐphpÒÔcurl·½Ê½¶ÁÈ¡Íⲿ½Ó¿ÚµÄÎļþÁ÷ʾÀý£º
<?php $cookie = 'Authorization: 12345678901234567890123456789012'; $api_url = 'http://test.xxx.com'; $file_id = '22223222232222322223'; $url = $api_url."/file_info/".$file_id; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, Array($cookie)); $result = curl_exec($curl); $code = curl_getinfo($curl,CURLINFO_HTTP_CODE); $result = json_decode($result,true); curl_close($curl); if($code == 200){ $file_size = $result['size']; header("Content-type: video/mp4"); if (isset($_SERVER['HTTP_RANGE'])){ rangeDownload($file_id,$cookie,$api_url,$file_size); }else{ allDownload($file_id,$cookie,$api_url,$file_size); } } function allDownload($file_id,$cookie,$api_url,$file_size){ $url = $api_url."/file_content/".$file_id; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_TIMEOUT, 600); curl_setopt($curl, CURLOPT_RETURNTRANSFER, false); curl_setopt($curl, CURLOPT_HTTPHEADER, Array($cookie)); /* part1 ²»×ö»º´æ */ /* header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Content-Description: File Transfer"); header("Content-Transfer-Encoding: binary"); Header('Content-Disposition: attacurlment; filename="'.$file_name.'"'); Header("Content-Length: ".$file_size); */ /* part2 ×ö»º´æ */ $seconds_to_cache = 60*60*24*365; $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT"; header("last-modified:" . gmdate("d M Y H:i:s") . " GMT"); header("Expires: $ts"); header("Pragma: cache"); header("Cache-Control: max-age=$seconds_to_cache"); header("Content-Description: File Transfer"); header("Content-Transfer-Encoding: binary"); Header('Content-Disposition: attacurlment; filename="'.$file_name.'"'); Header("Content-Length: ".$file_size); /* ÒÔÉϵÄÁ½¸öpartѡһ¸öÓü´¿É */ ob_end_flush(); flush(); $result = curl_exec($curl); curl_close($curl); } function rangeDownload($file_id,$cookie,$api_url,$file_size){ header("Accept-Ranges: bytes"); $http_range = $_SERVER['HTTP_RANGE']; $at = explode('=',$http_range); $at = explode('-',$at[1]); $start = $at[0]; if($at[1]==null){ $end = $file_size - 1; }else{ $end = $at[1]; } $length = $end - $start + 1; header('HTTP/1.1 206 Partial Content'); header("Content-Range: bytes $start-$end/$file_size"); header("Content-Length: $length"); $range = "Range:bytes=".$start.'-'.$end; $post_header = Array ( $cookie, $range ); $url2 = $api_url."/file_content/".$file_id; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $post_header); curl_setopt($ch, CURLOPT_TIMEOUT, 600); curl_exec($ch); curl_close($ch); } ?>
Ê×Ïȸù¾ÝÎļþµÄid»ñÈ¡ÎļþµÄsize£¨Ö®ºó·µ»ØÎļþÁ÷ÐÅÏ¢µÄʱºòÐèÒªÔÚÍ·ÐÅÏ¢ÖÐÔö¼ÓÎļþ´óСÕâÒ»²ÎÊý£©
Æä´ÎºÍ²½Ö裨3£©ÖÐÒ»Ñù£¬ÅжÏÍ·ÐÅÏ¢ÖÐÊÇ·ñÓÐ$_SERVER['HTTP_RANGE']£¬
Èç¹ûÓÐÔò°´ÕշֶζÁÈ¡µÄ·½Ê½£¬¸ù¾ÝÍ·ÐÅÏ¢ÖÐÇëÇóµÄ·¶Î§·µ»ØÎļþµÄÊý¾Ý£¬
£¨ÐèÒªÔÚ·µ»ØµÄÍ·ÐÅÏ¢ÖÐÔö¼Ó·¶Î§£¬³¤¶È£¬ÎļþÁ÷ÀàÐÍÒÔ¼°206ÐÒ飻
Èç¹ûÍⲿ½Ó¿ÚÖ§³Ö·Ö¶Î¶ÁÈ¡£¬¿ÉÒÔ°´ÕÕdemoÖÐÖ±½Ó·Ö¶ÎÇëÇó£¬
·ñÔòÐèÒªÓÃÈ«²¿¶ÁÈ¡µÄ·½Ê½£¬È»ºóͨ¹ýphpµÄÇзÖ×Ö·û´®·½Ê½£¬»ñÈ¡ÐèÒª·¶Î§µÄÎļþÁ÷£¬Ê¹ÓÃÕâÖÖ·½·¨»áÀË·ÑÁ÷Á¿£¬Ôö¼ÓÇëÇ󷵻صÄʱ¼ä£©
·ñÔò¾Í½«Õû¸öÎļþÁ÷·µ»Ø£¨ÐèÒªÔÚ·µ»ØµÄÍ·ÐÅÏ¢ÖÐÔö¼ÓÎļþÁ÷ÀàÐÍ£¬demoÖеÄÍ·ÐÅϢΪ²»»º´æµÄ·½Ê½£©
ÍÆ¼öÐÅÏ¢
- ¡¾ÊÓÆµ²¥·Å¡¿JplayerÊÓÆµ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃë¼¶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔØ½ø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæÊµIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆÊµÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓÆµÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓÆµ²¥·Å¡¿JplayerÊÓÆµ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹ØÏµ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ