From abe9ca19f0cd810af5687de82534643bd935ac9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Fri, 25 Dec 2020 22:02:14 +0100 Subject: [PATCH 1/2] Define playlist in playlist.json --- index.html | 21 +++++++++++---------- playlist.json | 12 ++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 playlist.json diff --git a/index.html b/index.html index 99c612f..6e90376 100644 --- a/index.html +++ b/index.html @@ -29,16 +29,17 @@ // test image for web notifications var iconImage = null; - AP.init({ - container:'#player',//a string containing one CSS selector - volume : 0.7, - autoPlay : true, - notification: false, - playList: [ - {'icon': iconImage, 'title': 'Try Everything', 'file': 'mp3/try-everything.mp3'}, - {'icon': iconImage, 'title': 'Let It Go', 'file': 'mp3/let-it-go.mp3'} - ] - }); + fetch("playlist.json") + .then(response => response.json()) + .then(playList => { + AP.init({ + container:'#player',//a string containing one CSS selector + volume : 0.7, + autoPlay : true, + notification: false, + playList: playList + }); + }) diff --git a/playlist.json b/playlist.json new file mode 100644 index 0000000..6556a33 --- /dev/null +++ b/playlist.json @@ -0,0 +1,12 @@ +[ + { + "file" : "mp3/try-everything.mp3", + "icon" : null, + "title" : "Try Everything" + }, + { + "icon" : null, + "title" : "Let It Go", + "file" : "mp3/let-it-go.mp3" + } +] From 06d6f793d125306d649919a357aa95827ac03aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 26 Dec 2020 08:01:34 +0100 Subject: [PATCH 2/2] Handle load errors --- index.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 6e90376..c03fdc5 100644 --- a/index.html +++ b/index.html @@ -30,7 +30,13 @@ var iconImage = null; fetch("playlist.json") - .then(response => response.json()) + .then(response => { + if (response.ok) { + return response.json() + } else { + throw Error('Loading playlist: ' + response.statusText) + } + }) .then(playList => { AP.init({ container:'#player',//a string containing one CSS selector @@ -40,6 +46,7 @@ playList: playList }); }) + .catch(error => alert(error))