music.c ID3V1格式读取信息

/*file name "music.c"
  用于读取MP3格式歌曲信息.
  仅支持ID3V1格式的MP3文件.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

#define MAX 128
/*歌曲信息结构
   结构中Header[3] 更改为 header[4],但只赋值3个.最后一个为0
 */
struct tagID3V1{
    char Header[4];        /*TAG*/
    char Title[30];        /*标题*/
    char Artist[30];    /*作者*/
    char Album[30];        /*专辑*/
    char Year[4];        /*年代*/
    char Comment[28];    /*备注*/
    char reserve;        /*保留*/
    char track;        /*音轨*/
    char Genre;        /*类型*/
};
   

int main(int arg, char* argv[])
{
    printf("The Music is:%s/n", argv[1]);
   
    struct tagID3V1 ID3V1;
    int fd;
    off_t off;
//    char buf[MAX];
   
    if((fd = open(argv[1], O_RDWR)) == -1)
    {
        printf("%s Can/'t open!/n", argv[1]);
        exit(1);
    }
    off = lseek(fd, -128, SEEK_END);
    if(read(fd, ID3V1.Header, 3) == -1)
    {
        printf("%s Can/'t read the music header/n", argv[1]);
        exit(1);
    }
    if(read(fd, ID3V1.Title, 30) == -1)
    {
        printf("%s can/'t read the music title/n", argv[1]);
        exit(1);
    }
    if(read(fd, ID3V1.Artist, 30) == -1)
    {
        printf("%s can/'t read the music Artist/n", argv[1]);
        exit(1);
    }
    if(read(fd, ID3V1.Album, 30) == -1)
    {
        printf("%s can/'t read the music Album/n", argv[1]);
        exit(1);
    }
    if(read(fd, ID3V1.Year, 4) == -1)
    {
        printf("%s can/'t read the music Year/n", argv[1]);
        exit(1);
    }
    if(read(fd, ID3V1.Comment, 28) == -1)
    {
        printf("%s can/'t read the music Comment/n", argv[1]);
        exit(1);
    }
//    printf("The music Header is:%s/n", ID3V1.Header);
    printf("歌曲名称:%s/n", ID3V1.Title);
    printf("作者:%s/n", ID3V1.Artist);
    printf("专辑:%s/n", ID3V1.Album);
    printf("年代:%s/n", ID3V1.Year);
    printf("备注:%s/n", ID3V1.Comment);
    close(fd);
       
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值