我正在使用他们示例的 ID3lib 和 MP3Lib ( http://id3lib.sourceforge.net/ ) 当我编辑我的 MP3 时,它有时可以工作,有时不能。然后我得到一个异常,文件不能被重写。文件未使用。我认为,问题在于,我通过库设置了 ID3v2 标签,而 MP3 可能只有 ID3v1 标头?以前有人遇到过这样的问题吗?
编辑:我设法找到了问题,每当我尝试为相册保存图片时都会发生这种情况。
string filepath = Application.StartupPath + @"\temp.jpg";
if(File.Exists(filepath))
File.Delete(filepath);
FileStream fs = File.Create(filepath);
id3AlbumImage.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
fs.Close();
using (FileStream stream = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
byte[] buffer = new Byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
if (buffer != null)
{
MemoryStream memoryStream = new MemoryStream(buffer, false);
_mp3File.TagHandler.Picture = Image.FromStream(memoryStream);
}
}
错误说:System.IO.IOException:要替换的文件无法被要移动的文件覆盖。要替换的文件保留其原始名称。
bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.__Error.WinIOError()
bei System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName, Boolean ignoreMetadataErrors)
bei Com.Hertkorn.Helper.Filesystem.FileMover.FileMove(FileInfo sourceLocation, FileInfo targetLocation, FileInfo backupLocation) in E:\Projects\id3lib\Mp3Lib\Utils\FileMover.cs:Zeile 51.
bei Mp3Lib.Mp3File.RewriteFile(FileInfo bakFileInfo) in E:\Projects\id3lib\Mp3Lib\MP3\Mp3File.cs:Zeile 346.
bei Mp3Lib.Mp3File.Update() in E:\Projects\id3lib\Mp3Lib\MP3\Mp3File.cs:Zeile 231.