我一直试图将位图设置为MP3的封面艺术,但我似乎无法使其正常工作。它没有抛出任何错误,但是当我播放MP3时,位图没有显示。
这就是我目前所拥有的:
TagLib.File f = TagLib.File.Create("song.mp3");
Image currentImage = getAlbumArt(result.passedAlbumID);
Picture pic = new Picture();
pic.Type = PictureType.FrontCover;
pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
pic.Description = "Cover";
MemoryStream ms = new MemoryStream();
currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
pic.Data = ByteVector.FromStream(ms);
f.Tag.Pictures = new IPicture[1] { pic };
pictureBox1.Image = currentImage; //testing the image is correct
f.Save();
ms.Close();
答案 0 :(得分:7)
我正在使用以下代码,一切正常对我来说:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case OUR_REQUEST_CODE:
if(resultCode == RESULT_OK) {
//Do something useful with data
}
break;
}
}
根据您提供的代码,我唯一注意到的是,我的代码使用了以下行
TagLib.File file = TagLib.File.Create(/*path to your mp3 file*/);
TagLib.Picture pic = new TagLib.Picture();
pic.Type = TagLib.PictureType.FrontCover;
pic.Description = "Cover";
pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
MemoryStream ms = new MemoryStream();
/*your image*/.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
pic.Data = TagLib.ByteVector.FromStream(ms);
file.Tag.Pictures = new TagLib.IPicture[] { pic };
file.Save();
ms.Close();
而不是
file.Tag.Pictures = new TagLib.IPicture[] { pic };
如果你删除方括号内的f.Tag.Pictures = new TagLib.IPicture[1] { pic };
,只需尝试一下。