开发者

Problem saving a MP3 with new ID3 Tags

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:Ze开发者_如何学Goile 346.
   bei Mp3Lib.Mp3File.Update() in E:\Projects\id3lib\Mp3Lib\MP3\Mp3File.cs:Zeile 231.


The actual problem is NTFS. If you rewrite the ID3 Tags you open the MP3 itself. It seems like this opening process is occasionally throws an error. As said, it just happen "sometimes". Right now, I really did the dirty solution and did a try catch around it, in case of that error, I just redo the same. Funny thing is, that this works so far. I will mark this answer as solution, even if its a dirty one. If anyone knows a better way, or a solution for it, let us know!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