MP3 Player File Lock
807591Apr 24 2008 — edited Apr 24 2008I am working on a program that edits the tags of an MP3. Everything works great until I edit a song that is playing with another program.
My code does the following:
Copy the MP3 while editing the tag into a temp file.
Delete the MP3
Rename it with a temp file.
Where it goes wrong:
The delete happens, but the file still plays in the player.
The rename fails.
When the song is closed by the player, the file is deleted.
Only the temp file remains.
I would like to solve this one of two ways:
1) I found that I can get an exclusive lock (FileLock) on the playing MP3. This stops the player after some seconds. I cannot figure out the next step which is to delete the locked file, and rename the temp file the same name as the locked file. I did a test. Just getting a lock does not stop the player; I was able to lock and unlock a file without interruption of the playback.
2) I would like to detect that the song in being played. That way I just don't try to edit the MP3. I can log that to the user and they can close down the player.
I realize that this is all rather high level. I am just looking for a good direction to go. Any pointers or code snippets would be great.
Edited by: solarburn on Apr 23, 2008 10:53 PM