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.