国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

MP3文件分析:TAG區,C#小試牛刀!

2024-07-21 02:26:25
字體:
來源:轉載
供稿:網友

the tag is used to describe the mpeg audio file. it contains information about artist, title, album, publishing year and genre. there is some extra space for comments. it is exactly 128 bytes long and is located at very end of the audio data. you can get it by reading the last 128 bytes of the mpeg audio file.

aaabbbbb bbbbbbbb bbbbbbbb bbbbbbbb
bccccccc cccccccc cccccccc cccccccd
dddddddd dddddddd dddddddd dddddeee
efffffff ffffffff ffffffff fffffffg

signlength
(bytes)
position
(bytes)
description
a3(0-2)tag identification. must contain 'tag' if tag exists and is correct.
b30(3-32)title
c30(33-62)artist
d30(63-92)album
e4(93-96)year
f30(97-126)comment
g1(127)genre

the specification asks for all fields to be padded with null character (ascii 0). however, not all applications respect this (an example is winamp which pads fields with <space>, ascii 32).

there is a small change proposed in mp3v1.1 structure. the last byte of the comment field may be used to specify the track number of a song in an album. it should contain a null character (ascii 0) if the information is unknown.

genre is a numeric field which may have one of the following values:

0'blues'20'alternative'40'alternrock'60'top 40'
1'classic rock'21'ska'41'bass'61'christian rap'
2'country'22'death metal'42'soul'62'pop/funk'
3'dance'23'pranks'43'punk'63'jungle'
4'disco'24'soundtrack'44'space'64'native american'
5'funk'25'euro-techno'45'meditative'65'cabaret'
6'grunge'26'ambient'46'instrumental pop'66'new wave'
7'hip-hop'27'trip-hop'47'instrumental rock'67'psychadelic'
8'jazz'28'vocal'48'ethnic'68'rave'
9'metal'29'jazz+funk'49'gothic'69'showtunes'
10'new age'30'fusion'50'darkwave'70'trailer'
11'oldies'31'trance'51'techno-industrial'71'lo-fi'
12'other'32'classical'52'electronic'72'tribal'
13'pop'33'instrumental'53'pop-folk'73'acid punk'
14'r&b'34'acid'54'eurodance'74'acid jazz'
15'rap'35'house'55'dream'75'polka'
16'reggae'36'game'56'southern rock'76'retro'
17'rock'37'sound clip'57'comedy'77'musical'
18'techno'38'gospel'58'cult'78'rock & roll'
19'industrial'39'noise'59'gangsta'79'hard rock'
any other value should be considered as 'unknown'


以上是mp3文件tag區的文檔格式:
下面針對上面的說明,來訂制一個讀取tag信息的類:

using system;
using system.text;

namespace mp3coder
{
    
/**//// <summary>
    
/// clsmp3tag 的摘要說明。
    
/// 利用c#來解讀mp3文件的tag區信息。
    
/// </summary>
    
    
/// 作者:任兀
    
/// nick name:dsclub(兀兒 - 干部)
    
/// qq:9967030
    
/// e-mail:dsclub at 126.com
    
/// msn:dsclub at hotmail.com
    
/// 版權聲明:本代碼只用于c#的學習交流。
    
/// 如果您想轉載或將代碼應用于您的作品中,請保留此信息。


    
public class clsmp3tag
    
{
        
private byte[] tagbody = new byte[128];

        
private byte[] stag = new byte[3];
        
private byte[] stitle = new byte[30];
        
private byte[] sartist = new byte[30];
        
private byte[] salbum = new byte[30];
        
private byte[] syear = new byte[4];
        
private byte[] scomment = new byte[30];
        
private byte[] sgenre = new byte[1];
        
