jsmediatags icon indicating copy to clipboard operation
jsmediatags copied to clipboard

Problems while works on electron?

Open Amarillys opened this issue 6 years ago • 8 comments
trafficstars

This is a good tools but I met a problem. snipaste_2019-02-01_23-05-52 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. image

Amarillys avatar Feb 01 '19 15:02 Amarillys

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)

MonNomSontPasUtile avatar Feb 01 '19 15:02 MonNomSontPasUtile

Thanks for your reply. The error is on the following picture. image

I will see your code for reference.

Amarillys avatar Feb 01 '19 15:02 Amarillys

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.

MonNomSontPasUtile avatar Feb 02 '19 01:02 MonNomSontPasUtile

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"

image

Amarillys avatar Feb 02 '19 02:02 Amarillys

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.

Amarillys avatar Feb 02 '19 02:02 Amarillys

I use a npm package 'music-metadata' on electron and problem solved

Amarillys avatar Feb 03 '19 17:02 Amarillys

I have the same problem as you. The 3.8.1 version is no problem in electron.

duanwenjian avatar Aug 21 '19 08:08 duanwenjian

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)})   
})

Moebytes avatar Aug 06 '21 00:08 Moebytes