-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJukeboxAPI.js
127 lines (115 loc) · 3.99 KB
/
JukeboxAPI.js
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
116
117
118
119
120
121
122
123
124
125
126
127
SC.initialize({client_id: 'QcfpeasymrnTbJJoanZ9kjWdzHZjfzXW'});
var playIcon = document.getElementById("play")
var pauseIcon = document.getElementById("pause")
var nextIcon = document.getElementById("next")
var prevIcon = document.getElementById("previous")
var albumPic = document.querySelector("#albumpic")
var ArtistName = document.querySelector("#ShowArtist")
var linkToArtist = document.querySelector("#linktoartist")
var MusicTitle = document.querySelector("#ShowMusicTitle")
var SongTitle = document.querySelector("#ShowSongTitle")
var linkToSong = document.querySelector("#linktosong")
var descriptionPlace = document.querySelector("#descriptionplace")
var GenrePos = document.querySelector("#genre")
var ReleaseDate = document.querySelector("#releasedate")
// var trackID = [271223883]
var index = [0]
var songs = []
var playlist = [317184390]
// var soundsong= SC.stream('/tracks/' + trackID[index])
var soundsong= SC.stream('/playlists/' + playlist[index])
SC.resolve("https://api.soundcloud.com/playlists/317184390").then(function(response) {
console.log("Hey");
});
function Jukebox(songs){
this.songs= songs
SC.resolve("https://api.soundcloud.com/playlists/317184390").then(function(response){
var album = response.artwork_url
var img = document.createElement('img')
img.src = album
albumPic.appendChild(img)
var title = response.title
MusicTitle.innerHTML = "Album Title: " + title
var trackTitle = response.tracktitle
SongTitle.innerHTML = "Track: " + trackTitle
var titlelink = response.permalink_url
var a = document.createElement('a')
a.setAttribute('href', titlelink)
a.setAttribute('target', '_blank')
a.innerHTML = "link to track"
linkToSong.appendChild(a)
var artist = response.user.username
ArtistName.innerHTML = "Artist: " + artist
var artistlink = response.user.permalink_url
var anchor = document.createElement('a')
anchor.setAttribute('href', artistlink)
anchor.setAttribute('target', '_blank')
anchor.innerHTML = "link to artist page"
linkToArtist.appendChild(anchor)
// var description = response.description
// descriptionPlace.innerHTML = "Description: " + description
var genre = response.genre
GenrePos.innerHTML = "Genre: " + genre + "/" + genre
var month = response.release_month
var day = response.release_day
var year = response.release_year
ReleaseDate.innerHTML = "Release Date: " + month + "/" + day + "/" + year
console.log(response);
});
}
//instantiation: jukebox object created, songs pushed into jukebox array
var jukebox = new Jukebox(songs);
// Jukebox object methods
Jukebox.prototype.play = function() {
soundsong.then(function(player){
player.play()
player.on("finish", function(){
player.pause()
soundsong.currentTime= 0
pauseIcon.style.color= "#ff4f5a"
playIcon.style.color= "#2d2d2d"
player.play()
})
})
}
Jukebox.prototype.pause = function() {
soundsong.then(function(player){
player.pause()
})
}
Jukebox.prototype.skip = function() {
soundsong.then(function(player){
player.next();
})
}
// button event listeners
playIcon.addEventListener("click", function(event){
event.preventDefault()
jukebox.play()
playIcon.style.color = "#ff4f5a"
pauseIcon.style.color = "#2d2d2d"
})
pauseIcon.addEventListener("click", function(event){
event.preventDefault()
jukebox.pause()
pauseIcon.style.color = "#ff4f5a"
playIcon.style.color = "#2d2d2d"
})
nextIcon.addEventListener("click", function(event){
event.preventDefault()
jukebox.skip()
ShowMusicTitle.innerHTML = titles[index]
ShowArtist.innerHTML = artists[index]
playIcon.style.color = "#FF1493"
pauseIcon.style.color = "#000000"
stopIcon.style.color = "#000000"
})
prevIcon.addEventListener("click", function(event){
event.preventDefault()
jukebox.back()
ShowMusicTitle.innerHTML = titles[index]
ShowArtist.innerHTML = artists[index]
playIcon.style.color = "#FF1493"
pauseIcon.style.color = "#000000"
stopIcon.style.color = "#000000"
})