HIRO's.NET Blog

PowerShellが好き

目次

Blog 利用状況

ニュース

あわせて読みたい

書庫

日記カテゴリ

リンク

VB.NETでMP3タグ情報を読み込む

VB.NET(2005で試しました。2003でも動作すると思います)で、MP3のタグ情報(ID3v1)を取得してみたいと思います。

 

第1章.ID3タグについて

 音声ファイルフォーマットであるmp3には、ID3タグと呼ばれる情報を保存するエリアがあります。

 このエリアには、タイトル、アーティスト名、作成年など、その楽曲の情報を保存することができます。

 ID3タグにはいくつかバージョンがあるのですが、今回はID3v1.1について説明したいと思います。

 MP3ファイルの後ろ128バイトがID3タグエリアとなっており、表のようなフォーマットとなっています。

項目 バイト数
*1 3
タイトル 30
アーティスト 30
アルバム 30
作成年 4
コメント 28
トラック番号 1
ジャンル 1

 *1)先頭3バイトには"TAG"という文字列が保存される

 

第2章.タグ情報を取得する

 第1章で、ID3v1.1のタグ情報は128バイトであることを説明しました。

 1)このことから、ファイルサイズが128バイトに満たない場合はタグ情報が無いことになりますので、処理は行わないこととします。

 2)次に、タグ情報は、ファイルの終わり128バイトのエリアにあることがわかっているので、FileStreamのSeekメソッドで読み込み位置をセットします。

 3)読み込んだ128バイトの先頭3バイトが"TAG"となっているかを確認します。

 4)各データを読み込む

 

第3章.コーディング

 上記をふまえてコーディングした例を示します。

 例ではButton1をクリックしたときにOpenFileDialogを表示して、選択させたMP3のタグ情報を取得しています。

