使用新 ID3 标签保存 MP3 时出现问题

发布于 2024-11-17 03:17:18 字数 1649 浏览 2 评论 0原文

我正在使用他们的示例中的 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百善笑为先 2024-11-24 03:17:18

实际问题是NTFS。如果您重写 ID3 标签,则会打开 MP3 本身。看来这个打开过程偶尔会抛出错误。正如所说,它只是“有时”发生。
现在,我确实做了肮脏的解决方案,并围绕它做了尝试捕获,以防出现该错误,我只是重做同样的事情。有趣的是,到目前为止这仍然有效。
我会将这个答案标记为解决方案,即使它是一个肮脏的答案。如果有人知道更好的方法或解决方案,请告诉我们!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文