从 javascript 控制 QuickTime 影片在 IE 中不起作用

发布于 2024-12-11 04:12:08 字数 2021 浏览 0 评论 0原文

我在通过 JavaScript 控制 QuickTime 电影时遇到问题。我使用 HTML5 元素在 HTML 页面中嵌入视频 - 如果浏览器不支持它(例如 IE 8),则回退到 Quicktime(我有一个特定要求“不flash”,但允许使用 Quicktime)。视频显示在弹出窗口中;当弹出窗口关闭时,我想停止视频播放。我可以在 HTML5 中成功完成此操作,但 Quicktime 控件无法正常工作。

我的 html 看起来像这样:

<video width="360" height="298" autobuffer="autobuffer" controls="controls" id="video" tabindex="0">
    <source type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;" src="/data/mmg-demo.mp4"></source>
    <source type="video/ogg" src="/data/mmg-demo.ogv"></source>
    <object width="360" height="298" id="videoem" codebase="http://www.apple.com/qtactivex/qtplugin.cab" classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b">
        <param value="/data/mmg-demo.mp4" name="src">
        <param value="false" name="autoplay">
        <param value="true" name="controller">
        <embed width="360" height="298" name="videoem" pluginspage="http://www.apple.com/quicktime/download/" loop="false" controller="true" autoplay="false" src="../files/380/380523/video.mp4">
    </object>
</video>

弹出关闭 javascript 函数看起来像这样:

function closePopup {
    //stop html5 playback if it's there
    if(typeof document.getElementById('video').pause == 'function') {
        document.getElementById('video').pause();
    }
    //stop playback of quicktime embed if it's there
    if(document.getElementById('videoem')) {
        document.getElementById('videoem').SetRate(0.0);
    }
    $('#demo-video').fadeOut();
}

我已经在 Firefox 中测试了完全相同的 Quicktime 代码 - 并且它工作正常。此外,其他论坛中声称可以工作的示例在 IE 8 中不起作用(例如,请参阅 http://lists.apple.com/archives/quicktime-api/2008/Mar/msg00187.html - 在 IE 中不起作用8).

document.getElementById('videoem').SetRate(0.0) 行导致 Object 不支持此属性或方法 错误。

我不知道还能去哪里看看。非常感谢任何帮助。

I've got a problem controlling a quicktime movie from javascript. I am embedding a video in my HTML page using <video> HTML5 element - with fallback to quicktime if the browser doesn't support it (e.g. IE 8) (I have a specific requirement of "no flash", but quicktime is allowed). The video is displayed in a popup; when the popup is being closed, I want to stop video playback. I can do this successfully in HTML5, but the quicktime control is not working.

My html looks like this:

<video width="360" height="298" autobuffer="autobuffer" controls="controls" id="video" tabindex="0">
    <source type="video/mp4; codecs="avc1.42E01E, mp4a.40.2"" src="/data/mmg-demo.mp4"></source>
    <source type="video/ogg" src="/data/mmg-demo.ogv"></source>
    <object width="360" height="298" id="videoem" codebase="http://www.apple.com/qtactivex/qtplugin.cab" classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b">
        <param value="/data/mmg-demo.mp4" name="src">
        <param value="false" name="autoplay">
        <param value="true" name="controller">
        <embed width="360" height="298" name="videoem" pluginspage="http://www.apple.com/quicktime/download/" loop="false" controller="true" autoplay="false" src="../files/380/380523/video.mp4">
    </object>
</video>

The pop-up close javascript function looks like this:

function closePopup {
    //stop html5 playback if it's there
    if(typeof document.getElementById('video').pause == 'function') {
        document.getElementById('video').pause();
    }
    //stop playback of quicktime embed if it's there
    if(document.getElementById('videoem')) {
        document.getElementById('videoem').SetRate(0.0);
    }
    $('#demo-video').fadeOut();
}

I've tested this exact same quicktime code in firefox - and it works fine. Moreover, examples in other forums that claim to work, do not work in IE 8 (e.g. see http://lists.apple.com/archives/quicktime-api/2008/Mar/msg00187.html - does not work in IE 8).

Line document.getElementById('videoem').SetRate(0.0) causes Object does not support this property or method error.

I'm not sure where else to look. Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2024-12-18 04:12:08

好吧,我想我明白了。诀窍是使用 元素中的 ID,而不是 元素。所以我得到的最终(工作)代码是这样的。

HTML:

<div id="mkt-video" style="position:fixed;width:360px;background-color:black;padding:10px;border:solid 2px white;display:none;z-index:100003">
    <video id="video" width="360" height="298" controls="controls" autobuffer="autobuffer">
        <source src="/data/mmg-demo.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
        <source src="/data/mmg-demo.ogv" type="video/ogg" />
        <object classid='clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b' width="360" height="298" codebase='http://www.apple.com/qtactivex/qtplugin.cab' id="videoem-object">
            <param name='src' value="/data/mmg-demo.mp4" />
            <param name='autoplay' value="false" />
            <param name='controller' value="true" />
            <param name="enablejavascript" value="true" />
            <embed src="../files/380/380523/video.mp4" width="360" height="298" autoplay="false" controller="true" loop="false" pluginspage='http://www.apple.com/quicktime/download/' name="videoem" id="videoem"></embed>
        </object>
    </video>
</div>

和Javascript:

function closeVideo() {
    if(typeof document.getElementById('video').pause == 'function') {
        document.getElementById('video').pause();
    }
    try {
        document.getElementById('videoem-object').SetRate(0.0);
    }
    catch (err) {}
    $('#mkt-video').fadeOut();
}

“try-catch”是必需的,因为IE9仍然创建嵌入对象,但类型奇怪,并抛出一些奇怪内容的错误。无论如何,现在工作得很好。

Ok, I think I figured it out. The trick is to use the ID from the <embed> element and not the <object> element. So the final (working) code I got is this.

HTML:

<div id="mkt-video" style="position:fixed;width:360px;background-color:black;padding:10px;border:solid 2px white;display:none;z-index:100003">
    <video id="video" width="360" height="298" controls="controls" autobuffer="autobuffer">
        <source src="/data/mmg-demo.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
        <source src="/data/mmg-demo.ogv" type="video/ogg" />
        <object classid='clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b' width="360" height="298" codebase='http://www.apple.com/qtactivex/qtplugin.cab' id="videoem-object">
            <param name='src' value="/data/mmg-demo.mp4" />
            <param name='autoplay' value="false" />
            <param name='controller' value="true" />
            <param name="enablejavascript" value="true" />
            <embed src="../files/380/380523/video.mp4" width="360" height="298" autoplay="false" controller="true" loop="false" pluginspage='http://www.apple.com/quicktime/download/' name="videoem" id="videoem"></embed>
        </object>
    </video>
</div>

And Javascript:

function closeVideo() {
    if(typeof document.getElementById('video').pause == 'function') {
        document.getElementById('video').pause();
    }
    try {
        document.getElementById('videoem-object').SetRate(0.0);
    }
    catch (err) {}
    $('#mkt-video').fadeOut();
}

The "try-catch" is required, because IE9 still creates the embed object but of some strange type and throws errors of some strange content. Anyway, it works fine now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文