2020-02-11 00:34:26 +08:00
|
|
|
export const AudioMimeType = {
|
|
|
|
mp3: "audio/mpeg",
|
|
|
|
flac: "audio/flac",
|
|
|
|
m4a: "audio/mp4",
|
|
|
|
ogg: "audio/ogg"
|
|
|
|
};
|
|
|
|
export const FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43, 0x00];
|
2020-01-21 19:03:41 +08:00
|
|
|
|
|
|
|
// Also a new draft API: blob.arrayBuffer()
|
2020-02-11 00:34:26 +08:00
|
|
|
export async function GetArrayBuffer(blobObject) {
|
2020-01-21 19:03:41 +08:00
|
|
|
return await new Promise(resolve => {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = (e) => {
|
|
|
|
resolve(e.target.result);
|
|
|
|
};
|
|
|
|
reader.readAsArrayBuffer(blobObject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-11 00:34:26 +08:00
|
|
|
export function GetFileInfo(artist, title, filenameNoExt) {
|
2020-01-21 19:03:41 +08:00
|
|
|
let newArtist = "", newTitle = "";
|
|
|
|
let filenameArray = filenameNoExt.split("-");
|
|
|
|
if (filenameArray.length > 1) {
|
|
|
|
newArtist = filenameArray[0].trim();
|
|
|
|
newTitle = filenameArray[1].trim();
|
|
|
|
} else if (filenameArray.length === 1) {
|
|
|
|
newTitle = filenameArray[0].trim();
|
|
|
|
}
|
|
|
|
|
2020-02-11 00:34:26 +08:00
|
|
|
if (typeof artist == "string" && artist !== "") newArtist = artist;
|
|
|
|
if (typeof title == "string" && title !== "") newTitle = title;
|
2020-02-06 16:18:40 +08:00
|
|
|
return {artist: newArtist, title: newTitle};
|
2020-01-21 19:03:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2020-02-11 00:34:26 +08:00
|
|
|
export function GetCoverURL(metadata) {
|
2020-01-21 19:03:41 +08:00
|
|
|
let pic_url = "";
|
|
|
|
if (metadata.common.picture !== undefined && metadata.common.picture.length > 0) {
|
|
|
|
let pic = new Blob([metadata.common.picture[0].data], {type: metadata.common.picture[0].format});
|
|
|
|
pic_url = URL.createObjectURL(pic);
|
|
|
|
}
|
|
|
|
return pic_url;
|
2020-02-06 16:18:40 +08:00
|
|
|
}
|
2020-02-11 00:34:26 +08:00
|
|
|
|
|
|
|
export function IsBytesEqual(first, second) {
|
|
|
|
return first.every((val, idx) => {
|
|
|
|
return val === second[idx];
|
|
|
|
})
|
|
|
|
}
|