Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
84008fa
First Bulk
gabbyMill Sep 12, 2021
18dd625
First Bulk Fixed
gabbyMill Sep 12, 2021
d164044
songElement function
gabbyMill Sep 12, 2021
0f4ad1e
createPlaylistFunction
gabbyMill Sep 12, 2021
0aa98bf
append to div
gabbyMill Sep 12, 2021
e3fa50d
append To Songs Div
gabbyMill Sep 12, 2021
b9ffecd
append to playlists
gabbyMill Sep 12, 2021
b2b4a23
PlaySong Function
gabbyMill Sep 12, 2021
b5a34b8
Fixed
gabbyMill Sep 12, 2021
27bfdb0
HTML
gabbyMill Sep 12, 2021
2e604fe
colors
gabbyMill Sep 12, 2021
e89f2b6
Bonus Requirement #2
gabbyMill Sep 13, 2021
030d014
Fixed
gabbyMill Sep 13, 2021
d598a90
CSS
gabbyMill Sep 13, 2021
938d492
Fixed a bit:
gabbyMill Sep 13, 2021
1fb6305
Made functions more readable with help of destructuring
gabbyMill Sep 13, 2021
e7b1cb1
Functions more readable and generic
gabbyMill Sep 13, 2021
4eacab0
Merge pull request #3 from gabbyMill/main
gabbyMill Sep 14, 2021
2cb4dba
CSS
gabbyMill Sep 14, 2021
94dcbe7
Merge branch 'Gabby's-Branch' of https://github.com/gabbyMill/MP3-DOM…
gabbyMill Sep 14, 2021
0690476
Start of Event listeners task
gabbyMill Sep 15, 2021
191ffac
Play Song
gabbyMill Sep 15, 2021
658d82e
Add song function
gabbyMill Sep 17, 2021
bb2dcb0
Generate Id. making more sense
gabbyMill Sep 17, 2021
60680e4
Bonus reqs
gabbyMill Sep 17, 2021
041de12
Progress bar
gabbyMill Sep 18, 2021
0eb7912
Small fix
gabbyMill Sep 19, 2021
9c198e3
1 before final\ final commit
gabbyMill Sep 19, 2021
5aaa57a
Final commit
gabbyMill Sep 19, 2021
dc20635
Forgot songs duration
gabbyMill Sep 19, 2021
75cd5fe
Little Fix
gabbyMill Sep 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions images/pathto.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.\images\cover_art\jinjer_vortex.jpg
11 changes: 4 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
<meta charset="UTF-8" />
<title>Awesome MP3 Player</title>
<link rel="shortcut icon" type="image/x-icon" href="./images/icon.png" />
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="./style.css" />
<script src="./scripts/player.js"></script>
<script src="./scripts/index.js" defer></script>
<script src="./scripts/index.new.js" defer></script>
</head>
<body>
<div id="songs">
<!-- Generated songs go here -->
</div>
<div id="playlists">
<!-- Generated playlists go here -->
</div>
<div id="songs"></div>
<div id="playlists"></div>
</body>
</html>
3 changes: 2 additions & 1 deletion index.new.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<link rel="stylesheet" href="./style.css">
<script src="./scripts/player.js"></script>
<script src="./scripts/index.new.js" defer></script>
<script src="./scripts/index.js" defer></script>
</head>
<body>
<h1>Awesome Player!!!</h1>
<div id="add-section">
<h2>Add a new song</h2>
<h2 class="click-to-add">Click me to add a new song</h2>
<div id="inputs">
<input name="title" placeholder="Title">
<input name="album" placeholder="Album">
Expand Down
8 changes: 8 additions & 0 deletions leftToDo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
each song is generated an id so it can be played and removed. DoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDone
event listeners inside createElemtn functions, createSongElemnt...

Time Displayed, bonus.
Double playlists, songs header.DoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDone

bonus: added songs will remain sorted by title.DoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDoneDone

2 changes: 2 additions & 0 deletions leftToDo2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// automatically switches between songs not working
// first click only pauses progress bar but doesn't automatically start next song.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

172 changes: 162 additions & 10 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,131 @@
function playlistDuration(id) {
let answer = 0
const playlists = player.playlists
playlists.forEach((playlist) => {
if (playlist.id === id) {
if (!playlist.songs) return;
playlist.songs.forEach((songNumber) => {
player.songs.forEach((song) => {
// finds songs that match the numbers in the array 'songs' of playlist object
if (song.id === songNumber) {
answer += song.duration
}
})
})
}
})
return answer
}

