HTML5 audio/video player for oTranscribe. Requires jQuery and progressor.js.
oTplayer is a bring-your-own-interface component. See this demo for an example of a very basic GUI player.
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.
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:0
skipTime
: The number of seconds the player should skip forward/back. Default:1.5
speedIncrement
: Factor of speed increase/decrease step. Default:0.25
speedMax
: Maximum speed allowed. Normal speed is1
. Default:2
speedMin
: Minimum speed allowed. Default:0.5
buttons
: Sub-object of selectors (or elements):playPause
: Is given class nameplaying
during 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
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 byskipTime
option.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.1
is normal speed.getTime()
: Get current playback time, in seconds.setTime(seconds)
: Alias forskipTo()
.getDuration()
: Get length of media, in seconds.parseYoutubeURL(url)
: Returns true ifurl
argument is a valid YouTube URL. Can be used from uninitialisedoTplayer
object.reset()
: Return element to original state.oTplayer
object will no longer be usable.remove()
: Alias forreset()
.
These can be accessed in a similar manner to methods:
// assuming it's already been set up...
player.paused; // true
player.play();
player.paused; // false
progressBar
: Instance ofprogressor.js
, if you need to access it.speedChangeDisabled
: Istrue
if speed change is disabled (eg. in some YouTube videos).paused
: Istrue
if playback is currently paused.
This should work with anything that supports the File API.
- Install Node and npm and Grunt
- Run
npm install
- Run
grunt
- Build dist folder
- Run
grunt test
May 21, 2016
- Allow 'back' as option for skip() method
May 26, 2015
- Add getSpeed() method
- Bugfixes
May 25, 2015
- Initial release