首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >外部接口和Internet Explorer 9问题

外部接口和Internet Explorer 9问题
EN

Stack Overflow用户
提问于 2012-01-14 06:36:02
回答 2查看 5.6K关注 0票数 3

男孩-哦-男孩,我讨厌外部接口。我有一个视频播放器,它利用外部接口来控制flash对象,并允许flash对象将消息传递给相同的javascript。有一段时间,它在所有浏览器中都工作得很好。几天前,在我将项目移出开发阶段之前,我去了所有浏览器中测试它,发现应用程序在internet Explorer9中崩溃了。控制台中出现了以下错误:

代码语言:javascript
复制
SCRIPT16389: Could not complete the operation due to error 8070000c.
jquery.min.js, line 16 character 29366

我的javascript文件真的很长,但这里是重要的部分。我的所有操作都包含在我创建的对象中。在我的一个方法中,我有以下几行代码:

代码语言:javascript
复制
var that = this;
that.stop();

下面是作为该方法的结果而调用的所有方法:

代码语言:javascript
复制
this.stop = function(){
    var that = this;
    console.log('stop called');
    that.pause();
    that.seek(0);
    that.isPlaying = false;
    console.log('stop finished');
};

this.pause = function(){  
    var that = this;
        console.log('pause called');
    if(that.player == 'undefined' || that.player == null){
        that.player = that.GetMediaObject(that.playerID);
    }
    that.player.pauseMedia(); //external interface call
    that.isPlaying = false;
    console.log('pause finished');
};

this.seek = function(seek){                 
    var that = this;
    console.log('seek called');
    if(that.player == 'undefined' || that.player ==null){
        console.log("player="+that.player+".  resetting player object");
        that.player = that.GetMediaObject(that.playerID);
        console.log("player="+that.player);
    }
    that.player.scrubMedia(seek); //external interface call

    console.log('seek finished');            
};

//this method returns a reference to my player.  This method is call once when the page loads and then again as necessary by all methods that make external interface calls
this.GetMediaObject = function(playerID){
    var mediaObj = swfobject.getObjectById(playerID);
        console.log('fetching media object: ' +mediaObj );

        //if swfobject.getObjectById fails  
        if(typeof mediaObj == 'undefined' || mediaObj == null){
                console.log('secondary fetch required');
        var isIE = navigator.userAgent.match(/MSIE/i);
        mediaObj = isIE ? window[playerID] : document[playerID];
    }

    return mediaObj;
};

下面是我的console.log语句的输出:

代码语言:javascript
复制
LOG: fetching media object: [object HTMLObjectElement] 
LOG: video-obj-1: ready 
LOG: stop called 
LOG: pause called 
LOG: pause finished 
LOG: seek called 
LOG: player=[object HTMLObjectElement] 
SCRIPT16389: Could not complete the operation due to error 8070000c. 
jquery.min.js, line 16 character 29366

有趣的是,第一个外部接口调用'that.player.pauseMedia()‘似乎没有任何问题,但随后调用'that.player.scrubMedia(0)’失败了。另一件奇怪的事情是,它指出jquery是错误的来源,但在这些函数中没有对jquery的调用。

这是我所知道的不是。这不是我选择时机的问题。当flash对象完全加载后,actionscript的最后一行向javascript发送一条消息。此外,我将参数'allowScriptAccess‘设置为'always’,因此也不是这样。我们使用的actionscript文件已经在以前的项目中使用过,所以我90%确定这不是问题所在。

这是我的actionscript。我没有写actionscript,也不太熟悉actionscript,但我尽量把与我的应用程序最相关的部分放进去:

代码语言:javascript
复制
flash.system.Security.allowDomain("*.mydomain.com");

import flash.external.ExternalInterface;

// variables to store local information about the current media
var mediaEmbedServer:String = "www";
var mediaPlayerID:String;
var mediaFile:String;
var mediaDuration:Number;

// variables to be watched by actionscript and message javascript on changes
var mediaPositions:String = "0,0"; // buffer position, scrub position
var mediaStatus:String;

