ES6 多媒体
ES6 多媒体
JavaScript的navigator对象包括一个名为plugins的子对象。此对象返回一个数组,安装在浏览器上每个插件都在其中有一条记录。navigator.plugins对象仅由Netscape、Firefox和Mozilla支持。
例子
<html> <head> <title>List of Plug-Ins</title> </head> <body> <table border = "1"> <tr> <th>Plug-in Name</th> <th>Filename</th> <th>Description</th> </tr> <script LANGUAGE = "JavaScript" type = "text/javascript"> for (i = 0; i<navigator.plugins.length; i++) { document.write("<tr><td>"); document.write(navigator.plugins[i].name); document.write("</td><td>"); document.write(navigator.plugins[i].filename); document.write("</td><td>"); document.write(navigator.plugins[i].description); document.write("</td></tr>"); } </script> </table> </body> </html>
输出结果如下图所示
检查插件
每个插件在数组中都有一条记录。每个记录都具有以下属性
名称—插件的名称。
文件名:加载的可执行文件。
描述:由开发人员提供的插件的描述。
mime类型:一个由插件支持的每个mime类型的条目的数组。
您可以在脚本中使用这些属性来查找已安装的插件,然后使用JavaScript,您可以播放适当的多媒体文件。请看下面的代码。
<html> <head> <title>Using Plug-Ins</title> </head> <body> <script language = "JavaScript" type = "text/javascript"> media = navigator.mimeTypes["video/quicktime"]; if (media) { document.write("<embed src = 'quick.mov' height = 100 width = 100>"); } else { document.write("<img src = 'quick.gif' height = 100 width = 100>"); } </script> </body> </html>
注意:我们使用<embed>加载一个多媒体文件.
控制多媒体
让我们举一个在几乎所有浏览器中工作的真实例子。
<html> <head> <title>Using Embeded Object</title> <script type = "text/javascript"> <!-- function play() { if (!document.demo.IsPlaying()) { document.demo.Play(); } } function stop() { if (document.demo.IsPlaying()){ document.demo.StopPlay(); } } function rewind() { if (document.demo.IsPlaying()){ document.demo.StopPlay(); } document.demo.Rewind(); } // --> </script> </head> <body> <embed id = "demo" name = "demo" src = "http://www.amrood.com/games/kumite.swf" width = "318" height = "300" play = "false" loop = "false" pluginspage = "http://www.macromedia.com/go/getflashplayer" swliveconnect = "true"> </embed> <form name = "form" id = "form" action = "#" method = "get"> <input type = "button" value = "Start" onclick = "play();" /> <input type = "button" value = "Stop" onclick = "stop();" /> <input type = "button" value = "Rewind" onclick = "rewind();" /> </form> </body> </html>