summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details
diff options
context:
space:
mode:
authorjulian laplace <julescarbon@gmail.com>2022-10-27 22:36:20 +0200
committerjulian laplace <julescarbon@gmail.com>2022-10-27 22:36:20 +0200
commit61b119ecbddf2275f39a91fa252e071c4767d863 (patch)
tree106e02593edaf66865fc5f3a0924a2f8abccb3d5 /public/assets/js/lib/views/details
parenteea34be30711fc9de9a65dce772b0f8b42541f9c (diff)
play music button
Diffstat (limited to 'public/assets/js/lib/views/details')
-rw-r--r--public/assets/js/lib/views/details/audio.js40
-rw-r--r--public/assets/js/lib/views/details/audioPlayer.js5
2 files changed, 29 insertions, 16 deletions
diff --git a/public/assets/js/lib/views/details/audio.js b/public/assets/js/lib/views/details/audio.js
index 2329886..1c2f6f0 100644
--- a/public/assets/js/lib/views/details/audio.js
+++ b/public/assets/js/lib/views/details/audio.js
@@ -20,23 +20,37 @@ const audio = (function () {
audio.index();
audio.build();
if (music.length) {
- audio.el.src = music[0];
+ audio.el.src = music[0].href;
}
initted = true;
};
- audio.index = function () {
+ audio.index = function (files) {
music = [];
current_index = -1;
- var links = document.querySelectorAll("a");
- Array.prototype.slice.apply(links).forEach(function (link) {
- if (!link.href.match(/\.(mp3|wav|aiff?|m4a|ogg|opus|flac)$/)) return;
- link.dataset.index = music.length;
- music.push(link);
- if (playing && link.href === audio.el.src) {
- current_index = parseInt(link.dataset.index);
- }
- });
+ if (files) {
+ music = files
+ .filter((file) => AUDIO_REGEXP.test(file.filename))
+ .map((file) => ({
+ href: make_link(file),
+ title: file.filename.replace(AUDIO_REGEXP, ""),
+ }));
+ } else {
+ var links = document.querySelectorAll("a");
+ Array.prototype.slice.apply(links).forEach(function (link) {
+ if (!link.href.match(/\.(mp3|wav|aiff?|m4a|ogg|opus|flac)$/)) return;
+ link.dataset.index = music.length;
+ music.push({
+ el: link,
+ href: link.href,
+ title: link.innerText,
+ });
+ if (playing && link.href === audio.el.src) {
+ current_index = parseInt(link.dataset.index);
+ }
+ });
+ }
+ console.log(music);
if (playing) {
audio.set_cursor();
}
@@ -99,8 +113,8 @@ const audio = (function () {
audio.set_cursor = function () {
selected = document.querySelector(".playing");
if (selected) selected.classList.remove("playing");
- if (current_index > -1) {
- music[current_index].classList.add("playing");
+ if (current_index > -1 && music[current_index].el) {
+ music[current_index].el.classList.add("playing");
}
};
diff --git a/public/assets/js/lib/views/details/audioPlayer.js b/public/assets/js/lib/views/details/audioPlayer.js
index a2e38e5..89f0dd4 100644
--- a/public/assets/js/lib/views/details/audioPlayer.js
+++ b/public/assets/js/lib/views/details/audioPlayer.js
@@ -75,7 +75,7 @@ const AudioPlayer = View.extend({
/**
* Receiving play events
*/
- onPlay: function (element) {
+ onPlay: function ({ href, title, element }) {
if (!this.active) {
this.$el.removeClass("unloaded");
this.active = true;
@@ -87,8 +87,7 @@ const AudioPlayer = View.extend({
}
this.onTimeUpdate();
- if (element) {
- const title = element.innerText;
+ if (title) {
this.$title.html(title);
}
},