5
5
</header >
6
6
<main >
7
7
<section class =" player" >
8
- <h2 class =" song-title" ></h2 >
8
+ <h2 class =" song-title" >{{ current.title }} <span >{{ current.artist }}</span ></h2 >
9
+ <div class =" control" >
10
+ <button class =" prev" @click =" previous" >Previous</button >
11
+ <button class =" play" v-if =" !isPlaying" @click =" play" >Play</button >
12
+ <button class =" pause" v-else @click =" pause" >Pause</button >
13
+ <button class =" next" @click =" next" >Next</button >
14
+ </div >
15
+ </section >
16
+ <section class =" playlist" >
17
+ <h3 >The Playlist</h3 >
18
+ <button v-for =" song in songs" :key =" song.src" @click =" play(song)" :class =" (song.src == current.src) ? 'song playing' : 'song'" >
19
+ {{ song.title }} - {{ song.artist}}
20
+ </button >
9
21
</section >
10
22
</main >
11
23
</div >
15
27
16
28
export default {
17
29
name: ' App' ,
18
-
30
+ data () {
31
+ return {
32
+ current: {},
33
+ index: 0 ,
34
+ isPlaying : false ,
35
+ songs: [
36
+ {
37
+ title : ' Suragana Kirilliye' ,
38
+ artist: ' Infaass' ,
39
+ src : require (' ./assets/Suragana-Kirilliye-(Remix)-Infaas-Nooruddin.mp3' )
40
+ },
41
+ {
42
+ title : ' Yannada Igilli' ,
43
+ artist: ' Infaass' ,
44
+ src : require (' ./assets/iraj_get-gone-luca-dayz-iraj-ft-carlprit.mp3' )
45
+ },
46
+ ],
47
+ player: new Audio ()
48
+ }
49
+ },
50
+ methods: {
51
+ play (song ) {
52
+ if (typeof song .src != " undefined" ) {
53
+ this .current = song;
54
+ this .player .src = this .current .src ;
55
+ }
56
+ this .player .play ();
57
+ this .isPlaying = true ;
58
+ },
59
+ pause (){
60
+ this .player .pause ();
61
+ this .isPlaying = false ;
62
+ },
63
+ next (){
64
+ this .index ++ ;
65
+ if (this .index > this .songs .lenght - 1 ){
66
+ this .index = 0 ;
67
+ }
68
+ this .current = this .songs [this .index ];
69
+ this .play [this .current ];
70
+ },
71
+ previous (){
72
+ this .index -- ;
73
+ if (this .index < 0 ){
74
+ this .index = this .songs .lenght - 1 ;
75
+ }
76
+ this .current = this .songs [this .index ];
77
+ this .play [this .current ];
78
+ }
79
+ },
80
+ created () {
81
+ this .current = this .songs [this .index ];
82
+ this .player .src = this .current .src ;
83
+
84
+ }
19
85
}
20
86
</script >
21
87
@@ -34,6 +100,6 @@ header{
34
100
align-item :center ;
35
101
padding : 15px ;
36
102
background-color : #212121 ;
37
- color :#fff ;
103
+ color :#fff ;
38
104
}
39
105
</style >
0 commit comments