function durationConverter(time) {
if (typeof time === "string") {
const arr = time.split(":")
const seconds = +arr[0] * 60 + +(+arr[1])
return seconds
} else {
let newFormat = new Date(time * 1000).toISOString().substr(14, 5)
return newFormat
}
}
/**
* Plays a song from the player.
* Playing a song means changing the visual indication of the currently playing song.
*
* @param {String} songId - the ID of the song to play
*/
function playSong(songId) {
// Your code here

function originalPlaySong(songId) {
const resetSongs = document.querySelectorAll(".song-element")
resetSongs.forEach((song) => {
song.setAttribute("style", "background-color: rgb(118, 201, 204)")
})
player.songs.forEach((song) => {
if (song.id == songId) {
const soughtSong = document.querySelector(".song" + songId)
soughtSong.setAttribute("style", "background-color: rgb(96, 150, 163)")
soughtSong.setAttribute("style", "cursor: pointer")
soughtSong.classList.add("current-song")
}
})
// index++
// clearInterval(doesSomething)
}

function setColors (songArray) {
for (let i = 0; i < songArray.length; i++) {
const soughtSong = document.querySelector(`.song${songArray[i].id}`)
if (songArray[i].duration < 421 && songArray[i].duration > 119) {
const color = (421 - songArray[i].duration) * (120/420)
soughtSong.setAttribute("style", `background-color: hsl(${color}, 100%, 25%)`)
} else if (songArray[i].duration < 120) {
soughtSong.setAttribute("style", `background-color: green`)
} else { soughtSong.setAttribute("style", `background-color: red`)}
}
}
/**
* Creates a song DOM element based on a song object.
*/
function createSongElement({ id, title, album, artist, duration, coverArt }) {
const children = []
const classes = []
const attrs = { onclick: `playSong(${id})` }
const classes = ["song-element"]
const attrs = {} // onclick: `playSong(${id})` this was once here
const ul = document.createElement("ul")
const image = document.createElement("img")
const playButton = document.createElement('button')
playButton.classList.add('play-button', 'play-button' + id)
playButton.append('⏯')
const removeButton = document.createElement('button')
removeButton.classList.add('remove-button', 'remove-button' + id)
removeButton.append('✖️')
image.src = coverArt
image.alt = 'cover-photo'
for (let key in arguments[0]) {
if (key === 'id' || key === 'coverArt') {
continue
}
if (key === 'duration') {
const li = document.createElement("li")
if (!String(arguments[0][key]).includes(':')) {
li.innerText = durationConverter(arguments[0][key])
} else {
li.innerText = arguments[0][key]
}
ul.append(li)
} else {
const li = document.createElement("li")
li.innerText = arguments[0][key]
ul.append(li)
}
}
ul.appendChild(image)
const divOfButtons = createElement('div', [playButton, removeButton], ['button-container'])
ul.append(divOfButtons)
children.push(ul)
return createElement("div", children, classes, attrs)
}

/**
* Creates a playlist DOM element based on a playlist object.
*/
function createPlaylistElement({ id, name, songs }) {
// const newId = arguments[0]
// console.log(arguments[0]);
const children = []
const classes = []
const attrs = {}
const classes = [name + '-playlist']
const attrs = { id }
const ul = document.createElement("ul")
for (let key in arguments[0]) {
if (key === 'id') { continue }
if (key === 'songs') {
const li = document.createElement("li")
li.innerText = arguments[0][key].length + ' songs'
ul.append(li)
} else {
const li = document.createElement("li")
li.innerText = arguments[0][key]
ul.append(li)
}
}
children.push(ul)
return createElement("div", children, classes, attrs)
}

Expand All @@ -40,8 +141,59 @@ function createPlaylistElement({ id, name, songs }) {
* @param {Array} classes - the class list of the new element
* @param {Object} attributes - the attributes for the new element
*/
function createElement(tagName, children = [], classes = [], attributes = {}) {
// Your code here
}

// You can write more code below this line

// creating a ul with nested li for songs:
const songs = document.getElementById("songs")
const playlists = document.getElementById("playlists")
const siteHeader = document.createElement("header")
const headerContent = document.createElement("h1")
headerContent.innerText = `Gabby's MP3 Player`
const songHeader = document.createElement("h2")
// songHeader.innerText = `Songs`
siteHeader.append(headerContent, songHeader)
document.body.insertBefore(siteHeader, songs)
document.body.insertBefore(makeProgressBar(), songs)

const playlistHeader = document.createElement("h2")
// playlistHeader.innerText = `Playlists:`
document.body.insertBefore(playlistHeader, playlists)

// sort songs and playlists using chained ternary
function sortSongsAndPlaylists () {
player.songs.sort((a, b) => (a.title > b.title ? 1 : a.title === b.title ? 0 : -1))
player.playlists.sort((a, b) => (a.name > b.name ? 1 : a.name === b.name ? 0 : -1))
}


function appendToSongsDiv() {
songs.innerText = ''
sortSongsAndPlaylists();
player.songs.forEach((song) => {
const newSong = createSongElement(song)
newSong.classList.add("song" + song.id)
// newSong.append(makeProgressBar())
songs.append(newSong)
})
// paint songs on load:
setColors(player.songs)
}
appendToSongsDiv()

function appendToPlaylistsDiv() {
playlists.innerText = ''
sortSongsAndPlaylists()
player.playlists.forEach((playlist) => {
const newPlaylist = createPlaylistElement(playlist)
playlists.append(newPlaylist)
const playListTime = document.createElement("li")
playListTime.innerText = durationConverter(playlistDuration(playlist.id))
newPlaylist.append(playListTime)
})
}
appendToPlaylistsDiv()




Loading