forked from FreeTubeApp/FreeTube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autoplay toggle to the video player (FreeTubeApp#5866)
* Add autoplay toggle to the video player * Fix (pre-existing) bug where mobile Shaka overflow menu overflows into top nav bar * Update confusing autoplay labels to use consistent language * Update src/renderer/components/ft-shaka-video-player/player-components/AutoplayToggle.js Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> * Have autoplay toggle value update when setting updates elsewhere, e.g., in another window * Apply suggestions from code review Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> * Remove now-redundant playlist pause feature * Update overflow width threshold --------- Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
- Loading branch information
1 parent
89d163e
commit 67102f1
Showing
13 changed files
with
186 additions
and
109 deletions.
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
79 changes: 79 additions & 0 deletions
79
src/renderer/components/ft-shaka-video-player/player-components/AutoplayToggle.js
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,79 @@ | ||
import shaka from 'shaka-player' | ||
|
||
import i18n from '../../../i18n/index' | ||
|
||
export class AutoplayToggle extends shaka.ui.Element { | ||
/** | ||
* @param {boolean} autoplayEnabled | ||
* @param {EventTarget} events | ||
* @param {HTMLElement} parent | ||
* @param {shaka.ui.Controls} controls | ||
*/ | ||
constructor(autoplayEnabled, events, parent, controls) { | ||
super(parent, controls) | ||
|
||
/** @private */ | ||
this.button_ = document.createElement('button') | ||
this.button_.classList.add('autoplay-toggle') | ||
this.button_.classList.add('shaka-tooltip') | ||
|
||
/** @private */ | ||
this.icon_ = document.createElement('i') | ||
this.icon_.classList.add('material-icons-round') | ||
this.icon_.textContent = 'pause_circle' | ||
|
||
this.button_.appendChild(this.icon_) | ||
|
||
const label = document.createElement('label') | ||
label.classList.add('shaka-overflow-button-label') | ||
label.classList.add('shaka-overflow-menu-only') | ||
|
||
/** @private */ | ||
this.nameSpan_ = document.createElement('span') | ||
label.appendChild(this.nameSpan_) | ||
|
||
/** @private */ | ||
this.currentState_ = document.createElement('span') | ||
this.currentState_.classList.add('shaka-current-selection-span') | ||
label.appendChild(this.currentState_) | ||
|
||
this.button_.appendChild(label) | ||
|
||
this.parent.appendChild(this.button_) | ||
|
||
/** @private */ | ||
this.autoplayEnabled_ = autoplayEnabled | ||
|
||
// listeners | ||
|
||
this.eventManager.listen(this.button_, 'click', () => { | ||
events.dispatchEvent(new CustomEvent('toggleAutoplay', { | ||
detail: !this.autoplayEnabled_ | ||
})) | ||
}) | ||
|
||
const handleAutoplayValueChange = (/** @type {CustomEvent} */ event) => { | ||
this.autoplayEnabled_ = event.detail | ||
this.updateLocalisedStrings_() | ||
} | ||
|
||
this.eventManager.listen(events, 'setAutoplay', handleAutoplayValueChange) | ||
|
||
this.eventManager.listen(events, 'localeChanged', () => { | ||
this.updateLocalisedStrings_() | ||
}) | ||
|
||
this.updateLocalisedStrings_() | ||
} | ||
|
||
/** @private */ | ||
updateLocalisedStrings_() { | ||
this.nameSpan_.textContent = i18n.t('Video.Autoplay') | ||
|
||
this.icon_.textContent = this.autoplayEnabled_ ? 'play_circle' : 'pause_circle' | ||
|
||
this.currentState_.textContent = this.localization.resolve(this.autoplayEnabled_ ? 'ON' : 'OFF') | ||
|
||
this.button_.ariaLabel = this.autoplayEnabled_ ? i18n.t('Video.Player.Autoplay is on') : i18n.t('Video.Player.Autoplay is off') | ||
} | ||
} |
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.