summaryrefslogtreecommitdiffstats
path: root/assets/js/player.js
diff options
context:
space:
mode:
authorTheFrenchGhosty <47571719+TheFrenchGhosty@users.noreply.github.com>2021-05-13 10:33:47 +0200
committerGitHub <noreply@github.com>2021-05-13 10:33:47 +0200
commit75e5b49c3ae684096c8074bada846414d2b02b88 (patch)
treece36fcae7db3bf3850ee01ff24bb3b3ce2409cde /assets/js/player.js
parent3cf08dc45163268cee48d045e347eaf7c7be92a6 (diff)
parentd6585d7583018010467cead2956d375067b9acce (diff)
downloadinvidious-75e5b49c3ae684096c8074bada846414d2b02b88.tar.gz
invidious-75e5b49c3ae684096c8074bada846414d2b02b88.tar.bz2
invidious-75e5b49c3ae684096c8074bada846414d2b02b88.zip
Merge pull request #2008 from syeopite/mobile-ui
Improve player controls for mobile devices
Diffstat (limited to 'assets/js/player.js')
-rw-r--r--assets/js/player.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/assets/js/player.js b/assets/js/player.js
index f1429233..a6d0c8c1 100644
--- a/assets/js/player.js
+++ b/assets/js/player.js
@@ -14,6 +14,7 @@ var options = {
'durationDisplay',
'progressControl',
'remainingTimeDisplay',
+ 'Spacer',
'captionsButton',
'qualitySelector',
'playbackRateMenuButton',
@@ -73,6 +74,55 @@ if (location.pathname.startsWith('/embed/')) {
});
}
+// Detect mobile users and initalize mobileUi for better UX
+// Detection code taken from https://stackoverflow.com/a/20293441
+
+function isMobile() {
+ try{ document.createEvent("TouchEvent"); return true; }
+ catch(e){ return false; }
+}
+
+if (isMobile()) {
+ player.mobileUi();
+
+ buttons = ["playToggle", "volumePanel", "captionsButton"];
+
+ if (video_data.params.quality !== 'dash') {
+ buttons.push("qualitySelector")
+ }
+
+ // Create new control bar object for operation buttons
+ const ControlBar = videojs.getComponent("controlBar");
+ let operations_bar = new ControlBar(player, {
+ children: [],
+ playbackRates: [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
+ });
+ buttons.slice(1).forEach(child => operations_bar.addChild(child))
+
+ // Remove operation buttons from primary control bar
+ primary_control_bar = player.getChild("controlBar");
+ buttons.forEach(child => primary_control_bar.removeChild(child));
+
+ operations_bar_element = operations_bar.el();
+ operations_bar_element.className += " mobile-operations-bar"
+ player.addChild(operations_bar)
+
+ // Playback menu doesn't work when its initalized outside of the primary control bar
+ playback_element = document.getElementsByClassName("vjs-playback-rate")[0]
+ operations_bar_element.append(playback_element)
+
+ // The share and http source selector element can't be fetched till the players ready.
+ player.one("playing", () => {
+ share_element = document.getElementsByClassName("vjs-share-control")[0]
+ operations_bar_element.append(share_element)
+
+ if (video_data.params.quality === 'dash') {
+ http_source_selector = document.getElementsByClassName("vjs-http-source-selector vjs-menu-button")[0]
+ operations_bar_element.append(http_source_selector)
+ }
+ })
+}
+
player.on('error', function (event) {
if (player.error().code === 2 || player.error().code === 4) {
setTimeout(function (event) {