为几种类型的视频流嵌入播放器

时间:2013-11-24 11:40:24

标签: php

假设我们有不同的媒体文件链接,例如

$link = "http://www.my_site.com/test.mp4"; //MP4

// could be anything else such as
//$link = "http://www.my_site.com/test.flv" //FLV
//$link = "http://www.my_site.com/test.asf" //ASF
//$link = "http://www.my_site.com/test.avi" //AVI
//$link = "http://www.my_site.com/test.rmbv" //RMVB
// so on up to 25 well known extensions

好的,因为没有播放器支持所有媒体扩展,所以我一直在考虑设置

flv,mp4jwplay - asf,avi,wmv,mpg,mpegmedia player - rmvb,rmvreal player - movquick time ..等

因此,对于每个$link functionpathinfo($link, PATHINFO_EXTENSION);将使用wmv获取链接文件扩展名并显示播放器名称。

问题:2个分机mp4function embed($link)的示例如何编写function embed($link){ $ext = pathinfo($link, PATHINFO_EXTENSION); //some code here i can not know what should be //something like this //if ($ext === 'mp4') { //$what = 'JW Player'; //} else if($ext === 'wmv') { //$what = 'Media Player'; //} else { //$what = 'Unknwon'; //} return $url; } // then at applying it for link $link = "http://www.my_site.com/test.mp4"; echo embed($link); // Output : JW Player // then at applying it for link2 $link2 = "http://www.my_site.com/test.wmv"; echo embed($link2); // Output : Media Player // then at applying it for link3 $link3 = "http://www.my_site.com/test.ra"; echo embed($link3); // Output : Unknown ,可以知道媒体文件的扩展名并显示播放器名称。

像这样(但它不仅仅是为了显示我的意思)

{{1}}

所以请你写一下函数做这样的工作,这样我就能理解它是如何工作的,并将它应用于更复杂的例子〜感谢您的帮助

1 个答案:

答案 0 :(得分:1)

只需将return var更改为$what,如下所示:

function embed($link){
$ext = pathinfo($link, PATHINFO_EXTENSION);

//some code here i can not know what should be
//something like this
if ($ext === 'mp4') {
$what = 'JW Player';
} else if($ext === 'wmv') {
$what = 'Media Player';
} else {
$what = 'Unknwon';
}

return $what;
}

现在它返回玩家名称。 然后当你这样称呼它时......

$link = "http://www.my_site.com/test.mp4";
echo embed($link);

...输出JW Player。

相关问题