众所周知,Youtube的ActionScript API已经停止使用。因此,我寻找替代方案来在我的Adobe AIR应用程序中播放Youtube视频。
我测试了一些代码,并记录了每个代码的结果,如下所示:
1° 代码:
var hl:HTMLLoader = new HTMLLoader();
hl.width = 500;
hl.height = 300;
hl.addEventListener(Event.COMPLETE, complete); //event is dispatched, but with js errors
hl.load(new URLRequest("http://www.youtube.com/embed/XXXXX"));
结果:出现了“Object.freeze不是函数”的错误。
2° 代码:
var webView:StageWebView = new StageWebView();
webView.viewPort = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
webView.stage = stage;
webView.addEventListener(Event.COMPLETE, complete); //event is dispatched, but with js errors
webView.loadURL("http://www.youtube.com/embed/XXXXX");
结果: 出现了相同的错误'Object.freeze不是一个函数'。
第三段代码:
// changed 'useNative' param to true for StageWebView
var webView:StageWebView = new StageWebView(true);
// the same code of 2° Code
结果:没有错误,但页面没有完全加载,并且视频无法播放。
4° 代码:
// I've changed loadURL to loadString, for both methods...
var stringPage:String = '<html><head></head><body><iframe width="640" height="360" src="http://youtube.com/embed/XXXXXX" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></body></html>';
webView.loadString(stringPage);
// or
hl.loadString(stringPage);
结果:出现黑色矩形,但是视频无法加载。
5° 代码:
// I've tried use the AS3 API URL:
hl.load(new URLRequest("http://www.youtube.com/v/XXXXXX"));
// or
webView.loadURL("http://www.youtube.com/v/XXXXXX");
结果:出现“不再支持嵌入Flash视频”的消息,视频无法播放。“怪奇物语”:
// the Youtube Page Video works!
webView.loadURL("http://www.youtube.com/watch?v=XXXXXX");
// or
hl.load(new URLResquest("http://www.youtube.com/watch?v=XXXXXX"));
问题是:有人知道如何在2019年用ActionScript 3.0加载YouTube视频吗?