解析MP3歌曲檔案的內建資訊

來源:互聯網
上載者:User

解析MP3歌曲檔案的內建資訊,註:請尊重個人勞動成果,轉載請註明出處。

其實現代碼如下所示:

/*************************************************************************   檔案名稱  :  MP3Analysis.c                                            **   建立日期:  2012-8-17                                                **   作者    :  Martin(p11234)                                           **   連絡方式:  Ma.Martin153@gmail.com                                   **   描述    :  解析MP3歌曲檔案的內建資訊                                        **   修改    :  無                                                                **                                                                       **   聲明    :本程式僅供學習交流,未經作者授權不得用於商業目的,**               否則保留追究法律責任的權利。                                    **************************************************************************/#include <stdio.h>#include <stdlib.h>/************************************************************ *  定義一個名為MP3的結構體                                    * ************************************************************/typedef struct tagMP3{char tag[4];       // 標籤char name[31];     // 歌曲名char singer[31];   // 歌手名char special[31];  // 專輯名char year[5];      // 年份char remark[29];   // 備忘char hasTRK;       // 是否有音軌?0表示下一位為音軌char TRK;          // 音軌char style;        // 風格} MP3;/************************************************************ *  函數功能:輸出一個MP3檔案的資訊                         * ************************************************************/void ShowMP3Info(MP3 mp3){printf("歌曲的詳細資料如下:\n");printf("標籤        :%s\n", mp3.tag);printf("歌曲名      :%s\n", mp3.name);printf("歌手名      :%s\n", mp3.singer);printf("專輯        :%s\n", mp3.special);printf("年份        :%s\n", mp3.year);printf("備忘        :%s\n", mp3.remark);   if(0 == mp3.hasTRK){printf("是否有音軌  :有\n");}else{printf("是否有音軌  :無\n");}printf("音軌        :%d\n", mp3.TRK);printf("風格        :%x\n", mp3.style);}int main(void){MP3 Mp3music;  //定義一個MP3類型FILE *fp = fopen("D:/test.mp3", "r"); // 開啟mp3檔案if(NULL == fp){ // 檔案開啟失敗printf("檔案開啟失敗!請檢查“D:/test.mp3”檔案是否存在。\n");exit(0);}else{ // 檔案開啟成功// 讀取標籤資訊fseek(fp, -128L, SEEK_END);fgets(Mp3music.tag, 4, fp);// 讀取歌曲名fseek(fp, -125L, SEEK_END);fgets(Mp3music.name, 31, fp);// 讀取歌手名fseek(fp, -95L, SEEK_END);fgets(Mp3music.singer, 31, fp);// 讀取專輯名fseek(fp, -65L, SEEK_END);fgets(Mp3music.special, 31, fp);// 讀取年份fseek(fp, -35L, SEEK_END);fgets(Mp3music.year, 5, fp);// 讀取備忘fseek(fp, -31L, SEEK_END);fgets(Mp3music.remark, 29, fp);// 讀取是否音軌fseek(fp, -3L, SEEK_END);fgets(&(Mp3music.hasTRK), 2, fp);// 讀取音軌fseek(fp, -2L, SEEK_END);fgets(&(Mp3music.TRK), 2, fp);// 讀取風格fseek(fp, -1L, SEEK_END);fgets(&(Mp3music.style), 2, fp);}fclose(fp); // 關閉mp3檔案// 顯示mp3檔案的資訊ShowMP3Info(Mp3music);return 0;}

系統正常啟動並執行如下所示:

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.