ply: restore screen orientation on fullscreen exit (fix #521)
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/563/head
parent
dae5785462
commit
0566075efe
|
@ -402,21 +402,32 @@ class VideoContentSetup {
|
||||||
|
|
||||||
// Add fullscreen orientation hooks
|
// Add fullscreen orientation hooks
|
||||||
if (screen.orientation?.lock) {
|
if (screen.orientation?.lock) {
|
||||||
|
// Store the previous orientation
|
||||||
|
// This is because unlocking (at least on Chrome) does
|
||||||
|
// not restore the previous orientation
|
||||||
|
let previousOrientation: OrientationLockType;
|
||||||
|
|
||||||
|
// Lock orientation when entering fullscreen
|
||||||
plyr.on("enterfullscreen", (event) => {
|
plyr.on("enterfullscreen", (event) => {
|
||||||
const rotation = this.updateRotation(content);
|
const rotation = this.updateRotation(content);
|
||||||
const exif = content.data.photo.imageInfo?.exif;
|
const exif = content.data.photo.imageInfo?.exif;
|
||||||
const h = Number(exif?.ImageHeight || 0);
|
const h = Number(exif?.ImageHeight || 0);
|
||||||
const w = Number(exif?.ImageWidth || 1);
|
const w = Number(exif?.ImageWidth || 1);
|
||||||
|
|
||||||
if (h && w) {
|
if (h && w) {
|
||||||
if (h < w && !rotation) {
|
previousOrientation = screen.orientation.type;
|
||||||
screen.orientation.lock("landscape");
|
const orientation = h < w && !rotation ? "landscape" : "portrait";
|
||||||
} else {
|
screen.orientation.lock(orientation);
|
||||||
screen.orientation.lock("portrait");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Unlock orientation when exiting fullscreen
|
||||||
plyr.on("exitfullscreen", (event) => {
|
plyr.on("exitfullscreen", (event) => {
|
||||||
|
if (previousOrientation) {
|
||||||
|
screen.orientation.lock(previousOrientation);
|
||||||
|
previousOrientation = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
screen.orientation.unlock();
|
screen.orientation.unlock();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue