谷歌 IMA + MediaElementJS

发布于 2024-12-24 19:57:27 字数 550 浏览 0 评论 0原文

我已成功合并 HTML5 版本的 Google IMA 广告,并尝试与 MediaElement 的 fla 项目文件挂钩。

IMA 使用 Flash 组件,可以轻松添加到舞台并进行配置。有没有办法将其与 MediaElements.JS 一起使用,而无需使用 Google IMA Flash SDK?

更新

目前,我一直按照 Google 的 IMA 网站 将其 SWC 组件合并到媒体播放器中。

理想情况下,我想简单地从 JavaScript 函数传递一些变量来设置、触发、停止和删除视频广告。

I've managed to incorporate the HTML5 version of Google IMA ads and am trying to hook in with MediaElement's fla project file.

IMA uses a Flash Component which can be easily added to stage and configured. Is there any way to use this with MediaElements.JS without resorting to using the Google IMA Flash SDK?

UPDATE:

Currently I've been following directions from Google's IMA site on incorporating their swc component into media players.

Ideally I would like to simply pass a few variables from a JavaScript function to set, trigger, stop and remove video ads.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的她 2024-12-31 19:57:27

好吧,既然没有人知道或愿意回答,..

根据 MediaElement.JS 的网站,将会有很快就会有关于后贴片的教程。每当出现这种情况时(或者如果我在此之前开始处理此 ActionScript),我都会在此处发布预卷版本。

更新:

最终我们找到了答案。有一些内容需要添加到媒体元素中,特别是在 FlashMediaElement.as 文件中。

第一步是下载并安装 Google IMA ActionScript 3 组件。

接下来打开 MediaElement 的 \src\flash\ 文件夹中的 FlashMediaElement.flaFlashMediaElement.as

在 .FLA 文件中,您需要将 Google IMA 组件添加到舞台,然后将 preroll 标签配置到任意 url。这只是使该字段在 .as 范围内可用。

最后,通过将以下属性添加到 .AS 文件中的 FlashMediaElement 类,开始集成 Google IMA:

    // Google Ad Object
    private var ads:Object;

    private var ad:Object = {
            type:'',
            url:''
        };

    private var episodeData:Object = {
            pre:ad, post:ad, 
            video:'', 
            pageTitle:'',
            title:'',
            source:''
        };

接下来转到构造函数 public function FlashMediaElement() { 并设置 EpisodeData 的值。您可能希望通过多种方式动态填充这些内容。此示例使用简单的 flashvars 添加到您在 HTML 或 JS 中看到 mediaelement.swf 的位置,使用 mediaelement.swf?title=YourTitle 等。

        // get parameters
        var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
        //Media Element Params start here
        .
        .
        .

        customVariable = (params['customVariable'] != undefined) ? (String(params['customVariable']) : "DefaultStringValue";

在构造函数的末尾,您所要做的就是调用 addEventListener(Event.ADDED_TO_STAGE,initialize);

最后一步是将 Google IMA 示例中的以下函数放入 FlashMediaElement 的末尾班级。

        private function initialize(event:Event):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, initialize);
            // videoComponent is the name of the Google In-Stream component instance
            // on the stage.
            log("component version: " + videoComponent.getVersion());
            videoComponent.addEventListener("adStart", onAdStart);
            videoComponent.addEventListener("adComplete", onAdComplete);
            // Attach event listeners to the video component for access
            // to the ads object. The ads object is used for various purposes
            // such as resetting ads across multiple content pieces.
            videoComponent.addEventListener("adsReady", onAdsReady);
            videoComponent.addEventListener("error", onAdError);
            // Attach event listener to the flvplayback component to listen to
            // the content complete event.
            _video.addEventListener("complete", onContentComplete);
        }

            private function onAdsReady(event:Object):void {
              // Extract the ads object from the adsReady event which is later used to
              // reset the ads.
              // The adsReady event is fired when the ads requested through the
              // component are initialized.
            AdSlotSettings.prerollAdTag = episodeData.pre.url;
            ads = event.getAds();
            }

            private function onContentComplete(event:Event):void {
              log("Content complete");
              if (ads) {
            log("Resetting ads.");
            ads.resetAds();
              }
            }

            private function onAdStart(event:Object):void {
              log("Ad has started.");
            }

            private function onAdComplete(event:Object):void {
                log("Ad has completed."); 
            }

            private function onAdError(event:Object):void {
              log("Error occured while playing the ad. Error : "
              + event.getError().message);
            }

            private function log(msg:Object):void {
              //textAreaLogger.appendText(msg + "\n");
            }

