oTplayer
HTML5 audio/video player for oTranscribe. Requires jQuery and progressor.js.
oTplayer is a bring-your-own-interface component.
The Fork
My fork is a quick and dirty edition, having on-board all the things required to use the player offline in a basic HTML UI.
Instructions to run oTplayer out of the box
Assumption: you have already cloned this repository.
-
Open
examples/basic-player.htmlin your browser. -
Provide the URL to your local file in the following format:
file:///C:/Users/.../path/to/file.mp4
- Hit Enter. That's it!
---
How to use
With a parent element (in this case, a div with class '.player-container') and a media source (either a URL, or an HTML5 File object from local upload):
var config = {
source: 'http://example.com/my-file.mp3',
container: document.querySelector('.player-container')
}
var player = new oTplayer(config);This won't do a whole lot without adding your own interface, which can then be linked up to the methods below.
Options
In addition to source and player, there are many potential options to add to the configuration object.
source: HTML5 File object or media URL. Required.container: DOM element (eg. grabbed usingquerySelector). Required.startpoint: Time in seconds at which the media should start. Default:0skipTime: The number of seconds the player should skip forward/back. Default:1.5speedIncrement: Factor of speed increase/decrease step. Default:0.25speedMax: Maximum speed allowed. Normal speed is1. Default:2speedMin: Minimum speed allowed. Default:0.5buttons: Sub-object of selectors (or elements):playPause: Is given class nameplayingduring playback, and is clickable to start/stop.speedSlider: HTML input element withtype="range". Becomes linked with current speed and max/min/steps are modified to match settings.
onReady: Callback function for when ready to use.onChange(name): Callback function when there is a change of state (eg. speed changes, play/pause, skip forward). Argument is the name of function which called it, as a string.onDisableSpeedChange: Callback function only triggered when speed changing is disabled (primarily for certain YouTube videos).rewindOnPlay: If true, will triggerskip('back')when resuming. Default:true
Methods
These can be used with an initialised oTplayer object. For example:
// setup
var config = {
source: 'http://example.com/my-file.mp3',
container: document.querySelector('.player-container')
}
var player = new oTplayer(config);
// using methods
player.play();
var duration = player.getDuration();
player.skipTo( 42 );
player.reset();playPause(): Play or pause media, depending on current playback state.play(): Play media.pause(): Pause media.skipTo(seconds): Skip to a point in media, in seconds.skip(direction): Jump either'backwards'or'forwards'in time, as determined byskipTimeoption.speed(newSpeed): Speed playback'up'or'down', or'reset'to return to1. Can also enter a number instead (eg.0.5,2).getSpeed(): Get current playback speed.1is normal speed.getTime(): Get current playback time, in seconds.setTime(seconds): Alias forskipTo().getDuration(): Get length of media, in seconds.parseYoutubeURL(url): Returns true ifurlargument is a valid YouTube URL. Can be used from uninitialisedoTplayerobject.reset(): Return element to original state.oTplayerobject will no longer be usable.remove(): Alias forreset().
Read-only properties
These can be accessed in a similar manner to methods:
// assuming it's already been set up...
player.paused; // true
player.play();
player.paused; // falseprogressBar: Instance ofprogressor.js, if you need to access it.speedChangeDisabled: Istrueif speed change is disabled (eg. in some YouTube videos).paused: Istrueif playback is currently paused.
Browser support
This should work with anything that supports the File API.
Building dist folder
- Install Node and npm and Grunt
- Run
npm install - Run
grunt
Running tests
- Build dist folder
- Run
grunt test
Version history
v1.1.1
May 21, 2016
- Allow 'back' as option for skip() method
v1.1.0
May 26, 2015
- Add getSpeed() method
- Bugfixes
v1.0.0
May 25, 2015
- Initial release