javascriptmediaelement.js

MediaElement.js Ads not work


I Want to setup Video Ads before playing video with Media ElementJs I Download latest Version of MediaElementJS from : https://github.com/mediaelement/mediaelement/zipball/master

in demo Folder : I edit this Javascript codes:

<script id="mejs-code">
    var mediaElements = document.querySelectorAll('video, audio');

    for (var i = 0, total = mediaElements.length; i < total; i++) {
    var features = ['prevtrack', 'playpause', 'nexttrack', 'current', 'progress', 'duration', 'speed', 'skipback', 'jumpforward',
    'markers', 'volume', 'playlist', 'loop', 'shuffle', 'contextmenu'];
    // To demonstrate the use of Chromecast with audio
    if (mediaElements[i].tagName === 'AUDIO') {
        features.push('chromecast');
    }
    new MediaElementPlayer(mediaElements[i], {
        // This is needed to make Jump Forward to work correctly
        pluginPath: 'https://cdnjs.cloudflare.com/ajax/libs/mediaelement/4.2.3/',
        shimScriptAccess: 'always',
        autoRewind: false,
        features: features,
        currentMessage: 'Now playing:'
    });
}

to these Codes :

<script id="mejs-code">
    var mediaElements = document.querySelectorAll('video, audio');

    for (var i = 0, total = mediaElements.length; i < total; i++) {
    var features = ['prevtrack', 'playpause', 'nexttrack', 'current', 'progress', 'duration', 'speed', 'skipback', 'jumpforward',
    'markers', 'volume', 'playlist', 'loop', 'shuffle', 'contextmenu','ads'];
    // To demonstrate the use of Chromecast with audio
    if (mediaElements[i].tagName === 'AUDIO') {
        features.push('chromecast');
    }
    new MediaElementPlayer(mediaElements[i], {
        // This is needed to make Jump Forward to work correctly
        pluginPath: 'https://cdnjs.cloudflare.com/ajax/libs/mediaelement/4.2.3/',
        shimScriptAccess: 'always',
        autoRewind: false,
        adsPrerollMediaUrl: 'http://media.productionhub.com.s3.amazonaws.com/preroll.mp4',
        adsPrerollAdUrl: 'http://www.github.com/',
        features: features,
        currentMessage: 'Now playing:'
    });
}

But I cant see my VideoAds before Playing the Video Please help me with thanks.


Solution

  • You need to setup the URL for ads using https://github.com/mediaelement/mediaelement-plugins repository, and then adsPrerollMediaUrl should be an array not just a string