        system.exception myexception;

        
public clsmp3tag(byte[] tag)
        
{
            
if( tag.length != 128 )
            
{
                myexception 
= new exception("不是標準的 mpeg-mp3 tag 格式。/ntag長度應該是 128 byte。");
                
throw(myexception);
            }

            
else
            
{
                array.copy(tag, 
0, stag, 03);
                
if!encoding.default.getstring(stag).equals("tag") )
                
{
                    myexception 
= new exception("不是標準的 mpeg-mp3 tag 格式。/ntag位校驗出錯。");
                    
throw(myexception);
                }


                array.copy(tag, 
3, stitle, 030);
                array.copy(tag, 
33, sartist, 030);
                array.copy(tag, 
63, salbum, 030);
                array.copy(tag, 
93, syear, 04);
                array.copy(tag, 
97, scomment, 030);
                array.copy(tag, 
127, sgenre, 01);

                    
            }

        }


        
/**///////////////////////////////////////////////////////
        
/// 以下是屬性,只讀
        
//////////////////////////////////////////////////////

        public string title
        
{
            
get
            
{
                
return encoding.default.getstring(stitle);
            }

        }

        
        
public string artist
        
{
            
get
            
{
                
return encoding.default.getstring(sartist);
            }

        }

        
        
public string album
        
{
            
get
            
{
                
return encoding.default.getstring(salbum);
            }

        }

        
        
public string year
        
{
            
get
            
{
                
return encoding.default.getstring(syear);
            }

        }

        
        
public string comment
        
{
            
get
            
{
                
return encoding.default.getstring(scomment);
            }

        }

        
        
public , string genre
        
{
            
get
            
{
                
switch(convert.toint16(sgenre[0]))
                
{
                    
case 0return "blues"case 20return "alternative"case 40return "alternrock"case 60return "top 40"
                    
case 1return "classic rock"case 21return "ska"case 41return "bass"case 61return "christian rap"
                    
case 2return "country"case 22return "death metal"case 42return "soul"case 62return "pop/funk"
                    
case 3return "dance"case 23return "pranks"case 43return "punk"case 63return "jungle"
                    
case 4return "disco"case 24return "soundtrack"case 44return "space"case 64return "native american"
                    
case 5return "funk"case 25return "euro-techno"case 45return "meditative"case 65return "cabaret"
                    
case 6return "grunge"case 26return "ambient"case 46return "instrumental pop"case 66return "new wave"
                    
case 7return "hip-hop"case 27return "trip-hop"case 47return "instrumental rock"case 67return "psychadelic"
                    
case 8return "jazz"case 28return "vocal"case 48return "ethnic"case 68return "rave"
                    
case 9return "metal"case 29return "jazz+funk"case 49return "gothic"case 69return "showtunes"
                    
case 10return "new age"case 30return "fusion"case 50return "darkwave"case 70return "trailer"
                    
case 11return "oldies"case 31return "trance"case 51return "techno-industrial"case 71return "lo-fi"
                    
case 12return "other"case 32return "classical"case 52return "electronic"case 72return "tribal"
                    
case 13return "pop"case 33return "instrumental"case 53return "pop-folk"case 73return "acid punk"
                    
case 14return "r&b"case 34return "acid"case 54return "eurodance"case 74return "acid jazz"
                    
case 15return "rap"case 35return "house"case 55return "dream"case 75return "polka"
                    
case 16return "reggae"case 36return "game"case 56return "southern rock"case 76return "retro"
                    
case 17return "rock"case 37return "sound clip"case 57return "comedy"case 77return "musical"
                    
case 18return "techno"case 38return "gospel"case 58return "cult"case 78return "rock & roll"
                    
case 19return "industrial"case 39return "noise"case 59return "gangsta"case 79return "hard rock"


                    
default:
                        
return "未知類型";
                }


            }

        }

    

    }

}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌拉特前旗| 乌海市| 登封市| 友谊县| 宝丰县| 新巴尔虎右旗| 宿迁市| 黄冈市| 呼图壁县| 天祝| 玉树县| 彭州市| 枣庄市| 常山县| 时尚| 河源市| 方城县| 法库县| 栖霞市| 图木舒克市| 广汉市| 阿拉善盟| 拉孜县| 苏尼特左旗| 镇安县| 阿拉善右旗| 荣成市| 庆元县| 长汀县| 长沙县| 金沙县| 博湖县| 中卫市| 台东市| 会宁县| 洛南县| 靖安县| 鸡西市| 罗平县| 龙口市| 个旧市|