如题,怎样在java程序中,解析返回值: 如下
http://zhangmens hiting.baidu.com/data/music/3653665/Poker%20Face.mp3?xcode=0a22a6a372506c53f08f3bb5c5f0aafe&r=1309660412
这是一首百度的MP3下载
在程序中得到url对应的得到流后,怎样解析流得到 文件名字,后缀,大小。。。。其它信息!
去掉zhangmens hiting中的空格,敏感词语!
你是想要的是不是http response header里面的东西?
context-length是响应体长度, 文件名正确的下载站的话,会有个什么内容是xxxxxx;filename=xxxx的头
如果MP3提供方是流媒体。你只能去下载这个MP3文件的前3个结构体(大约1K大小)。
在这3个结构体里,包含该音乐文件的信息。
public interface PublicInfo {
/*
char Header[3]; //标签头必须是"TAG"否则认为没有标签
char Title[30]; //标题
char Artist[30]; //作者
char Album[30]; //专集
char Year[4]; //出品年代
char Comment[28]; //备注
char reserve; //保留
char track; //音轨
char Genre; //类型
*/
public String getTitle();
public String getArtist();
public String getAlbum();
public String getYaer();
public String getComment();
public String getGenre();
}
class FrameHead{
/* 4字节(32位)数据*/
/* AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
public FrameHead(byte[] head) throws Exception{
if(head.length!=4) {
System.out.println("FrameHead数据长度不足4字节!");
throw new Exception();
}
this.MPEGVersion=this.getMPEGVersionByBit(head[1]);
this.protectionBit=this.getProtectionBitByBit(head[1]);
this.bitrate=this.getBitrateByBit(head[2]);
this.sampling=this.getSamplingByBit(head[2]);
this.paddingBit=this.getPaddingBitByBit(head[2]);
this.channelMode=this.getChannelModeByBit(head[3]);
this.bitDataSize=this.getBitDataSizeByBit();
}
文件名不就是Poker Face,后缀就是mp3呀,文件大小下载完就可以知道
关于歌曲的信息,比如时长、歌曲名、艺术家等,这个是MP3的ID3 tag
关于mp3文件的信息,比如比特率、单双声道、帧数等,是在MP3文件头部,就像楼上说的