本文介绍了是否有任何方式/ API与< object>进行交互?播放视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看我自己的答案,让它正常运作!

我正在使用video.js在网站上播放视频脱机工作,因此无法使用闪存。由于video.js使用flash后备,我自己写了。

I am using video.js to play videos on a website which will also have to work offline, hence the usage of flash is not possible. Since video.js uses a flash fallback, I wrote my very own.

例如在IE8中创建了对象:

In IE8 for instance and object is created:

<OBJECT codeBase="http://www.microsoft.com/Windows/MediaPlayer/" classid=CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95 width=660 height=418 type=application/x-oleobject>
<embed src="Videos/Aktionen_Coffee-Stop/Teaser_Coffee-Stop.wmv" type="application/x-mplayer2" enabled="1" showstatusbar="1" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="true" width="660" height="418" scale="tofit"></embed></OBJECT>

这完全正常,并且该对象呈现视频播放器(Windows媒体播放器,即resp.quicktime in较旧的mac / safari版本。。

This works perfectly fine and the object renders a video player (windows media player i.e., resp. quicktime in older mac/safari versions).

JavaScript中是否有任何方法可以播放此视频以停止,重放,触发已结束的事件?

Is there any way in JavaScript to make this video playing to stop, replay, fire an "ended" like event?

编辑:时 - 如何创建一个Player对象?人们如何创建这样的文档?认真的MS ......

even when looking at these "docs" - how to freakin create a Player object? How can people create such a doc? Seriously MS...

更新

var wmp = $('#wmp').get(0);

setTimeout(function() {

    console.log(wmp.Controls.currentPosition());
    wmp.Stop();
}, 2000);

wmp.stop()将有效,但 wmp.Controls .controls 始终抛出错误。我只是想知道视频何时结束。

the wmp.stop() will work, but wmp.Controls or .controls always throws an error. I just want to know when the video has ended.

推荐答案

好的,我发现了一些非常奇怪的东西(谁会猜到,它的MS)。

Ok, I found out some really weird stuff (who would have guessed, its MS).

首先,我总是得到Player.controls不可用的错误。也许它与我的代码中使用 CLASSID =CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95而不是有关CLASSID =CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6,如docs中所述。这是因为使用任何其他classid会导致wmp无法加载/播放视频,所以我必须使用该classid。

First thing, I was always getting errors that Player.controls is not available. Maybe it has something to do with that I use the CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" in my code rather than CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" as described in the "docs". This is because using any other classid would cause the wmp not to load/play the video, so I'd have to go with that classid.

var player = document.getElementById("player");

所以,无论我做了什么,任何在我的播放器对象中不可用,例如 player.controls player.media ,没有一个。

So, no matter what I did, any of the objects listed here were not available in my player object, like player.controls or player.media, none of them.

所以我试着记录整个玩家对象,看看究竟是什么: console.log(player)。 IE8,非常棒,在日志中优雅地打印出来: [object] 。真是太令人惊讶了。调试不起作用(怎么可能......)。所以,我为(一个玩家) log :)做了一个,IE崩溃了。太棒了。

So I tried to just log the whole player object to see what actually is there: console.log(player). IE8, awesome as it is, gracefully printed this in the log: [object]. What a surprise, really. Debugging did not work (how could it...). So, I did a for (a in player) log :) IE crashes. Awesome.

奇怪的是,在打开一个新标签后,控制台出现了所有日志。我发现了,这是奇怪但很棒的 - 从现在起作用 - 所有属性,方法和东西都直接放入播放器var中,所以它不是 player.controls.currentPosition ,而是 player.currentPosition 。 Booya。

Strangely, after opening a new tab, the console showed up with all the logs. I found out, and this is the strange but awesome-since-works-now part: all the properties, methods and stuff are directly put into the player var, so it's not player.controls.currentPosition but rather player.currentPosition. Booya.

这是我的工作代码:

    var obj = '<object id="wmp" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" TYPE="application/x-oleobject" width="' + parseInt(parsed.width) + '" height="' + (parseInt(parsed.height) + 0) + '" codebase="http://www.microsoft.com/Windows/MediaPlayer/">';
..
obj += '</object>';

$('#wrapper').html(obj);

var wmp = document.getElementById("wmp");

wmp.attachEvent('playStateChange', function(a) {
    if (a == 8 || a === 0 || a === '0' || parseInt(a) === 0 || a == 'MediaEnded') {
        // check if playback has really finished
        var cpos = wmp.currentPosition,
            dur = wmp.duration;

        if (dur - cpos >= dur - 0.1 ) {
            console.log('the video has ended');
        }
    }
});

在视频播放完毕后使用状态8,实际上永远不会是8。它相当随机0,2或3.大部分为0.

This page here suggests to use the state 8 when the video has finished playback which actually never is 8, ever. It's rather randomly 0, 2 or 3. Mostly 0.

希望这对任何人都有帮助!

Hope this helps anybody!

这篇关于是否有任何方式/ API与&lt; object&gt;进行交互?播放视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 23:07