问题
Is There any way by which we can have album art of any music file , i am able to extract file detail like album name , length , author , genre , track info. But i am intresred in to showing album art image. Please help
回答1:
Apparently someone on this page managed to write some code to extract the image's data as a ByteArray, then finally load it through a Loader object. Here's the code they came up with:
var binaryData:ByteArray;
var file:URLLoader = new URLLoader(new URLRequest("test.mp3"));
var finalData:ByteArray = new ByteArray;
var byteCon:Loader = new Loader;
var offset:int; var rLength:int;
var found:Boolean = false;
var end:Boolean = false;
file.dataFormat = URLLoaderDataFormat.BINARY;
file.addEventListener(Event.COMPLETE, handleComplete);
function handleComplete(e:Event):void{
binaryData = file.data as ByteArray;
binaryData.position = 0;
//get offset and length
while(!found){
var pos:int = binaryData.readUnsignedInt();
if(pos == 0x41504943){
offset = binaryData.position + 20;
}
if(pos == 0){
if (!found){
rLength = binaryData.position - 1 - offset;
if(rLength > 5000){
found = true;
}
}
}
binaryData.position = binaryData.position - 3;
}
finalData.writeBytes(binaryData, offset, rLength);
finalData.position = 0;
byteCon.loadBytes(finalData);
addChild(byteCon);
}
Of course this is talking about MP3s specifically, although you might be able to adapt it for other formats.
来源:https://stackoverflow.com/questions/11718051/album-art-of-music-file