Some users may want to listen to their songs in the order the album's artists intended it to be. However, right now album songs are always ordered alphabetically. You can use the tag.tags.track
attribute of the jsmediatags library to sort them correctly. tag.tags.track
is a string integer, so you can use parseInt()
to convert it to a number and set it to a temporary variable.
Where the const album
object is first created, have the songs
, songArtist
, songsB64
, & songYear
values set to Array(files.length).fill("")
by default.
Then, rewrite this section:
jsmediatags.read(file, {
onSuccess: (tag) => {
album["songs"].push(tag.tags.title)
album["songArtist"].push(tag.tags.artist)
album["songYear"].push(tag.tags.year)
},
onError: (error) => {
console.error(error)
}
})
As this:
const index = 0
jsmediatags.read(file, {
onSuccess: (tag) => {
let index = parseInt(tag.tags.track)
album["songs"][index] = tag.tags.title
album["songArtist"][index] = tag.tags.artist
album["songYear"][index] = tag.tags.year
},
onError: (error) => {
console.error(error)
}
})
The same, likewise, should be done for the FileReader() section:
const reader = new FileReader()
reader.onload = () => {
console.log(`Reader: ${file.name}`)
statusText.innerHTML = `Saving ${file.name} in storage...`
album["songsB64"][index] = `${file.name}_${reader.result}`
}
reader.onerror = (e) => {
console.error(e)
}
reader.readAsDataURL(file)
This should (ideally) set the songs, B64, artists, and song years to their correct order. Complete Issue #8 before starting this issue.