$media API
$media has a very simple and intuitive API, based in jQuery API, so you will know use it in few minutes.
To inicialize a new $media element, you can use the construct $media or the jQuery function $.media:
//Using jQuery:
var video = $.media('#my-video');
//Using the construct function
var video = $media(document.getElementById('my-video'));
Properties of $media
Once the $media instance is created you can access to following properties:
- element
- The html video/audio element
- $element
- The jQuery video/audio element
- type
- The type of element: "video" or "audio"
- seek_points
- The stored seek points
- fragments
- The fragment info
Accessing to $media properties
var video = $.media('#my-video');
var video_element = video.element;
Prototypes
$media prototypes the objects "String" and "Number" with two new functions: "toSeconds" and "secondsTo". The internal time unit is the second, so sometimes you need convert some time values to seconds or convert seconds to other format.
The available formats are:
- ms
- The time in miliseconds
- mm:ss
- The time in minutes:seconds
- hh:mm:ss
- The time in hours:minutes:seconds
- hh:mm:ss.ms
- The time in hours:minutes:seconds.miliseconds
var time1 = 4.569.secondsTo('hh:mm:ss'); //Returns 00:00:04
var time2 = "4.569".secondsTo('hh:mm:ss.ms'); //Returns 00:00:04.569
var time3 = '00:01:10'.toSeconds(); //Returns 70
The $media methods
You have a complete list of its methods in the left menu.