Open Amarillys opened 5 years ago
I think you should also attach a picture of the library script where it gone wrong. And by the way, I think if you try to fetch the file via AJAX and then read it as blob, it would be better. Speaking of showing the album picture, I found I could not display image using method same as yours even on browser, but later I found a way to let it show properly, rather than creating a blob. If convenient, you can check my code either: GitHub Repository (Apache License 2.0)
Thanks for your reply. The error is on the following picture.
I will see your code for reference.
In some versions, Chromium (the basis of electron) forbids extensions to load files via "file:///" URLs. And it seems that you have entered the file path in a wrong way. Instead of entering direct path of the file like D:\foo.mp3 or E:\Moha\Toad.wav, you should enter it in file:/// URLs like file:///D:/foo.mp3 or file:///E:/Moha/Toad.wav.
In some versions, Chromium (the basis of electron) forbids extensions to load files via "file:///" URLs. And it seems that you have entered the file path in a wrong way. Instead of entering direct path of the file like D:\foo.mp3 or E:\Moha\Toad.wav, you should enter it in file:/// URLs like file:///D:/foo.mp3 or E:\Moha\Toad.wav.
Thanks for your tips! I have tried that add a header "file:///". The result was that the music can play normally but the mediatag still report an error. Like this:
{type: "parseData", info: "Offset 1025 hasn't been loaded yet."}
info: "Offset 1025 hasn't been loaded yet."
type: "parseData"
I have created a demo, here is the link: Demo
Install electron at first and then change the path at lib/main.js, and then execute
npm start
toggle the dev tool and you can see the error.
I use a npm package 'music-metadata' on electron and problem solved
I have the same problem as you. The 3.8.1 version is no problem in electron.
I have the same problem. It only works with a Javascript File
object and not a direct file:///
path. The workaround that I found is to basically create your own File
object (which is an extension of Blob
):
const getFile = async (filepath: string) => {
const blob = await fetch(filepath).then((r) => r.blob())
const name = path.basename(filepath).replace(".mp3", "").replace(".wav", "").replace(".flac", "").replace(".ogg", "")
// @ts-ignore
blob.lastModifiedDate = new Date()
// @ts-ignore
blob.name = name
return blob as File
}
const fileObject = await getFile("file:///audio.mp3")
// It should now work
const tagInfo = await new Promise((resolve, reject) => {
new jsmediatags.Reader(fileObject).read({onSuccess: (tagInfo: any) => resolve(tagInfo), onError: (error: any) => reject(error)})
})
This is a good tools but I met a problem. It seems that it broke down on electron? The same code but http's url can work out.
Sample: url ="https://foo.bar/foo.mp3" √ url ="D:/foo.mp3" X
I think that transforming it to a blob can solve it maybe, however, I hope it can be more convenient. Thank you for listening my question.
Here is a part of code.