外部接口和Internet Explorer 9问题 [英] External interface and Internet Explorer 9 issue

查看:394
本文介绍了外部接口和Internet Explorer 9问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小男孩,我讨厌外部接口。我有一个视频播放器,利用外部接口来控制Flash对象,并允许Flash对象将消息传递给同一个javascript。一段时间以来,它在所有浏览器中都运行良好。之前几天我在所有的浏览器中去测试它,然后我将项目移出开发阶段,发现该应用程序在Internet Explorer 9中出现。控制台中出现以下错误:

  SCRIPT16389:由于错误8070000c,无法完成操作。 
jquery.min.js,第16行字符29366

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

  var that = this; 
that.stop();

这里是所有由该方法调用的方法:

  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(); //外部接口调用
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); //外部接口调用

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

//此方法返回对我的播放器的引用。该方法是在页面加载时调用一次,然后根据需要再次进行外部接口调用的所有方法
this.GetMediaObject = function(playerID){
var mediaObj = swfobject.getObjectById(playerID);
console.log('提取媒体对象:'+ mediaObj);

//如果swfobject.getObjectById失败
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文件的输出:

  LOG:提取媒体对象:[object HTMLObjectElement] 
日志:video-obj-1:ready
日志:停止调用
日志:暂停称为
日志:暂停完成
日志:寻求调用
日志:播放器= [对象HTMLObjectElement]
SCRIPT16389:由于错误8070000c无法完成操作。
jquery.min.js,第16行字符29366

有趣的是,它出现第一个外部接口调用'that.player.pauseMedia()'没有任何问题,但后来的that.player.scrubMedia(0)调用失败。另一个奇怪的是它指向jquery作为错误的根源,但是在这些函数中没有调用jquery。



这是我知道的不是。这不是我的时间关闭的问题。当Flash对象完全加载时,我的动作脚本的最后一行会向javascript发送一条消息。此外,我将参数'allowScriptAccess'设置为始终,因此也不是。我们使用的actionscript文件已被用于以前的项目,所以我有90%的确定这不是问题。



这里是我的动作脚本。我没有写动作脚本,我不太熟悉这个语言,但是我试图放入与我的应用程序最相关的部分:

  flash.system.Security.allowDomain(*。mydomain.com); 

import flash.external.ExternalInterface;

//存储有关当前媒体的本地信息的变量
var mediaEmbedServer:String =www;
var mediaPlayerID:String;
var mediaFile:String;
var mediaDuration:Number;

//要由actioncript观察的变量和更改消息javascript
var mediaPositions:String =0,0; //缓冲位置,擦除位置
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();

//获取媒体的可用时间
函数metaDataHandler(info:Object):void {
mediaDuration = info.duration;
}

函数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(paramObject in paramObject){
paramValue = String(paramObject [paramName]);
switch(paramName){
caseserver:
mediaEmbedServer = paramValue;
break
caseplayerID:
mediaPlayerID = paramValue;
break
}
}
} catch(错误:错误){
}

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

函数securityErrorHandler(event:SecurityErrorEvent):void {
trace(securityErrorHandler:+ event);
}

函数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);
}

函数netStatusHandler(stats:NetStatusEvent){
switch(stats.info.code){
caseNetConnection.Connect.Success:
connectStream();
break;
caseNetConnection.Call.BadVersion:
caseNetConnection.Call.Failed:
caseNetConnection.Call.Prohibited:
caseNetConnection.Connect.AppShutdown :
caseNetConnection.Connect.Failed:
caseNetConnection.Connect.InvalidApp:
caseNetConnection.Connect.Rejected:
caseNetGroup.Connect
caseNetGroup.Connect.Rejected:
caseNetStream.Connect.Failed:
caseNetStream.Connect.Rejected:
caseNetStream
NetStream.Play.Failed:
caseNetStream.Play.FileStructureInvalid:
caseNetStream.Play.NoSupportedTrackFound:
caseNetStream 。
caseNetStream.Seek.Failed:
caseNetStream.Seek.InvalidTime:
//报告错误状态并重置javascriptPlay
clearInterval( progressInterval);
messageStatus(error);
break;
默认值:
//检查文件的时间以确定媒体是否超过
if(stream.time> 0&& stream.time> =(mediaDuration - .25) ){
//如果已经结束,请重置媒体
clearInterval(progressInterval);
stream.play(mediaFile,0,0);
messageStatus(finished);
}
}
};

var progressInterval:Number;

//通过播放/暂停当前流来响应播放/暂停请求
function pauseMedia(){
clearInterval(progressInterval);
if(mediaStatus =='playing'){
stream.pause();
messageStatus(paused);
}
};
ExternalInterface.addCallback(pauseMedia,pauseMedia);

//通过寻求媒体中的位置来响应一个擦除请求
函数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);


解决方案

我使用JPEGCam有这个问题,外部接口我的网络摄像头控件正在动态加载到一个div中,然后将这个错误引到IE中(而不是Firefox或chrome)。将我的Flash控件的初始化移动到父页面中的document.ready后,根据需要隐藏/显示/移动控件,我可以解决这个异常。



希望有帮助。


Boy-oh-boy do I hate external interface. I have a video player that utilizes external interface to control the flash object and to allow the flash object to pass messages to the same javascript. For a time it worked well in all browsers. Then a few days ago i went to go test it in all browsers before i moved the project out of development, and found that the application broke in internet explorer 9. The following error appeared in the console:

SCRIPT16389: Could not complete the operation due to error 8070000c.
jquery.min.js, line 16 character 29366

My javascript file is really long but here are the important parts. All my actions are contained in an object that i created. Inside one of my methods i have the following lines:

var that = this;
that.stop();

here are all the methods that get called as a result of that method:

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;
};

Here's the output from my console.log statments:

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

The interesting thing is that it appears that the first external interface call 'that.player.pauseMedia()' doesn't have any issue, but the subsequent call to 'that.player.scrubMedia(0)' fails. Another odd thing is that it points to jquery as the source of the error, but there's no call to jquery in those functions.

Here's what i know it's not. It is not an issue where my timing is off. The last line of my actionscript sends a message to the javascript when the flash object has completely loaded. Also i set the parameter 'allowScriptAccess' to 'always' so it's not that either. The actionscript file we use has been used in previous projects so i am 90% certain that that is not the issue.

here's my actionscript anyways. I didn't write actionscript and i'm not too familiar with the language but I tried to put in the parts that seemed most pertinent to my application:

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);   

解决方案

I had this problem using JPEGCam, which also uses flash's external interface. My webcam control was being loaded dynamically within a div, and would then throw this error in IE (not firefox or chrome). After moving the initialization of my flash control to document.ready in the parent page, then hiding/showing/moving the control as needed, i was able to work around this exception.

Hope that helps.

这篇关于外部接口和Internet Explorer 9问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