-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
playbackRate support #1132
Closed
Closed
playbackRate support #1132
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
524b253
playback API support (thx coursera)
H1D 6ebb5ac
implemented playback rate control (broke tests)
H1D 61eb54a
Replaced webkitRequestFullScreen with webkitReplaceFullscreen
michelt 8630248
Merge remote-tracking branch 'upstream/master'
H1D 1100ce3
check for "playbackRate" support
H1D 3082afa
fixed typo
H1D c5d46c1
Adding tests for playbackRate API
jnwng 778d56f
Merge branch 'master' of github.com:jnwng/video.js into jw/add-playba…
jnwng 2ea98af
Merge pull request #1 from jnwng/jw/add-playbackrate-test
H1D 20798aa
minor fixes for playback rate (coding styles)
H1D a5bc688
Merge branch 'Akkuma-master'
heff adf4e50
Added line to the changelog
heff 269f7b1
Merge branch 'master' of github.com:michelt/video.js into michelt-master
heff ef25557
Added line to changelog
heff dbff62e
Made tap events on mobile less sensitive to touch moves. closes #1111
61696c0
Merge branch 'master' of github.com:StepicOrg/video.js into StepicOrg…
heff 10c5aea
Made updates to #1132 - Playback Rate - to get tests passing
heff 2f4c619
Merge pull request #2 from heff/StepicOrg-master
H1D File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* The component for controlling the playback rate | ||
* | ||
* @param {vjs.Player|Object} player | ||
* @param {Object=} options | ||
* @constructor | ||
*/ | ||
vjs.PlaybackRateMenuButton = vjs.MenuButton.extend({ | ||
/** @constructor */ | ||
init: function(player, options){ | ||
vjs.MenuButton.call(this, player, options); | ||
|
||
this.updateVisibility(); | ||
this.updateLabel(); | ||
|
||
player.on('loadstart', vjs.bind(this, this.updateVisibility)); | ||
player.on('ratechange', vjs.bind(this, this.updateLabel)); | ||
} | ||
}); | ||
|
||
vjs.PlaybackRateMenuButton.prototype.createEl = function(){ | ||
var el = vjs.Component.prototype.createEl.call(this, 'div', { | ||
className: 'vjs-playback-rate vjs-menu-button vjs-control' | ||
}); | ||
|
||
this.contentEl_ = vjs.createEl('div', { | ||
className: 'vjs-playback-rate-value', | ||
innerHTML: 1.0 | ||
}); | ||
el.appendChild(this.contentEl_); | ||
|
||
return el; | ||
}; | ||
|
||
// Menu creation | ||
vjs.PlaybackRateMenuButton.prototype.createMenu = function(){ | ||
var menu = new vjs.Menu(this.player()); | ||
var rates = this.player().options().playbackRates; | ||
|
||
if (rates) { | ||
for (var i = rates.length - 1; i >= 0; i--) { | ||
menu.addChild( | ||
new vjs.PlaybackRateMenuItem(this.player(), {rate: rates[i] + 'x'}) | ||
); | ||
}; | ||
} | ||
|
||
return menu; | ||
}; | ||
|
||
vjs.PlaybackRateMenuButton.prototype.updateARIAAttributes = function(){ | ||
// Current playback rate | ||
this.el().setAttribute('aria-valuenow', this.player().playbackRate()); | ||
}; | ||
|
||
vjs.PlaybackRateMenuButton.prototype.onClick = function(){ | ||
// select next rate option | ||
var currentRate = this.player().playbackRate(); | ||
var rates = this.player().options().playbackRates; | ||
// this will select first one if the last one currently selected | ||
var newRate = rates[0]; | ||
for (var i = 0; i <rates.length ; i++) { | ||
if (rates[i] > currentRate) { | ||
newRate = rates[i]; | ||
break; | ||
} | ||
}; | ||
this.player().playbackRate(newRate); | ||
}; | ||
|
||
vjs.PlaybackRateMenuButton.prototype.playbackRateSupported = function(){ | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got a little too fancy here. :) Should remove the line break after return. |
||
this.player().tech | ||
&& this.player().tech.features['playbackRate'] | ||
&& this.player().options().playbackRates | ||
&& this.player().options().playbackRates.length > 0 | ||
; | ||
}; | ||
|
||
/** | ||
* Hide playback rate controls when they're no playback rate options to select | ||
*/ | ||
vjs.PlaybackRateMenuButton.prototype.updateVisibility = function(){ | ||
if (this.playbackRateSupported()) { | ||
this.removeClass('vjs-hidden'); | ||
} else { | ||
this.addClass('vjs-hidden'); | ||
} | ||
}; | ||
|
||
/** | ||
* Update button label when rate changed | ||
*/ | ||
vjs.PlaybackRateMenuButton.prototype.updateLabel = function(){ | ||
if (this.playbackRateSupported()) { | ||
this.contentEl().innerHTML = this.player().playbackRate() + 'x'; | ||
} | ||
}; | ||
|
||
/** | ||
* The specific menu item type for selecting a playback rate | ||
* | ||
* @constructor | ||
*/ | ||
vjs.PlaybackRateMenuItem = vjs.MenuItem.extend({ | ||
contentElType: 'button', | ||
/** @constructor */ | ||
init: function(player, options){ | ||
var label = this.label = options['rate']; | ||
var rate = this.rate = parseFloat(label, 10); | ||
|
||
// Modify options for parent MenuItem class's init. | ||
options['label'] = label; | ||
options['selected'] = rate === 1; | ||
vjs.MenuItem.call(this, player, options); | ||
|
||
this.player().on('ratechange', vjs.bind(this, this.update)); | ||
} | ||
}); | ||
|
||
vjs.PlaybackRateMenuItem.prototype.onClick = function(){ | ||
vjs.MenuItem.prototype.onClick.call(this); | ||
this.player().playbackRate(this.rate); | ||
}; | ||
|
||
vjs.PlaybackRateMenuItem.prototype.update = function(){ | ||
this.selected(this.player().playbackRate() == this.rate); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought using the component's build in contentEl would make sense for this, but it looks like MenuButton already makes use of contentEl. You might be able to just change that to 'labelEl' or something like that.