var netStreamClient:Object = new Object();
netStreamClient.onMetaData = metaDataHandler;
netStreamClient.onCuePoint = cuePointHandler;

var connection:NetConnection;
var stream:NetStream;
var media:Video = new Video();

// grab the media's duration when it becomes available
function metaDataHandler(info:Object):void {
mediaDuration = info.duration;
}

function cuePointHandler(info:Object):void {
}

connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

try {
var paramName:String;
var paramValue:String;
var paramObject:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (paramName in paramObject) {
paramValue = String(paramObject[paramName]);
switch (paramName){
case "server":
mediaEmbedServer = paramValue;
break
case "playerID":
mediaPlayerID = paramValue;
break
}
}
} catch (error:Error) {
}

if (mediaEmbedServer == "dev" || mediaEmbedServer == "dev2"){
connection.connect("rtmp://media.developmentMediaServer.com/myApp");
} else {
connection.connect("rtmp://media.myMediaServer.com/myApp");
}

function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}  

function connectStream():void {
stream = new NetStream(connection);
stream.soundTransform = new SoundTransform(1);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.client = netStreamClient;
media.attachNetStream(stream);
media.width = 720;
media.height = 405;
addChild(media);
}

function netStatusHandler(stats:NetStatusEvent){
switch (stats.info.code){
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetConnection.Call.BadVersion":
case "NetConnection.Call.Failed":
case "NetConnection.Call.Prohibited":
case "NetConnection.Connect.AppShutdown":
case "NetConnection.Connect.Failed":
case "NetConnection.Connect.InvalidApp":
case "NetConnection.Connect.Rejected":
case "NetGroup.Connect.Failed":
case "NetGroup.Connect.Rejected":
case "NetStream.Connect.Failed":
case "NetStream.Connect.Rejected":
case "NetStream.Failed":
case "NetStream.Play.Failed":
case "NetStream.Play.FileStructureInvalid":
case "NetStream.Play.NoSupportedTrackFound":
case "NetStream.Play.StreamNotFound":
case "NetStream.Seek.Failed":
case "NetStream.Seek.InvalidTime":
// report error status and reset javascriptPlay
clearInterval(progressInterval);
messageStatus("error");
break;
default:
// check time through file to determine if media is over
if (stream.time > 0 && stream.time >= (mediaDuration - .25)){
// reset media if it has ended
clearInterval(progressInterval);
stream.play(mediaFile, 0, 0);
messageStatus("finished");
}
}
};

var progressInterval:Number;

// respond to a play/pause request by playing/pausing the current stream
function pauseMedia(){
clearInterval(progressInterval);
if (mediaStatus == 'playing'){
stream.pause();
messageStatus("paused");
}
};
ExternalInterface.addCallback( "pauseMedia", pauseMedia );

// respond to a scrub request by seeking to a position in the media
function scrubMedia(newPosition){
clearInterval(progressInterval);
if (mediaStatus == "playing"){
stream.pause();
messageStatus("paused");
}
stream.seek(newPosition * mediaDuration);
var positionSeconds = newPosition * mediaDuration;
messagePositions(positionSeconds+","+positionSeconds);
};
ExternalInterface.addCallback( "scrubMedia", scrubMedia );


ExternalInterface.call("MediaPlayerReady", mediaPlayerID);   
EN

回答 2

Stack Overflow用户

发布于 2012-08-22 01:30:06

听起来像是由jQuery IE9 bug引起的undefined expando property。调试它的最佳方法是删除userAgent测试,并将其替换为对对象元素的检查,例如:

代码语言:javascript
复制
document.getElementsByTagName("object")[0].outerHTML

查看ID属性在jQuery第一次单击后是否发生更改。

票数 0
EN

Stack Overflow用户

发布于 2013-10-08 21:52:29

我在使用JPEGCam时遇到了这个问题,它也使用flash的外部接口。我的摄像头控件是在div中动态加载的,然后会在IE (而不是firefox或chrome)中抛出这个错误。在将flash控件的初始化移动到父页面中的document.ready,然后根据需要隐藏/显示/移动控件后,我能够解决此异常。

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8858182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档