我知道之前有类似的问题,特别是this one,但所有答案通常涉及以下两种事情之一,而我想避免这两种情况:
导入新库,或者
使用FileReader,据我所知,仅适用于用户输入的文件。
我正在制作一个小游戏,包括在选项菜单中切换几个音乐曲目的选项,并且我想显示曲目标题和艺术家。我可以调整我的歌曲对象,以便将信息(如标题、艺术家等)输入代码,但似乎将其作为文件元数据包含在内更简单,这样我只需输入文件名即可。是否有任何方法可以读取非由用户输入的文件中的元数据,而不使用额外的库?这是我正在使用的Song对象,尽管它非常简单:
var Song = function(filename)
{
this.intro = new Audio(); // the introduction of the song that leads into a loop
this.intro.src = filename + "-intro.mp3";
var temp = this;
this.intro.addEventListener("ended", function() {
this.currentTime = 0;
temp.loop.currentTime = 0;
temp.loop.play();
});
this.loop = new Audio(); // the main file that will be looped. Also has the relevant metadata
this.loop.src = filename + ".mp3";
this.loop.addEventListener("ended", function() {
this.currentTime = 0;
this.play();
});
};
var songs = [
new Song("track1"),
new Song("track2"),
new Song("track3")
];
var getTags = function(audio) { fetch(audio.src) .then(response => response.blob()) .then(mutag.fetch) .then((tags) => { console.log(tags); }); };
- KRLW890