From 685902adabb7da522587f6308495701891a8b5fe Mon Sep 17 00:00:00 2001 From: 138138138 <78271024+138138138@users.noreply.github.com> Date: Mon, 1 Feb 2021 15:59:27 +0800 Subject: [PATCH] Update player.js Fixes audio mode duration doubled in iPhone iOS browsers. The player will stop after reaching the real duration. iOS() checks both iOS and iPadOS. Only tested on iPhone iOS browsers. Testers needed for behavior of iPadOS and MacOS. --- assets/js/player.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/assets/js/player.js b/assets/js/player.js index 04326631..3c4188d0 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -547,3 +547,27 @@ window.addEventListener('keydown', e => { if (player.share) { player.share(shareOptions); } + +//iOS audio double duration fix +player.on('loadedmetadata', function () { + if (iOS() && video_data.params.listen) { + player.on('timeupdate', function () { + if (player.remainingTime() < player.duration() / 2) { + player.currentTime(player.duration() + 1); + } + }) + } +}); + +function iOS() { + return [ + 'iPad Simulator', + 'iPhone Simulator', + 'iPod Simulator', + 'iPad', + 'iPhone', + 'iPod' + ].includes(navigator.platform) + // iPad on iOS 13 detection + || (navigator.userAgent.includes("Mac") && "ontouchend" in document) +}