UNPKG

@checksub_team/peaks_timeline

Version:

JavaScript UI component for displaying audio waveforms

79 lines (63 loc) 1.55 kB
/** * @file * * Defines the {@link Player} class. * * @module player */ define([ './utils' ], function(Utils) { 'use strict'; /** * A wrapper for interfacing with the HTML5 media element API. * Initializes the player for a given media element. * * @class * @alias Player * * @param {Peaks} peaks The parent {@link Peaks} object. */ function Player(peaks) { var self = this; self._peaks = peaks; self._currentTime = 0; } /** * Returns the current playback time position, in seconds. * * @returns {Number} */ Player.prototype.getCurrentTime = function() { return this._currentTime; }; /** * Seeks to a given time position within the media. * * @param {Number} time The time position, in seconds. */ Player.prototype.seek = function(time) { if (!this._seek(time)) { return; } this._peaks.emit('timeline.seek', this._currentTime); }; /** * Update the time (variation of seek, with a different event). */ Player.prototype.update = function(time) { if (!this._seek(time)) { return; } this._peaks.emit('timeline.update', this._currentTime); }; Player.prototype._seek = function(time) { if (!Utils.isValidTime(time)) { this._peaks.logger('peaks.player.seek(): parameter must be a valid time, in seconds'); return false; } this._currentTime = Math.max(0, time); return true; }; return Player; });