[ golang读取flag,mp3等文件信息 ]


go读取音频信息

GIT地址

案例测试

package test

import (
    "log"
    "os"
    "testing"

    "github.com/dhowden/tag"
)

func TestMusic(t *testing.T) {
    f, err := os.Open("G:/go_work/go-weixin/src/go-weixin/test/music/1.flac")
    if err != nil {
        panic(err)
    }
    m, err := tag.ReadFrom(f)
    if err != nil {
        log.Fatal(err)
    }
    // log.Print(m.Format())      // The detected format.
    // log.Print(m.Title())       // The title of the track (see Metadata interface for more details).
    // log.Print(m.Album())       // The title of the track (see Metadata interface for more details).
    // log.Print(m.Artist())      // The title of the track (see Metadata interface for more details).
    // log.Print(m.AlbumArtist()) // The title of the track (see Metadata interface for more details).
    // log.Print(m.Composer())    // The title of the track (see Metadata interface for more details).
    // log.Print(m.Genre())       // The title of the track (see Metadata interface for more details).
    // log.Print(m.Year()) // The title of the track (see Metadata interface for more details).
    // log.Print(m.Picture())     // The title of the track (see Metadata interface for more details).
    i := m.Picture()
    f1, err := os.Create("G:/go_work/go-weixin/src/go-weixin/test/music/1.jpg")
    if err != nil {
        panic(err)
    }
    _, err = f1.Write(i.Data)
    if err != nil {
        panic(err)
    }
}