2011-06-23 87 views
0

我正在使用ID3lib和它們示例的MP3Lib(http://id3lib.sourceforge.net/) 當我編輯我的MP3時,它有時會起作用,有時候不起作用。然後我得到一個異常,該文件不能被重寫。這些文件未被使用。我認爲,問題是,我通過庫設置了ID3v2標籤,並且MP3可能只有ID3v1標頭? 有沒有人有過這樣的問題?使用新ID3保存MP3時出現問題標籤

編輯: 我設法找到問題,這發生在我試圖保存專輯的圖片時發生。

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. 

回答

0

實際的問題是NTFS。如果您重寫了ID3標籤,則會打開MP3本身。似乎這個開放過程偶爾會引發錯誤。如前所述,它只是「有時」發生。 現在,我真的做了這個骯髒的解決方案,並試圖繞過它,如果出現這種錯誤,我只是重做相同。有趣的是,這是迄今爲止的作品。 我會將此答案標記爲解決方案,即使它很髒。如果有人知道更好的方法或解決方案,請告訴我們!