-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayPause.vue
115 lines (101 loc) · 2.38 KB
/
PlayPause.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<script setup lang="ts">
import { ref, watch, computed } from "vue";
const props = defineProps<{ mediaUrl: string; parentClickPlay: number }>();
const audioPlayerRef = ref<HTMLMediaElement | null>(null);
const playing = ref(false);
const parentClickPlayCount = computed(() => props.parentClickPlay);
watch(parentClickPlayCount, () => {
if (!playing.value) {
audioPlayerRef.value?.play();
playing.value = true;
}
});
const playHandler = () => {
playing.value = true;
};
const stopHandler = () => {
playing.value = false;
};
const toggle = () => {
if (playing.value) {
audioPlayerRef.value?.pause();
playing.value = false;
} else {
audioPlayerRef.value?.play();
playing.value = true;
}
};
</script>
<template>
<div class="audio-play-pause" @click="toggle">
<audio
:src="props.mediaUrl"
ref="audioPlayerRef"
autoplay="false"
preload="auto"
style="display: none"
@play="playHandler"
@pause="stopHandler"
@end="stopHandler"
></audio>
</div>
<div class="audio-play-pause__bg">
<img
v-if="playing"
src="@/assets/buttons/buttonPause.svg"
alt="Pause button"
/>
<img v-else src="@/assets/buttons/buttonPlay.svg" alt="Play button" />
</div>
</template>
<style lang="scss">
@import "@/assets/variables";
.audio-play-pause {
--max-dimension: max(100vw, 100vh);
width: calc(var(--max-dimension) * 0.35);
height: calc(var(--max-dimension) * 0.38);
left: calc(var(--max-dimension) * 0.7);
top: calc(var(--max-dimension) * 0.24);
position: fixed;
background: transparent;
z-index: 2;
@include for-mobile {
position: fixed;
width: 100vw;
height: 35vw;
top: 0px;
left: 0px;
z-index: 2;
}
}
.audio-play-pause__bg {
--max-dimension: max(100vw, 100vh);
width: 1px;
height: 1px;
left: calc(var(--max-dimension) * 0.7);
top: calc(var(--max-dimension) * 0.24);
position: fixed;
z-index: -2;
img {
width: calc(var(--max-dimension) * 0.65);
height: calc(var(--max-dimension) * 0.65);
transform: translate(
calc(var(--max-dimension) * -0.18),
calc(var(--max-dimension) * -0.14)
);
@include for-mobile {
width: 45vw;
height: 45vw;
transform: translate(50vw, 0);
}
}
@include for-mobile {
position: fixed;
width: 35vw;
height: 35vw;
top: 0px;
left: 0px;
z-index: -2;
}
}
</style>