From 7b17c4698789c038cd045cb6fcff0acd50a6caed Mon Sep 17 00:00:00 2001 From: wvffle Date: Fri, 7 Oct 2022 15:22:22 +0000 Subject: [PATCH] Create audio system based on Web Audio API --- .yarnrc | 1 + front/package.json | 1 + front/public/embed.html | 6 +- front/src/components/audio/Player.vue | 21 +- front/src/composables/audio/audio-api.ts | 36 + front/src/composables/audio/player.ts | 33 + front/src/composables/audio/tracks.ts | 133 +++ front/src/composables/audio/usePlayer.ts | 1 - front/yarn.lock | 1126 +++++++++------------- 9 files changed, 655 insertions(+), 703 deletions(-) create mode 100644 .yarnrc create mode 100644 front/src/composables/audio/audio-api.ts create mode 100644 front/src/composables/audio/player.ts create mode 100644 front/src/composables/audio/tracks.ts diff --git a/.yarnrc b/.yarnrc new file mode 100644 index 000000000..1be5bccd1 --- /dev/null +++ b/.yarnrc @@ -0,0 +1 @@ +--cwd front diff --git a/front/package.json b/front/package.json index fdd077ed7..dd8f9a0ce 100644 --- a/front/package.json +++ b/front/package.json @@ -38,6 +38,7 @@ "qs": "6.11.0", "sass": "1.54.9", "showdown": "2.1.0", + "standardized-audio-context": "^25.3.32", "text-clipper": "2.2.0", "transliteration": "2.3.5", "universal-cookie": "4.0.4", diff --git a/front/public/embed.html b/front/public/embed.html index 96551b87a..96c85a992 100644 --- a/front/public/embed.html +++ b/front/public/embed.html @@ -72,8 +72,10 @@ // NOTE: Add a transcoded MP3 src at the end for browsers // that do not support other codecs to be able to play it :) - if (sources.length > 0 && !sources.some(({ type }) => type === 'audio/mpeg')) { - sources.push({ mimetype: 'audio/mpeg', listen_url: `${sources[0].listen_url}?to=mp3` }) + if (sources.length > 0 && !sources.some(({ mimetype }) => mimetype === 'audio/mpeg')) { + const url = new URL(sources[0].listen_url) + url.searchParams.set('to', 'mp3') + sources.push({ mimetype: 'audio/mpeg', listen_url: url.toString() }) } return sources diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index f060839aa..a8d9c75b2 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -1,14 +1,17 @@