From b2a6a5d1454954dfb48e2154c0ecf53f2f030083 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Fri, 7 May 2021 11:30:24 +0200 Subject: [PATCH] Custom audio player UI For issue #122. --- src/assets/css/chat.scss | 48 ++++- src/components/messages/AudioPlayer.vue | 185 ++++++++++++++++++ .../messages/MessageIncomingAudio.vue | 7 +- .../messages/MessageOutgoingAudio.vue | 5 +- src/plugins/utils.js | 7 + 5 files changed, 241 insertions(+), 11 deletions(-) create mode 100644 src/components/messages/AudioPlayer.vue diff --git a/src/assets/css/chat.scss b/src/assets/css/chat.scss index 459a51b..156440c 100644 --- a/src/assets/css/chat.scss +++ b/src/assets/css/chat.scss @@ -185,10 +185,8 @@ $admin-fg: white; background-color: $admin-bg; } .audio-bubble { - overflow: scroll; - display: inline-block; - width: fit-content; - max-width: 70%; + width: 70%; + height: 50px; } .bubble.image-bubble { padding: 0px; @@ -252,10 +250,14 @@ $admin-fg: white; max-width: 70%; } .audio-bubble { - overflow: scroll; + background-color: #e5e5e5; + border-radius: 10px 10px 0 10px; + padding: 8px; display: inline-block; - width: fit-content; + position: relative; max-width: 70%; + width: 70%; + height: 50px; } .video2-bubble { background-color: #e5e5e5; @@ -384,6 +386,40 @@ $admin-fg: white; user-select: text; } +.audio-player { + width: 100%; + position: absolute; + .currentColor { + background-color: #000000 !important; + } + .v-icon { + color: black !important; + } + .from-admin & { + color: $admin-fg; + .currentColor { + background-color: #555555 !important; + } + .v-icon { + color: white !important; + } + } + .play-time { + font-family: 'Inter', sans-serif; + font-weight: 400; + font-size: 13 * $chat-text-size; + } + .play-progress { + padding: 0px 10px; + .v-slider__thumb { + display: none; + } + &:hover .v-slider__thumb { + display: block; + } + } +} + .message-operations-strut { position: relative; height: 0px; diff --git a/src/components/messages/AudioPlayer.vue b/src/components/messages/AudioPlayer.vue new file mode 100644 index 0000000..d309095 --- /dev/null +++ b/src/components/messages/AudioPlayer.vue @@ -0,0 +1,185 @@ + + + + + + + + +function playPauseAudio() { + if (player.src) { + if (player.paused || player.ended) { + // Change the button to a pause button + changeButtonType(btnPlayPause, 'pause'); + player.play(); + } + else { + // Change the button to a play button + changeButtonType(btnPlayPause, 'play'); + player.pause(); + } + } +} + +// Stop the current media from playing, and return it to the start position +function stopAudio() { + if (player.src) { + player.pause(); + if (player.currentTime) player.currentTime = 0; + } +} + +// Toggles the media player's mute and unmute status +function muteVolume() { + if (player.src) { + if (player.muted) { + // Change the button to a mute button + changeButtonType(btnMute, 'mute'); + player.muted = false; + } + else { + // Change the button to an unmute button + changeButtonType(btnMute, 'unmute'); + player.muted = true; + } + } +} + +// Replays the media currently loaded in the player +function replayAudio() { + if (player.src) { + resetPlayer(); + player.play(); + } +} + + +// Updates a button's title, innerHTML and CSS class +function changeButtonType(btn, value) { + btn.title = value; + btn.innerHTML = value; + btn.className = value; +} + +function resetPlayer() { + progressBar.value = 0; + //clear the current song + player.src = ''; + // Move the media back to the start + player.currentTime = 0; + // Set the play/pause button to 'play' + changeButtonType(btnPlayPause, 'play'); +} + diff --git a/src/components/messages/MessageIncomingAudio.vue b/src/components/messages/MessageIncomingAudio.vue index 1c0106b..a37f2b9 100644 --- a/src/components/messages/MessageIncomingAudio.vue +++ b/src/components/messages/MessageIncomingAudio.vue @@ -1,7 +1,7 @@ @@ -9,11 +9,12 @@ diff --git a/src/components/messages/MessageOutgoingAudio.vue b/src/components/messages/MessageOutgoingAudio.vue index 87969e4..615b4b6 100644 --- a/src/components/messages/MessageOutgoingAudio.vue +++ b/src/components/messages/MessageOutgoingAudio.vue @@ -1,18 +1,19 @@ diff --git a/src/plugins/utils.js b/src/plugins/utils.js index 91d07f3..0afbd6d 100644 --- a/src/plugins/utils.js +++ b/src/plugins/utils.js @@ -565,6 +565,13 @@ class Util { return dayjs.duration(ms).format("HH:mm:ss"); } + formatDuration(ms) { + if (ms >= (60 * 60000)) { + return dayjs.duration(ms).format("H:mm:ss"); + } + return dayjs.duration(ms).format("m:ss"); + } + formatRecordStartTime(timestamp) { var then = dayjs(timestamp); return then.format('lll');