googleads / videojs-ima

IMA SDK Plugin for Video.js
Apache License 2.0
450 stars 284 forks source link

set mid-roll timeoffset at 50% of the total video duration #963

Closed MMidali closed 3 years ago

MMidali commented 3 years ago

Hello,

I'm trying to pass a vmap to adsResponse and set the mid-roll timeOffset at 50% of the total video duration.

my code is

let midrollTime;

let player = videojs('my_video',{}, function() {
    this.on('loadedmetadata', () => {
        midrollTime = adjustTime((this.duration() / 2).toFixed(0));
    });
});
const vastPre = '';//vast pre-roll link
const vastMid = '';//vast mid-roll link
const vastPost = '';//vast post-roll link
let vmap = `<vmap:VMAP xmlns:vmap="http://www.iab.net/videosuite/vmap" version="1.0">
    <vmap:AdBreak timeOffset="start" breakType="linear" breakId="preroll">
        <vmap:AdSource id="preroll-ad-1" allowMultipleAds="false" followRedirects="true">
            <vmap:AdTagURI templateType="vast3">
                <![CDATA[ ${vastPre} ]]>
            </vmap:AdTagURI>
        </vmap:AdSource>
    </vmap:AdBreak>
    <vmap:AdBreak timeOffset="${midrollTime}" breakType="linear" breakId="midroll-1">
        <vmap:AdSource id="midroll-1-ad-1" allowMultipleAds="false" followRedirects="true">
            <vmap:AdTagURI templateType="vast3">
                <![CDATA[ ${vastMid} ]]>
            </vmap:AdTagURI>
        </vmap:AdSource>
    </vmap:AdBreak>
    <vmap:AdBreak timeOffset="end" breakType="linear" breakId="postroll">
        <vmap:AdSource id="postroll-ad-1" allowMultipleAds="false" followRedirects="true">
            <vmap:AdTagURI templateType="vast3">
                <![CDATA[ ${vastPost} ]]>
            </vmap:AdTagURI>
        </vmap:AdSource>
    </vmap:AdBreak>
</vmap:VMAP>`;

let imaOptions = {
    adsResponse: vmap,
    debug: true
};

player.ima(imaOptions);

the real problem is that the metadata are loaded after the vmap is being set as adsResponse.

Kiro705 commented 3 years ago

Hello @MMidali ,

The IMA SDK does not support VMAP percentage time offsets, which could have been a simple solution to this issue.

Because of the async nature of this.on('loadedmetadata', () => { ..., is it possible to add the call to player.ima(imaOptions) to the end of the function so it is only called after you have the metadata?

If not, I would recommend using a specific time for your midrolls instead of directly halfway through the content.

Thank you, Jackson IMA SDK DevRel

MMidali commented 3 years ago

I'll try and let you know.

I hope to find a useful solution for other people with the same problem.