diff --git a/CHANGES.md b/CHANGES.md index b7a1a41f..49fa8a80 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,14 @@ videojs-wavesurfer changelog ============================ +2.4.0 - unreleased +------------------ + +- Add plugin style `vjs-wavesurfer` and prefix all custom plugin styles with + this selector. This should prevent clashes with regular video.js players + loaded on the same page + + 2.3.2 - 2018/05/07 ------------------ diff --git a/karma.conf.js b/karma.conf.js index 0aa9a9ed..00827516 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -92,7 +92,7 @@ module.exports = function(config) { reporters: ['verbose', 'progress', 'coverage'], coverageReporter: { type: 'html', - dir: 'coverage/' + dir: 'coverage' }, webpack: webpackConfig, customLaunchers: { diff --git a/src/css/fluid.scss b/src/css/fluid.scss index bd9ae6cc..7946b740 100644 --- a/src/css/fluid.scss +++ b/src/css/fluid.scss @@ -1,7 +1,7 @@ /* Handle responsive / fluid view. -------------------------------------------------------------------------------- */ -.videojs-wavesurfer.vjs-fluid wave.vjs-wavedisplay { +.vjs-wavesurfer.vjs-fluid wave.vjs-wavedisplay { top: 0; position: absolute!important; width: 100%; diff --git a/src/css/main.scss b/src/css/main.scss index fa546230..af6af9e5 100644 --- a/src/css/main.scss +++ b/src/css/main.scss @@ -1,7 +1,7 @@ /* Position fullscreen control on right side of the player. -------------------------------------------------------------------------------- */ -.video-js.videojs-wavesurfer .vjs-control.vjs-fullscreen-control { +.video-js.vjs-wavesurfer .vjs-control.vjs-fullscreen-control { position: absolute; right: 0; } @@ -11,14 +11,14 @@ controls. -------------------------------------------------------------------------------- */ -.videojs-wavesurfer .vjs-using-native-controls .vjs-control-bar { +.vjs-wavesurfer .vjs-using-native-controls .vjs-control-bar { display: flex !important; } /* Ensure playToggle has pointer cursor. -------------------------------------------------------------------------------- */ -.videojs-wavesurfer button.vjs-play-control.vjs-control.vjs-button { +.vjs-wavesurfer button.vjs-play-control.vjs-control.vjs-button { cursor: pointer; } @@ -26,10 +26,10 @@ closed captions button). -------------------------------------------------------------------------------- */ -.videojs-wavesurfer .vjs-menu-content { +.vjs-wavesurfer .vjs-menu-content { z-index: 1; } -.videojs-wavesurfer .vjs-modal-dialog, .vjs-text-track-display { +.vjs-wavesurfer .vjs-modal-dialog, .vjs-text-track-display { z-index: 4; } diff --git a/src/js/tech.js b/src/js/tech.js deleted file mode 100644 index 603987db..00000000 --- a/src/js/tech.js +++ /dev/null @@ -1,169 +0,0 @@ -/** - * @file tech.js - * @since 2.1.0 - */ - -const Html5 = videojs.getTech('Html5'); - -class WavesurferTech extends Html5 { - /** - * Create an instance of this Tech. - * - * @param {Object} [options] - * The key/value store of player options. - * - * @param {Component~ReadyCallback} ready - * Callback function to call when the `Flash` Tech is ready. - */ - constructor(options, ready) { - // never allow for native text tracks, because this isn't actually - // HTML5 audio. Native tracks fail because we are using wavesurfer - options.nativeTextTracks = false; - - super(options, ready); - } - - setActivePlayer(player) { - // we need the player instance so that we can access the current - // wavesurfer plugin attached to that player - this.activePlayer = player; - this.waveready = false; - - // track when wavesurfer is fully initialized (ready) - this.activePlayer.on('waveReady', () => { - this.waveready = true; - }); - - if (!this.playerIsUsingWavesurfer()) { - // the plugin hasn't been initialized for this player, so it - // likely doesn't need our html5 tech modifications - return; - } - - // proxy timeupdate events so that the tech emits them too. This will - // allow the rest of videoJS to work (including text tracks) - this.activePlayer.activeWavesurferPlugin.on('timeupdate', () => { - this.trigger('timeupdate'); - }); - } - - /** - * Determine whether or not the player is trying use the wavesurfer plugin - * @returns {boolean} - */ - playerIsUsingWavesurfer() - { - let availablePlugins = videojs.getPlugins(); - let usingWavesurferPlugin = 'wavesurfer' in availablePlugins; - let usingRecordPlugin = 'record' in availablePlugins; - - return usingWavesurferPlugin && !usingRecordPlugin; - } - - /** - * Start playback. - */ - play() { - if (!this.playerIsUsingWavesurfer()) { - // fall back to html5 tech functionality - return super.play(); - } - - return this.activePlayer.activeWavesurferPlugin.play(); - } - - /** - * Pause playback. - */ - pause() { - if (!this.playerIsUsingWavesurfer()) { - //fall back to html5 tech functionality - return super.pause(); - } - - return this.activePlayer.activeWavesurferPlugin.pause(); - } - - /** - * Get the current time - * @return {number} - */ - currentTime() { - if (!this.playerIsUsingWavesurfer()) { - // fall back to html5 tech functionality - return super.currentTime(); - } - - if (!this.waveready) { - return 0; - } - - return this.activePlayer.activeWavesurferPlugin.getCurrentTime(); - } - - /** - * Get the current duration - * - * @return {number} - * The duration of the media or 0 if there is no duration. - */ - duration() { - if (!this.playerIsUsingWavesurfer()) { - // fall back to html5 tech functionality - return super.duration(); - } - - if (!this.waveready) { - return 0; - } - - return this.activePlayer.activeWavesurferPlugin.getDuration(); - } - - /** - * Set the current time - * - * @since 2.1.1 - * @param {number} time - * @returns {*} - */ - setCurrentTime(time) { - if (!this.playerIsUsingWavesurfer()) { - // fall back to html5 tech functionality - return super.currentTime(time); - } - - if (!this.waveready) { - return 0; - } - - return this.activePlayer.activeWavesurferPlugin.surfer.seekTo( - time / this.activePlayer.activeWavesurferPlugin.surfer.getDuration()); - } - - /** - * Sets the current playback rate. A playback rate of - * 1.0 represents normal speed and 0.5 would indicate half-speed - * playback, for instance. - * - * @since 2.1.1 - * @param {number} [rate] - * New playback rate to set. - * - * @return {number} - * The current playback rate when getting or 1.0 - */ - setPlaybackRate(rate) { - if (this.playerIsUsingWavesurfer()) { - this.activePlayer.activeWavesurferPlugin.surfer.setPlaybackRate(rate); - } - - return super.setPlaybackRate(rate); - } -} - -WavesurferTech.isSupported = function() { - return true; -}; - -export default WavesurferTech; diff --git a/src/js/videojs.wavesurfer.js b/src/js/videojs.wavesurfer.js index 2280f838..6bd45463 100644 --- a/src/js/videojs.wavesurfer.js +++ b/src/js/videojs.wavesurfer.js @@ -8,7 +8,6 @@ import log from './utils/log'; import formatTime from './utils/format-time'; import pluginDefaultOptions from './defaults'; -import WavesurferTech from './tech'; import window from 'global/window'; import videojs from 'video.js'; @@ -34,6 +33,9 @@ class Wavesurfer extends Plugin { constructor(player, options) { super(player, options); + // add plugin style + player.addClass('vjs-wavesurfer'); + // parse options options = videojs.mergeOptions(pluginDefaultOptions, options); this.waveReady = false; @@ -42,15 +44,8 @@ class Wavesurfer extends Plugin { this.debug = (options.debug.toString() === 'true'); this.msDisplayMax = parseFloat(options.msDisplayMax); - // attach this instance to the current player so that the tech can - // access it - this.player.activeWavesurferPlugin = this; - - // check that wavesurfer is initialized in options, and add class to - // activate videojs-wavesurfer specific styles - if (this.player.options_.plugins.wavesurfer !== undefined) { - this.player.addClass('videojs-wavesurfer'); - } + var tracks = player.textTracks(); + console.log('tracks', tracks); // microphone plugin if (options.src === 'live') { @@ -74,9 +69,6 @@ class Wavesurfer extends Plugin { * Player UI is ready: customize controls. */ initialize() { - // setup tech - this.player.tech_.setActivePlayer(this.player); - // hide big play button this.player.bigPlayButton.hide(); @@ -767,11 +759,6 @@ if (videojs.getPlugin('wavesurfer') === undefined) { videojs.registerPlugin('wavesurfer', Wavesurfer); } -// register the WavesurferTech as 'Html5' to override the default html5 tech. -// If we register it as anything other then 'Html5', the