textAreaLogger 指的是 Google 示例中的动态文本字段。为了与 Google 的代码稍有不同,如果您想使用 MediaElement 的内置调试文本窗口,可以将 textAreaLogger 更改为 _output(有时在构造函数中设置 debug=true)。

就这样吧; Google IMA 预贴片和后贴片。

Well since no one knows or is willing to answer,..

According to MediaElement.JS's website, there will soon be a tutorial on postrolls. Whenever that hits (or if I get to working on this ActionScript before then) I will post a preroll version here.

UPDATE:

Eventually we just figured it out. There are a few things which need to be added to Media Element, especially in the FlashMediaElement.as file.

First step is to download and install the Google IMA ActionScript 3 component.

Next open FlashMediaElement.fla and FlashMediaElement.as in MediaElement's \src\flash\ folder.

In the .FLA file, you need to add the Google IMA component to the stage, then configure the preroll tag to any url. This simply makes that field available in the .as scope.

Finally begin to integrate Google IMA by adding the following properties to the FlashMediaElement class in the .AS file:

    // Google Ad Object
    private var ads:Object;

    private var ad:Object = {
            type:'',
            url:''
        };

    private var episodeData:Object = {
            pre:ad, post:ad, 
            video:'', 
            pageTitle:'',
            title:'',
            source:''
        };

Next up go to the constructor, public function FlashMediaElement() { and set the values for episodeData. There are a number of ways you may want to fill these dynamically. This example is using simple flashvars added on where you see mediaelement.swf in your HTML or JS use mediaelement.swf?title=YourTitle and so on.

        // get parameters
        var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
        //Media Element Params start here
        .
        .
        .

        customVariable = (params['customVariable'] != undefined) ? (String(params['customVariable']) : "DefaultStringValue";

At the end of the constructor all you have to do is call addEventListener(Event.ADDED_TO_STAGE, initialize);

Finally the last step is to place the following functions from the Google IMA Example into the end of your FlashMediaElement class.

        private function initialize(event:Event):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, initialize);
            // videoComponent is the name of the Google In-Stream component instance
            // on the stage.
            log("component version: " + videoComponent.getVersion());
            videoComponent.addEventListener("adStart", onAdStart);
            videoComponent.addEventListener("adComplete", onAdComplete);
            // Attach event listeners to the video component for access
            // to the ads object. The ads object is used for various purposes
            // such as resetting ads across multiple content pieces.
            videoComponent.addEventListener("adsReady", onAdsReady);
            videoComponent.addEventListener("error", onAdError);
            // Attach event listener to the flvplayback component to listen to
            // the content complete event.
            _video.addEventListener("complete", onContentComplete);
        }

            private function onAdsReady(event:Object):void {
              // Extract the ads object from the adsReady event which is later used to
              // reset the ads.
              // The adsReady event is fired when the ads requested through the
              // component are initialized.
            AdSlotSettings.prerollAdTag = episodeData.pre.url;
            ads = event.getAds();
            }

            private function onContentComplete(event:Event):void {
              log("Content complete");
              if (ads) {
            log("Resetting ads.");
            ads.resetAds();
              }
            }

            private function onAdStart(event:Object):void {
              log("Ad has started.");
            }

            private function onAdComplete(event:Object):void {
                log("Ad has completed."); 
            }

            private function onAdError(event:Object):void {
              log("Error occured while playing the ad. Error : "
              + event.getError().message);
            }

            private function log(msg:Object):void {
              //textAreaLogger.appendText(msg + "\n");
            }

textAreaLogger refers to a dynamic text field in the Google example. To vary slightly from Google's code, you can change textAreaLogger to _output (and set debug=true in the constructor sometimes) if you want to use MediaElement's built in debug text window.

There you go; Google IMA prerolls and postrolls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文