From 9629fcde68ea56b44e45b2d1697e762f9dbfeb6a Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 15 Nov 2021 02:47:42 +0100 Subject: [PATCH] optionally enable seeking through os controls --- copyparty/web/browser.css | 4 +++- copyparty/web/browser.js | 17 ++++++++++------- copyparty/web/util.js | 5 ++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index dfd0905f..39dcaded 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -876,13 +876,15 @@ html.light #tree.nowrap .ntree a+a:hover { } #thumbs, #au_fullpre, +#au_os_seek, #au_osd_cv, #u2tdate { opacity: .3; } #griden.on+#thumbs, #au_preload.on+#au_fullpre, -#au_os_ctl.on+#au_osd_cv, +#au_os_ctl.on+#au_os_seek, +#au_os_ctl.on+#au_os_seek+#au_osd_cv, #u2turbo.on+#u2tdate { opacity: 1; } diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index f1555db4..9190ec88 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -319,7 +319,8 @@ var mpl = (function () { 'full' + '/np clip' + 'os-ctl' + - 'osd-cv' + + 'seek' + + 'art' + '' + '

playback mode

' + @@ -347,7 +348,8 @@ var mpl = (function () { }; bcfg_bind(r, 'preload', 'au_preload', true); bcfg_bind(r, 'fullpre', 'au_fullpre', false); - bcfg_bind(r, 'osd_cv', 'au_osd_cv', true); + bcfg_bind(r, 'os_seek', 'au_os_seek', !IPHONE, announce); + bcfg_bind(r, 'osd_cv', 'au_osd_cv', true, announce); bcfg_bind(r, 'clip', 'au_npclip', false, function (v) { clmod(ebi('wtoggle'), 'np', v && mp.au); }); @@ -360,7 +362,7 @@ var mpl = (function () { r.os_ctl = !r.os_ctl && have_mctl; bcfg_set('au_os_ctl', r.os_ctl); if (!have_mctl) - toast.err(5, 'need firefox 82+ or chrome 73+\n(or iOS 15+ supposedly)'); + toast.err(5, 'need firefox 82+ or chrome 73+ or iOS 15+'); }; function draw_pb_mode() { @@ -418,7 +420,7 @@ var mpl = (function () { navigator.mediaSession.playbackState = mp.au && !mp.au.paused ? "playing" : "paused"; }; - r.announce = function () { + function announce() { if (!r.os_ctl) return; @@ -460,12 +462,13 @@ var mpl = (function () { navigator.mediaSession.metadata = new MediaMetadata(tags); navigator.mediaSession.setActionHandler('play', playpause); navigator.mediaSession.setActionHandler('pause', playpause); - navigator.mediaSession.setActionHandler('seekbackward', function () { seek_au_rel(-10); }); - navigator.mediaSession.setActionHandler('seekforward', function () { seek_au_rel(10); }); + navigator.mediaSession.setActionHandler('seekbackward', r.os_seek ? function () { seek_au_rel(-10); } : null); + navigator.mediaSession.setActionHandler('seekforward', r.os_seek ? function () { seek_au_rel(10); } : null); navigator.mediaSession.setActionHandler('previoustrack', prev_song); navigator.mediaSession.setActionHandler('nexttrack', next_song); r.pp(); - }; + } + r.announce = announce; r.stop = function () { if (!r.os_ctl || !navigator.mediaSession.metadata) diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 0e47e275..c59e944c 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -7,8 +7,7 @@ if (!window['console']) var is_touch = 'ontouchstart' in window, - IPHONE = /iPhone|iPad|iPod/i.test(navigator.userAgent), - ANDROID = /android/i.test(navigator.userAgent), + IPHONE = is_touch && /iPhone|iPad|iPod/i.test(navigator.userAgent), WINDOWS = navigator.platform ? navigator.platform == 'Win32' : /Windows/.test(navigator.userAgent); @@ -862,7 +861,7 @@ var tt = (function () { r.el.removeEventListener('mouseleave', r.hide); }; - if (is_touch && IPHONE) { + if (IPHONE) { var f1 = r.show, f2 = r.hide, q = [];