workadventure/front/src/Components/UI/AudioPlaying.svelte

53 lines
1.3 KiB
Svelte
Raw Normal View History

2021-06-02 16:46:28 +02:00
<script lang="ts">
2021-12-06 16:12:37 +01:00
import { fly } from "svelte/transition";
2021-06-02 16:46:28 +02:00
import megaphoneImg from "./images/megaphone.svg";
2021-12-06 16:12:37 +01:00
import { soundPlayingStore } from "../../Stores/SoundPlayingStore";
import { afterUpdate } from "svelte";
2021-06-02 16:46:28 +02:00
export let url: string;
let audio: HTMLAudioElement;
function soundEnded() {
soundPlayingStore.soundEnded();
}
afterUpdate(() => {
2022-01-04 16:48:47 +01:00
audio.play().catch((e) => console.error(e));
2021-06-02 16:46:28 +02:00
});
</script>
2021-12-06 16:12:37 +01:00
<div class="audio-playing" transition:fly={{ x: 210, duration: 500 }}>
2021-06-02 16:46:28 +02:00
<img src={megaphoneImg} alt="Audio playing" />
<p>Audio message</p>
2021-12-06 16:12:37 +01:00
<audio bind:this={audio} src={url} on:ended={soundEnded}>
<track kind="captions" />
2021-06-02 16:46:28 +02:00
</audio>
</div>
<style lang="scss">
2021-12-06 16:12:37 +01:00
/*audio html when audio message playing*/
.audio-playing {
position: absolute;
width: 200px;
height: 54px;
right: 0;
top: 40px;
transition: all 0.1s ease-out;
background-color: black;
border-radius: 30px 0 0 30px;
display: inline-flex;
2021-06-02 16:46:28 +02:00
2021-12-06 16:12:37 +01:00
img {
border-radius: 50%;
background-color: #ffda01;
padding: 10px;
}
2021-06-02 16:46:28 +02:00
2021-12-06 16:12:37 +01:00
p {
color: white;
margin-left: 10px;
margin-top: 14px;
}
2021-06-02 16:46:28 +02:00
}
</style>