user1822240
user1822240

Reputation: 41

Requirejs with media element error

I am using require.js to load my js files and I am attempting to load mediaelementplayer but I am receiving two errors. mejs is not defined and object has no method. Is there a way I can delay this file to load even though jQuery is loading first and media element has jQuery as a dependency? I have tried to put it in the jquery load function but that didn't change anything. Error

Upvotes: 1

Views: 2053

Answers (1)

stone
stone

Reputation: 2202

The MediaElementPlayer as written has a dependency on jquery, hence shim accordingly (i.e jquery before mes!!)

requirejs.config({
    "paths": {
        "jquery" : "libs/jquery/jquery-1.10.2.min",
        "mes" : "libs/mes/mediaelement-and-player.min"
    },
    shim: {
        'jquery': {
            exports: '$'
        },
        'mes' : ['jquery']
    }
});

Then

require(["jquery","mes"], function($){
   $('video').mediaelementplayer({});
});

Hope it helps some one else searching for this. If you are working on IE6-9 you probably need html5shiv

Upvotes: 1

Related Questions