(取得した値はどこでも使っていません (;´-`))

 あくまでも例ですので、実際には各個人で使いやすいようにクラスライブラリ化するなどしてみてください。

 

VB.NETでMP3タグ情報を読み込む
Private title As String     '曲のタイトル
Private artist As String    'アーティスト名
Private album As String     'アルバム名
Private year As String      '作成年やCD発売年
Private comment As String   'コメント
Private track As Integer    'トラック番号
Private genre As String     'ジャンル

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim dlgOpen As New OpenFileDialog

    Dim buff(127) As Byte
    If dlgOpen.ShowDialog() Then
        Dim fs As New FileStream(dlgOpen.FileName, FileMode.Open, FileAccess.Read)

        '1)128バイトに満たない場合は情報を取得できないので処理を抜ける
        If fs.Length <= 128 Then
            Exit Sub
        End If

        '2)読み込み位置をファイルの終端から128バイト手前にセットする
        fs.Seek(-128, SeekOrigin.End)
        '128バイトデータを読み取る
        For I As Integer = 0 To 127
            buff(I) = fs.ReadByte()
        Next
        fs.Close()

        '3)読み込んだ128バイトのデータの先頭3バイトが"TAG"か?
        If Encoding.Default.GetString(buff, 0, 3) = "TAG" Then
            '4)各データの読み込み
            '===== タイトル =====
            title = Encoding.Default.GetString(buff, 3, 30)
            '===== アーティスト =====
            artist = Encoding.Default.GetString(buff, 33, 30)
            '===== アルバム =====
            album = Encoding.Default.GetString(buff, 63, 30)
            '===== 作成年 =====
            year = Encoding.Default.GetString(buff, 93, 4)
            '===== コメント =====
            comment = Encoding.Default.GetString(buff, 97, 28)
            '===== トラック番号 =====
            track = Convert.ToInt32(buff(126))
            '===== ジャンル =====
            genre = Convert.ToInt32(buff(127))
        End If

    End If
End Sub

投稿日時 : 2007年3月19日 23:07

コメントを追加

# re: VB.NETでMP3タグ情報を読み込む 2007/03/20 9:28 シャノン

ID3 v2.4とかになると、規格が複雑すぎてさっぱりだ…

# re: VB.NETでMP3タグ情報を読み込む 2007/03/20 20:58 HIRO

そうですねv2.4ともなると複雑で... なのでv1.1に逃げてみました...
近いうちに2.x系を紹介できればと思っています

# re: VB.NETでMP3タグ情報を読み込む 2007/03/23 0:27 ちゃっぴ

Windows Shell からでも結構な情報読み込めた気が。。。

# ルイヴィトン時計偽物 2017/10/27 16:25 fbakuteyr@nifty.com

★弊社は「信用第一」をモットーにお客様にご満足頂けるよう
★全物品運賃無料(日本全国)
★不良品物情況、無償で交換します.
★税関没収する商品は再度無料で発送します

# 人気ブランド 2017/10/30 19:54 qzzqknbjfnj@aol.jp

とても良心的でいいショップです。商品の過剰ランク評価もなく良かったです。
【送料無料】★ルイヴィトン★ダミエ・グラフィット★ポルトフォイユ・アコルディオン★チェーン付長財布★N60023★
思っていた以上に商品の状態が良かったです。

# ivermectin lotion http://stromectolabc.com/
stromectol price us 2022/02/08 2:44 Busjdhj

ivermectin lotion http://stromectolabc.com/
stromectol price us

# ivermectin 3 mg tablet dosage http://stromectolabc.com/
ivermectin cream 2022/02/08 9:32 Busjdhj

ivermectin 3 mg tablet dosage http://stromectolabc.com/
ivermectin cream

# ivermectin lotion price http://stromectolabc.com/
ivermectin 5 mg 2022/02/08 16:35 Busjdhj

ivermectin lotion price http://stromectolabc.com/
ivermectin 5 mg

# buy doxycycline online 270 tabs https://doxycyline1st.com/
buy generic doxycycline 2022/02/26 1:01 Jusidkid

buy doxycycline online 270 tabs https://doxycyline1st.com/
buy generic doxycycline

# online doxycycline https://doxycyline1st.com/
odering doxycycline 2022/02/26 10:05 Jusidkid

online doxycycline https://doxycyline1st.com/
odering doxycycline

# generic clomid https://clomiden.fun/ 2022/04/12 13:20 Clomids

generic clomid https://clomiden.fun/

# can i buy prednisone online without a prescription http://prednisonefast.site/ 2022/04/16 23:14 Prednisone

can i buy prednisone online without a prescription http://prednisonefast.site/

# cheap clomid online https://clomidonline.icu/ 2022/07/08 14:00 Clomidj

cheap clomid online https://clomidonline.icu/

# how long for ivermectin to work https://stromectolbestprice.com/ 2022/07/30 0:54 BestPrice

how long for ivermectin to work https://stromectolbestprice.com/

# prednisone 20 mg in india https://deltasone.icu/
online order prednisone 2022/08/22 10:04 Prednisone

prednisone 20 mg in india https://deltasone.icu/
online order prednisone

# ema paxlovid https://paxlovid.best/
paxlovid ema 2022/09/08 7:33 Paxlovid

ema paxlovid https://paxlovid.best/
paxlovid ema

# buy ed pills online https://ed-pills.xyz/
ed medications 2022/09/15 19:33 EdPills

buy ed pills online https://ed-pills.xyz/
ed medications

# best erection pills https://ed-pills.xyz/
ed drug prices 2022/09/16 19:59 EdPills

best erection pills https://ed-pills.xyz/
ed drug prices

# buy ed pills online https://ed-pills.xyz/
cure ed 2022/09/17 8:10 EdPills

buy ed pills online https://ed-pills.xyz/
cure ed

# by prednisone w not prescription https://prednisone20mg.icu/ 2022/10/15 13:18 Prednisone

by prednisone w not prescription https://prednisone20mg.icu/

# ロレックス偽物時計 2022/10/25 1:37 xqqrwkf@softbank.jp

迅速に対応していただきました。商品状態や配送とも問題なく。良い買い物が出来ました。
★グッチ グッチ★グッチシマ★プレートキーホルダー★ブラウン×シルバー色★
嫁の誕生日に購入しました。手軽でおしゃれだったので購入しました。かわいいととても喜んでました。
ロレックス偽物時計 https://www.ginza24.com/product/detail/7857

# dating games https://topdatingsites.fun/
datinghotlot 2022/11/15 0:24 DatingTop

dating games https://topdatingsites.fun/
datinghotlot

# prednisone brand name in india https://prednisone20mg.site/
prednisone nz 2022/11/15 17:54 Prednisone

prednisone brand name in india https://prednisone20mg.site/
prednisone nz

# purchase prednisone no prescription https://prednisonepills.site/
mail order prednisone 2022/11/28 23:49 Prednisone

purchase prednisone no prescription https://prednisonepills.site/
mail order prednisone

# japanese singles dating sites https://datingsiteonline.site/
local single 2022/12/05 23:45 Tading

japanese singles dating sites https://datingsiteonline.site/
local single

# gnc ed pills https://edpillsotc.store/# - pills for ed 2023/10/07 21:14 EdPills

gnc ed pills https://edpillsotc.store/# - pills for ed

# ed medications online https://edpills.tech/# best ed pills online 2023/12/23 4:39 EdPills

ed medications online https://edpills.tech/# best ed pills online

タイトル
名前
URL
コメント