由于Embed标签是Netscape的私有财产,故一直未被W3C认可,对于各种媒体文件使用Embed标签是非标准的,如何改变?Elizabeth Castro的 Bye Bye Embed 一文对于各种媒体播放器给出了很好的符合web标准的代码。

在线媒体播放--Google Video and YouTube

<objecttype="application/x-shockwave-flash"  data="http://video.google.com/googleplayer.swf? »
8755581808731033658"
  width="400"height="326"id="VideoPlayback"><paramname="movie"    value="http://video.google.com/googleplayer.swf? »
docId=8755581808731033658"
/><paramname="allowScriptAcess"value="sameDomain"/><paramname="quality"value="best"/><paramname="bgcolor"value="#FFFFFF"/><paramname="scale"value="noScale"/><paramname="salign"value="TL"/><paramname="FlashVars"value="playerMode=embedded"/></object>

其实就是FLASH文件的调用

Windows Media Player 文件

<objecttype="video/x-ms-wmv"  data="http://www.sarahsnotecards.com/catalunyalive/ »
fishstore.wmv"
  width="320"height="260"><paramname="src"    value="http://www.sarahsnotecards.com/catalunyalive/ »
fishstore.wmv"
/><paramname="autostart"value="true"/><paramname="controller"value="true"/></object>

上面的代码没有Windows Media Player特有的classid,作者在IE5.5, IE6, IE7, Opera Win/Mac, Firefox Win/Mac, Safari下测试通过。

QuickTime movies 没有 embed 标签

<objectclassid="clsid:02BF25D5-8C17-4B23-BC80- »
D3488ABDDC6B"
  codebase="http://www.apple.com/qtactivex/qtplugin.cab"  width="320"height="260"><paramname="src"    value="http://www.sarahsnotecards.com/catalunyalive/ »
diables.mov"
/><paramname="controller"value="true"/><paramname="autoplay"value="false"/><!--[if !IE]>--><objecttype="video/quicktime"    data="http://www.sarahsnotecards.com/catalunyalive/ »
diables.mov"
    width="320"height="260"><paramname="autoplay"value="false"/><paramname="controller"value="true"/></object><!--<![endif]--></object>

出处:蓝色理想

Bye Bye Embed

It has always gotten my goat that Internet Explorer’s non-standard use of the object tag has forced standards-loving browsers to use the non-standard embed tag in order to embed movies on a web page. Even on Apple’s site, the embed tag—a Netscape extension, for Pete’s sake!—is so entrenched that it’s hard to even find information about using the object element for QuickTime, except in a non-standard way.

The use of embed has gone on too long. Wishing for it to become part of the official specs is like wishing your partner would start putting the cap on the toothpaste. It’s not going to happen. It’s time to move on. If you want to validate your website, you have to get rid of embed. In this article, I’ll show you how.

Online Movies: Google Video and YouTube

ALA readers will remember Drew McLellan’s seminal article on Flash Satay. In that article, Drew described a method for inserting Flash animations on a page without using the embed element. Flash Satay has two parts. First, Drew figured out that you can use a single object element to call Flash as long as you specify its type adequately. Second, to properly stream Flash movies, you have to embed a sort of reference movie.

I’ve been experimenting with Drew’s code on Google Video and YouTube content. I was shocked to find that Google Video suggests you use only the embed tag to embed their video on Web pages. Alas, not shocked that they would suggest such a thing—just shocked that it actually works on Internet Explorer, which stopped supporting the non-standard, but universally-supported embed tag years ago in favor of its proprietary implementation of the standard object tag that renders that tag completely invisible to standards-loving browsers. It turns out that IE supports embed as long as the visitor has the appropriate player already installed. If not, they get an error and a generic broken-plugin icon, but no help. YouTube, for its part, does the often seen but hardly standard twice cooked approach, offering both the object and embed tags.

Since both Google Video and YouTube serve movies through the Flash player—regardless of your movie’s format when you uploaded it—you can use Drew’s single object method to embed such movies on your page. Indeed, you don’t have to use the Satay part of his code; movies on Google Video and YouTube stream even without the reference movie he suggests. (Line wraps marked » —Ed.)

<object type="application/x-shockwave-flash"
data="http://video.google.com/googleplayer.swf? »
8755581808731033658"
width="400" height="326" id="VideoPlayback">
<param name="movie"
value="http://video.google.com/googleplayer.swf? »
docId=8755581808731033658" />
<param name="allowScriptAcess" value="sameDomain" />
<param name="quality" value="best" />
<param name="bgcolor" value="#FFFFFF" />
<param name="scale" value="noScale" />
<param name="salign" value="TL" />
<param name="FlashVars" value="playerMode=embedded" />
</object>

