0

See my own answer, got it working!

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.

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>

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

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

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

Update

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

setTimeout(function() {

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

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


Actionscript filter xml with variable

I've been tinkering for a while whit this problem, and hope someone gets what I'm Trying to do

I have an Xml file

<Results>
    <Details>
        <Id>1</Id>
    </Details>
    <StepResults>
        <Step SeqNr="1">
          <Value>10</Value
        </Step>
        <Step SeqNr="2">
          <Value>100</Value
        </Step>
    </StepResults>
</Results>

Now I created a script where people can parse this dynamically, lets say someone would like to get the id of this Result he can add a variable in their backend like so: [Details.Id] and this will be parsed in actionscript and get the result from the xml.

I parse it like this:

var pattern:RegExp = /\[[A-Za-z\.0-9()=\[\]@]*\]/g;
var possibleVars:Array = str.match(pattern);
for each(var myVar:String in possibleVars){
  //Remove the blockquotes from the var (this would be the [Details.Id])
  var checkVar:String = myVar.substr(1,(myVar.length-2));
  var result:String = dotSyntax(xmlToParse,checkVar);
}

private function dotSyntax(target:XML, path:String):String {
                    //Split the var into different pars
        var level:Array=path.split(".");
        var curr:* = target;
        for (var i:int = 0; i<level.length; i++) {

            if(i==0 && curr[level[i]].length() <= 0){
                return "";
                break;
            }

            //Try to go trough the xml with the supplied var
            curr=curr[level[i]];

        }
                    //return the value from the xml file (if all went well we have 1 here
        return curr;
    }

Now this really works like a charm, but I would like to give them the possibility to find values from the different steps, so normally to get this working in actionscript directly you would filter the xml like this (if you want the Value of step SeqNr=2):

resXml.StepResults.Step.(@SeqNr==2).Value

But I can't seem to get this to work with a dynamic variable. any pointers how I can do this using the dotSyntax function? (returning the value of step seqnr2)

4

2 回答 2

0

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

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

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

所以,无论我做什么,这里列出的任何对象在我的玩家对象中都不可用,比如player.controlsor player.media,它们都没有。

所以我试图只记录整个播放器对象以查看实际存在的内容:console.log(player). IE8,虽然很棒,但它优雅地在日志中打印了这个:[object]. 真是一个惊喜,真的。调试不起作用(它怎么会......)。所以,我做了一个for (a in player)日志:) IE 崩溃。惊人的。

奇怪的是,打开一个新标签后,控制台显示了所有日志。我发现了,这是奇怪但很棒的部分,因为现在可以工作了:所有的属性、方法和东西都直接放入了 player var,所以不是player.controls.currentPosition,而是player.currentPosition. 布亚。

这是我的工作代码:

    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。

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

于 2013-10-10T16:28:58.093 回答
-1

WMV播放器的Javascript API在视频结束后重新开始播放..

document.getElementById("Player").attachEvent("PlayStateChange",function(newState) {
         if(newState == "1") // stopped, restart playback paused at 3 seconds
        {
             document.getElementById("Player").controls.play();
             document.getElementById("Player").controls.pause();
             document.getElementById("Player").controls.currentPosition = "3";
        }
    });
于 2013-10-10T19:08:58.297 回答