File tree 1 file changed +18
-2
lines changed
music-player/src/components
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
+ <audio :src =" song.songSrc" preload =" auto" autoplay ref =" audioPlayer" />
2
3
<div class =" text-white" >
3
4
<div class =" flex flex-row justify-between" @click =" goback" >
4
5
<button >Back</button >
19
20
<div class =" flex items-center justify-center" @click =" previous" >
20
21
<button >Previous</button >
21
22
</div >
22
- <div class =" flex items-center justify-center" >
23
+ <div class =" flex items-center justify-center" @click = " togglePlay " >
23
24
<button
24
25
class =" rounded-full bg-yellow-300 h-24 w-24 text-black font-bold"
25
26
>
26
- Play
27
+ {{ isPlaying ? "Pause" : " Play" }}
27
28
</button >
28
29
</div >
29
30
<div class =" flex items-center justify-center" @click =" next" >
36
37
37
38
<script >
38
39
export default {
40
+ name: " SongPlayer" ,
41
+ data () {
42
+ return {
43
+ isPlaying: true ,
44
+ };
45
+ },
39
46
props: {
40
47
song: {
41
48
id: Number ,
@@ -58,6 +65,15 @@ export default {
58
65
previous () {
59
66
this .$emit (" previous" );
60
67
},
68
+ togglePlay () {
69
+ if (this .isPlaying ) {
70
+ this .$refs .audioPlayer .pause ();
71
+ } else {
72
+ this .$refs .audioPlayer .play ();
73
+ }
74
+
75
+ this .isPlaying = ! this .isPlaying ;
76
+ },
61
77
},
62
78
};
63
79
</script >
You can’t perform that action at this time.
0 commit comments