Help us understand the problem. What is going on with this article?

Javascriptでmp3ファイルのID3タグを表示

More than 1 year has passed since last update.

mp3ファイルをアップロードした際にID3v1のデータを表示するプログラムを製作しました。
ID3v1はデータ最後の128bitなので、それを切り分けて読み込みしています。

ID3v2版も作ろうと思いましたが、v1とv2が混在していたり、データも可変長で何かと面倒なので次回にでもやろうと思います。

html
<!DOCTYPE html>
<html>

<body>
    <form method="post" enctype="multipart/form-data">
        <input type="file" id="file" accept="audio/mp3">
    </form>
    <p id='trackInfo'>ファイル情報</p>
    <script>

    </script>
</body>

</html>
javascript
window.onload = function() {
    const reader = new FileReader();
    file.addEventListener('change', function(e) {
        reader.readAsArrayBuffer(e.target.files[0]);
        trackInfo.innerHTML = "";
    });
    reader.onload = function(e) {
        var id3v1 = (new Uint8Array(e.target.result)).slice(-128);
        var judge = id3v1[0] + id3v1[1] + id3v1[2];
        if (judge == 220) {
            for (var i = 3; i < 93; i++) {
                if (i == 33 || i == 63) trackInfo.innerHTML += '<br>';
                trackInfo.innerHTML += String.fromCharCode(id3v1[i]);
            }
        }
    }
};
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした