Access Mediaelement.js Player Attributes
I need to access the properties of a MediaElementPlayer object, how can I do this? The website mentions you can access properties like currentTime and paused from the MediaElement
Solution 1:
EDIT
If you want to access the properties of the player you should get the DOM object. MediaElement is just some sort of extension of the element so it still uses the DOM object. So try this:
newMediaElementPlayer($("#myplayer"), /*mejsOptions*/);
var player = document.getElementById('myplayer');
console.log(player.duration());
It is recommended to do this using the events provided, for instance:
<video id="player1" width="320" height="240" poster="poster.jpg" controls="controls"preload="none">
<!-- MP4 for Safari, IE9, iPhone, iPad, Android, and Windows Phone 7 -->
<source type="video/mp4" src="http://mediaelementjs.com/media/echo-hereweare.mp4" />
</video>
player = new MediaElementPlayer('#player1',{
success: function(mediaElement, domObject, player) {
mediaElement.addEventListener('timeupdate', function(e) {
console.log("Duration is " + mediaElement.duration);
console.log("Current time is " + mediaElement.currentTime);
console.log("Volume is " + mediaElement.volume);
});
}
});
you can try it here on jsfiddle
Solution 2:
After a long time of working with MEJS I finally found the answer to this question. The MediaElementPlayer object encapsulates the MediaElement object, which can be accessed like this:
var mejsplayer = newMediaElementPlayer($("#myplayer"), mejsOptions);
setInterval(debug, 1000);
functiondebug() {
console.log("Duration is " + mejsplayer.media.duration);
console.log("Current time is " + mejsplayer.media.currentTime);
console.log("Volume is " + mejsplayer.media.volume);
....
};
Post a Comment for "Access Mediaelement.js Player Attributes"