mirror of
https://github.com/VueTubeApp/VueTube
synced 2024-11-17 16:55:12 +00:00
Merge pull request #290 from etekweb/handle-rotation
Enter fullscreen on device rotation, vertical fullscreen mode
This commit is contained in:
commit
2dc1ddaa15
1 changed files with 65 additions and 24 deletions
|
@ -8,6 +8,7 @@
|
||||||
}"
|
}"
|
||||||
class="d-flex flex-column"
|
class="d-flex flex-column"
|
||||||
style="position: relative"
|
style="position: relative"
|
||||||
|
:style="{ height: isFullscreen ? '100vh' : 'auto' }"
|
||||||
>
|
>
|
||||||
<video
|
<video
|
||||||
ref="player"
|
ref="player"
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
}"
|
}"
|
||||||
poster="https://media.discordapp.net/attachments/970793575153561640/974728851441729556/bam.png"
|
poster="https://media.discordapp.net/attachments/970793575153561640/974728851441729556/bam.png"
|
||||||
@click="controlsHandler()"
|
@click="controlsHandler()"
|
||||||
|
@loadedmetadata="checkDimensions()"
|
||||||
/>
|
/>
|
||||||
<!-- // NOTE: replace poster URL with "none" -->
|
<!-- // NOTE: replace poster URL with "none" -->
|
||||||
|
|
||||||
|
@ -178,7 +180,7 @@
|
||||||
<fullscreen
|
<fullscreen
|
||||||
style="z-index: 2"
|
style="z-index: 2"
|
||||||
:fullscreen="isFullscreen"
|
:fullscreen="isFullscreen"
|
||||||
@fullscreen="fullscreenHandler()"
|
@fullscreen="fullscreenHandler(true)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<!-- time & fullscreen row end -->
|
<!-- time & fullscreen row end -->
|
||||||
|
@ -308,6 +310,9 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isFullscreen: false,
|
isFullscreen: false,
|
||||||
|
fullscreenLock: false,
|
||||||
|
verticalFullscreen: false,
|
||||||
|
midRotation: false,
|
||||||
controls: false,
|
controls: false,
|
||||||
seeking: false,
|
seeking: false,
|
||||||
contain: true,
|
contain: true,
|
||||||
|
@ -317,6 +322,7 @@ export default {
|
||||||
watched: 0,
|
watched: 0,
|
||||||
blocks: [],
|
blocks: [],
|
||||||
vidSrc: "",
|
vidSrc: "",
|
||||||
|
isVerticalVideo: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -361,10 +367,15 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// TODO: detect orientation change and enter fullscreen
|
},
|
||||||
|
created() {
|
||||||
|
screen.orientation.addEventListener("change", () =>
|
||||||
|
this.fullscreenHandler(false)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.isFullscreen) this.exitFullscreen();
|
if (this.isFullscreen) this.exitFullscreen();
|
||||||
|
screen.orientation.removeEventListener("change");
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// TODO: make accumulative onclick after first dblclick (don't set timeout untill stopped clicking)
|
// TODO: make accumulative onclick after first dblclick (don't set timeout untill stopped clicking)
|
||||||
|
@ -395,35 +406,65 @@ export default {
|
||||||
this.$refs.player.src = q;
|
this.$refs.player.src = q;
|
||||||
this.$refs.player.currentTime = time;
|
this.$refs.player.currentTime = time;
|
||||||
},
|
},
|
||||||
fullscreenHandler() {
|
checkDimensions() {
|
||||||
if (document?.fullscreenElement === this.$refs.vidcontainer) {
|
if (this.$refs.player.videoHeight > this.$refs.player.videoWidth) {
|
||||||
this.exitFullscreen();
|
this.isVerticalVideo = true;
|
||||||
} else {
|
} else {
|
||||||
this.openFullscreen();
|
this.isVerticalVideo = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
exitFullscreen() {
|
fullscreenHandler(pressedFullscreenBtn) {
|
||||||
const cancellFullScreen =
|
// Prevent fullscreen button press from being handled twice
|
||||||
document.exitFullscreen ||
|
// (once by pressing fullscreen button, another by the resulting rotation)
|
||||||
document.mozCancelFullScreen ||
|
if (this.midRotation) {
|
||||||
document.webkitExitFullscreen ||
|
this.midRotation = false;
|
||||||
document.msExitFullscreen;
|
return;
|
||||||
cancellFullScreen.call(document);
|
}
|
||||||
screen.orientation.lock("portrait");
|
// Toggle fullscreen state
|
||||||
|
if (this.isFullscreen) {
|
||||||
|
this.exitFullscreen(pressedFullscreenBtn);
|
||||||
|
} else {
|
||||||
|
this.enterFullscreen(pressedFullscreenBtn);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exitFullscreen(unlock) {
|
||||||
|
if (unlock) {
|
||||||
|
if (this.verticalFullscreen) {
|
||||||
|
// Unset vertical fullscreen mode
|
||||||
screen.orientation.unlock();
|
screen.orientation.unlock();
|
||||||
|
this.fullscreenLock = false;
|
||||||
|
this.verticalFullscreen = false;
|
||||||
|
} else {
|
||||||
|
// Unset standard fullscreen mode
|
||||||
|
this.midRotation = true;
|
||||||
|
screen.orientation.lock("portrait");
|
||||||
|
this.fullscreenLock = true;
|
||||||
|
// Locks the rotation to portrait for two seconds,
|
||||||
|
// and will then rotate back to landscape if the
|
||||||
|
// user doesn't rotate first
|
||||||
|
setTimeout(() => {
|
||||||
|
this.fullscreenLock = false;
|
||||||
|
screen.orientation.unlock();
|
||||||
|
}, 2 * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.$vuetube.navigationBar.show();
|
this.$vuetube.navigationBar.show();
|
||||||
this.$vuetube.statusBar.show();
|
this.$vuetube.statusBar.show();
|
||||||
this.isFullscreen = false;
|
this.isFullscreen = false;
|
||||||
},
|
},
|
||||||
openFullscreen() {
|
enterFullscreen(force) {
|
||||||
const element = this.$refs.vidcontainer;
|
if (force) {
|
||||||
const requestFullScreen =
|
this.fullscreenLock = true;
|
||||||
element.requestFullscreen ||
|
if (this.isVerticalVideo) {
|
||||||
element.webkitRequestFullScreen ||
|
// Vertical fullscreen mode (vertical video only)
|
||||||
element.mozRequestFullScreen ||
|
screen.orientation.lock("portrait");
|
||||||
element.msRequestFullScreen;
|
this.verticalFullscreen = true;
|
||||||
requestFullScreen.call(element);
|
} else {
|
||||||
|
// Standard fullscreen mode
|
||||||
|
this.midRotation = true;
|
||||||
screen.orientation.lock("landscape");
|
screen.orientation.lock("landscape");
|
||||||
|
}
|
||||||
|
}
|
||||||
this.$vuetube.navigationBar.hide();
|
this.$vuetube.navigationBar.hide();
|
||||||
this.$vuetube.statusBar.hide();
|
this.$vuetube.statusBar.hide();
|
||||||
this.isFullscreen = true;
|
this.isFullscreen = true;
|
||||||
|
|
Loading…
Reference in a new issue