0

I am using the ID3lib and the MP3Lib of their examples ( http://id3lib.sourceforge.net/ ) When I edit my MP3s it works sometimes, and sometimes not. Then I get a exception, that the File cannot be rewritten. The files are not in use. I think, the problem is, that I set ID3v2 tags through the library and that the MP3s are maybe only with a ID3v1 header? Does anyone had problems like that before?

EDIT: I managed to find the problem, which happens whenever I try to save the picture for the album.

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);
    }
}

The Error says: System.IO.IOException: The file to be replaced could not be overwritten by the file to be moved. The file to be replaced has retained its original name.

   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.
4

1 に答える 1

0

実際の問題は NTFS です。ID3 タグを書き換えると、MP3 自体が開きます。このオープニングプロセスは時々エラーをスローするようです。おっしゃる通り「たまに」です。今、私は本当に汚い解決策を実行し、それを回避してtry catchを実行しました.そのエラーの場合は、同じことをやり直します. 面白いことに、これはこれまでのところ機能しています。汚いものであっても、この回答を解決策としてマークします。誰かがより良い方法、またはその解決策を知っている場合は、お知らせください!

于 2012-02-15T10:48:04.133 に答える