My real peeve, however, as I mentioned above, isn’t with Flash movies—which I have little experience with—but with QuickTime and Windows Media Player movies. I’ve been trying to embed these in a standard way for years, but without much luck. Quite recently, I came upon the MIME type that will let you use a single object for Windows Media Player files (.wmv). I still can’t quite believe it.

Eureka! One object for Windows Media Player

I am a firm believer in paying attention to mistakes. It’s only when I notice that I’ve done something wrong, and figure out why, that I am able to figure out new ways of doing things right. As I was reviewing the technique, I noticed that although it did work well for QuickTime movies (as described below), it didn’t work for Windows Media Player movies…on Opera…for Windows. I suppressed the urge to ignore it, and as I dug for an answer to that problem, I came across the MIME type that will let you use a single object to embed Windows Media Player files: video/x-ms-wmv.

To embed a Windows Media Player file, you should be able to use this code (Line wraps marked » —Ed.):

<object type="video/x-ms-wmv"
data="http://www.sarahsnotecards.com/catalunyalive/ »
fishstore.wmv"
width="320" height="260">
<param name="autostart" value="true" />
<param name="controller" value="true" />
</object>

But it turns out that IE6 and IE7 and Safari (strange bedfellows if ever there were), all need a little extra push, in the form of an extra param element:

<object type="video/x-ms-wmv"
data="http://www.sarahsnotecards.com/catalunyalive/ »
fishstore.wmv"
width="320" height="260">
<param name="src"
value="http://www.sarahsnotecards.com/catalunyalive/ »
fishstore.wmv" />
<param name="autostart" value="true" />
<param name="controller" value="true" />
</object>

And it works.

Personally, I consider this pretty experimental, or at the very least sacrilegious… embedding a Windows Media Player movie without a classid! (What’s next? Valid documents with no DOCTYPE?) I tested this simple example in IE5.5, IE6, IE7, Opera Win/Mac, Firefox Win/Mac, and Safari and it worked just fine. That said, I don’t do a lot of scripting or Microsoft stuff, so your mileage may vary. (Note: Of course, there are many more param elements that you may wish to use.)

Embedding QuickTime movies without embed

Unfortunately, I’m still pretty sure there’s no type that would convince IE to open a QuickTime movie without an ActiveX control. The obvious choices, type="video/quicktime" or even type="application/x-quicktime", only work on standards-loving browsers. So I went a different route.

Some basic premises

This technique is based on a couple of premises:

  • First, the object element is designed to be nested in order to help browsers degrade gracefully. If a browser can’t display the outermost object, it should try the next one and then the next one until it finds one it can handle. Once it does find an object it can deal with, it is supposed to ignore the rest.
  • Second, most major browsers fully support the object element. The big exception is (surprise) Internet Explorer. IE6 displays all object elements it can deal with—even if they’re nested—as well as rather ugly, ghostly apparitions of the ones it can’t. Thankfully, IE7 doesn’t do the ghosts, but it unfortunately doesn’t favor the nested objects if there’s a problem with the outer object. It just gives you an error.
  • Third, Internet Explorer (up to and including version 7) implements the object element in a non-standard way that makes other browsers ignore it.

I think the answer can be found in IE’s system of conditional comments. I started hearing about it when folks were trying to decide how to deal with IE7’s new approximation to CSS. And while IE’s commenting is peculiar to IE (read: proprietary), so is its failure to properly use the object element. It’s a perfect match.

Embedding QuickTime for Internet Explorer

I’m going to use QuickTime for my example, but you can use the same technique with Windows Media Player movies with the classid attribute, as I’ll show you a bit farther along.

To insert a basic QuickTime movie in Internet Explorer, we’ll use something like this (Line wraps marked » —Ed.):

<object classid="clsid:02BF25D5-8C17-4B23-BC80 »
-D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
width="320" height="256">
<param name="src"
value="http://www.sarahsnotecards.com/catalunyalive/ »
diables.mov" />
<param name="controller" value="true" />
<param name="autoplay" value="false" />
</object>

Don’t forget the height or the width or that horrendous classid which calls the QuickTime ActiveX control. Note that the param element that specifies the URI of the movie has a name attribute of “src,” not “url” or “movie.”

You can preview the effect here. In IE, you’ll see a movie, in other browsers you won’t see a thing.

Embedding QuickTime movies for everyone else

Although standards-loving browsers can’t deal with that object since the classid attribute is that awful number instead of a URL, they will keep looking to see if there’s any nested objects they can deal with.

So, just before the closing </object> tag, we’ll use a standard implementation of the object element (Line wraps marked » —Ed.):

<object classid="clsid:02BF25D5-8C17-4B23-BC80- »
D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
width="320" height="256">
<param name="src"
value="http://www.sarahsnotecards.com/catalunyalive/ »
diables.mov" />
<param name="controller" value="true" />
<param name="autoplay" value="false" />
<object type="video/quicktime"
data="http://www.sarahsnotecards.com/catalunyalive/ »
diables.mov"
width="320" height="256">
<param name="autoplay" value="false" />
<param name="controller" value="true" />
</object>
</object>

The width and height are required, as is the type.

If you view this combination in a standards-loving browser, it looks great, if a bit loud. IE 6 (and earlier), as we mentioned before, can’t quite decide what to do with the second object and basically botches it with a ghostly apparition.

What IE can’t see, it can’t mess up

Although IE’s conditional comments were designed to be used for the rather questionable purpose of serving it special code that is hidden from other browsers, we’ll use them here to hide code from IE but not from other browsers. (It’s a bit of a slap in the face—though not really that surprising—that Microsoft has the nerve to refer to these other browsers as “downlevel”.)

Comments written with Microsoft’s “original syntax” don’t validate (surprise) but thankfully, Lachlan Hunt figured out a way to adjust them so that they do.

So we need to hide the second object from IE with its own commenting system. Insert <!--[if !IE]>--> in front of the second <object> tag and <!--<![endif]--> right after the first closing </object> tag. (Line wraps marked » —Ed.)

<object classid="clsid:02BF25D5-8C17-4B23-BC80- »
D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
width="320" height="260">
<param name="src"
value="http://www.sarahsnotecards.com/catalunyalive/ »
diables.mov" />
<param name="controller" value="true" />
<param name="autoplay" value="false" />
<!--[if !IE]>-->
<object type="video/quicktime"
data="http://www.sarahsnotecards.com/catalunyalive/ »
diables.mov"
width="320" height="260">
<param name="autoplay" value="false" />
<param name="controller" value="true" />
</object>
<!--<![endif]-->
</object>

Now it’s beautiful!

What’s more you can use the whole collection of parameters with the object element as described on Apple’s Developers site.

Next time, I’ll test with a slightly less raucous movie.

The details for Windows Media Player

If you’d rather embed Windows Media Player files with the classid and not in the one-object method I demonstrate near the beginning of this article, the code is only slightly different. For the classid in the initial object tag, use classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6". To specify the URL of your Windows Media Player movie, use a param element with a name attribute equal to “url” for most browsers and then repeat the value using a name attribute equal to “src” for Safari.

Then in the second, standards-compliant implementation of the object, use the same code as in the one-object method.

Here’s an example (Line wraps marked » —Ed.):

<object classid="CLSID:6BF52A52-394A-11d3-B153- »
00C04F79FAA6"
id="player" width="320" height="260">
<param name="url"
value="http://www.sarahsnotecards.com/catalunyalive »
/fishstore.wmv" />
<param name="src"
value="http://www.sarahsnotecards.com/catalunyalive »
/fishstore.wmv" />
<param name="showcontrols" value="true" />
<param name="autostart" value="true" />
<!--[if !IE]>-->
<object type="video/x-ms-wmv"
data="http://www.sarahsnotecards.com/catalunyalive »
/fishstore.wmv"
width="320" height="260">
<param name="src"
value="http://www.sarahsnotecards.com/ »
catalunyalive/fishstore.wmv" />
<param name="autostart" value="true" />
<param name="controller" value="true" />
</object>
<!--<![endif]-->
</object>

A small wrinkle, or, what’s left to do

As of January 2006, Apple started promoting the use of JavaScript to call movies for web pages so that users wouldn’t have to click on ActiveX controls in order to activate them. It’s a long, convoluted story that began with a lawsuit against Microsoft and ended up making life difficult for the rest of us. At any rate, the methods described above work almost perfectly without any JavaScript at all, with one caveat: QuickTime movies won’t autoplay in IE. I’m not sure I’d even want the example video to autoplay! Nevertheless, I find it highly suspicious that Windows Media Player files load in the background and autoplay without any interaction while QuickTime movies show just the initial frame while the audio plays, but no moving pictures are shown.

At any rate, I want to see how the activating ActiveX controls issue plays out before I implement what I consider a rather laborious JavaScript solution to my whole site. I use very little JavaScript and like to keep it that way.

Whether you go the JavaScript route or not is actually irrelevant to the article at hand. Either way, you can still eschew the embed tag for the standard object element.

I would have liked to figure out a way to hide the inner objects only from IE 6 and earlier, since IE 7 (at least in beta 2) seems to be handling nested object elements properly, but I was unsuccessful. While there is a conditional comment that would allow such a thing (<!--[if gte IE 7]>-->), the extra characters (-->) that Lachlan offered to make the thing validate are visible with IE7 (as they should be logically). Any ideas?

On the shoulders of giants

Other people have also worked on this problem. This article agreed that two nested object elements should work but relied on what I consider rather complicated CSS to hide the second object.

Ian Hickson used the IE comments to hide a second object from IE that had Flash content.

And the aforementioned Lachlan Hunt figured out how to write valid Internet Explorer conditional comments that hide content from IE while revealing it to other browsers.

  • Illustration by Kevin Cornell

转载于:https://www.cnblogs.com/wangxiaodong/archive/2007/04/01/696343.html

Bye Bye Embed-再见了Embed,符合web标准的媒体播放器代码相关推荐

  1. web页面嵌入音乐播放器代码

    网站嵌入背景音乐代码大全,使用以下代码,给您的网站添加背景音乐吧!  注意,以下代码使用的时候,注意:一下代码有的需要改为半角形式,才能正常使用. 将这段代码插入到您的<head>< ...

  2. VLC媒体播放器Web插件详细说明

    原文地址:https://wiki.videolan.org/Documentation:WebPlugin/ 简介:使用视频构建网页 该VLC媒体播放器 webplugins是原生浏览器插件,类似于 ...

  3. web包下载_Plex Home Theater免费版下载-多功能媒体播放器 v1.4.1.469 免费版

    Plex Home Theater是一款综合影视文件播放解决方案,可将用户的普通旧PC转变为功能齐全的家庭影院PC,凭借易于使用的界面和吸引人的设计,您将立即获得前所未有的多媒体内容访问权限:Plex ...

  4. Web端H.265播放器研发解密

    音视频编解码对于前端工程师是一个比较少涉足的领域,涉及到流媒体技术中的文本.图形.图像.音频和视频多种理论知识的学习,才能够应用到具体实践中,本团队在多媒体领域深耕两年多,才算是有一定产出,我们自研w ...

  5. Discuz论坛web网页mp3音频播放器源码下载

    最近在做一个DZ论坛的搭建,在前几天的时候遇到Flash+Js的幻灯片的问题,特写了一篇<JS+Flash焦点图轮播源代码(2屏,3屏,多屏)>来记录论坛搭建过程遇到的一些技术性问题,以便 ...

  6. php项目网页音乐播放器插件,基于HTML5 canvas和Web Audio的音频播放器插件

    wavesurfer.js是一款基于HTML5 canvas和Web Audio的音频播放器插件.通过wavesurfer.js你可以使用它来制作各种HTML5音频播放器,它可以在各种支持 Web A ...

  7. Web端H.265播放器研发解密 1

    音视频编解码对于前端工程师是一个比较少涉足的领域,涉及到流媒体技术中的文本.图形.图像.音频和视频多种理论知识的学习,才能够应用到具体实践中,本团队在多媒体领域深耕两年多,才算是有一定产出,我们自研w ...

  8. 开源html5在线音乐,10 个基于 Web 的 HTML5 音乐播放器

    HTML5 是一种用于创建和呈现的网页内容的语言.这是一个革命性的语言,它拥有一些真正棒的功能和一个新的HTML5规范允许本地音频流的播放.本文向你推荐 10 个最棒的 HTML5 音频播放器,看看你 ...

  9. 5 个免费的 Web 视频及音频播放器

    在线视频,在线音频越来越流行,即使你的网站成不了 YouTube,也不妨在上面部署一些可以直接在线播放的视频,在 Web 上播放媒体,如今最可靠方案莫过于 Flash.本文介绍5个免费的,简单易用的, ...

最新文章

  1. Project Euler 50 Consecutive prime sum
  2. Python【Python基础】
  3. 另一个git进程似乎在这个存储库中运行
  4. OGG目标端复制Sequence时Hang住的问题
  5. ts获取服务器数据_基于Nginx的媒体服务器技术-线上公开课
  6. 【Todo】各种语言里面的for循环 loop
  7. DataTable 转为ListT集合
  8. leetcode589. N叉树的前序遍历
  9. Android 5.0 开发者官方网站疏理知识结构
  10. 读书笔记《程序员修炼之道》
  11. 房间计费系统改造E-R图纸设计
  12. POJ 334932742151184020022503
  13. hdoj6298:Maximum Multiple(找规律,总结)
  14. anaconda 安装Mosek
  15. python正态分布函数_使用Python实现正态分布、正态分布采样
  16. 直播系统开发,直播平台源码切忌一成不变
  17. 成长笔记4:教育是什么
  18. SP-API 修改货件api-修改货件sku个数坑分享
  19. RTOS系统与Linux系统的区别
  20. Python爬虫——爬取IEEE论文

热门文章

  1. 计算机基础:存储系统知识笔记(二)
  2. Linux文件和目录权限笔记
  3. 你怎样看待比自己强的人?
  4. saej1929_(1929年-2020年)
  5. 2021年7月 虾皮、货拉拉、有赞等面经总结
  6. 云时代架构读后感4--IT架构的本质
  7. Spring配置文件中bean标签的scope属性
  8. 深入理解javascript原型和闭包
  9. 实战使用Axure设计App,使用WebStorm开发(4) – 实现页面UI
  10. 魅族MX4的线控电路图