Solved

File Access Violations

Posted on 2001-07-05
2
159 Views
Last Modified: 2010-04-06
Hello.

I recently rewrote my MP3 player and although in the past I have never coded support for reading ID3 tags (I name my files in a fashion that I never really needed to) for some reason this time I did.  And I've run into a problem.

I run Win2k, and if I play the MP3 file and then try reading the tag I get errors.  This problem isnt present on Win9x systems of course because they have much more lax file sharing restrictions.

So anyway, Im wondering if there is any way to read the tag after the MP3 has already started playing.  I was told there are ways to make Win2k less anal about file sharing but that would mean users would also have to make the change.  If it helps any, I am using a TFileStream and the fmOpenRead access mode.  Originally I was using AssignFile/Reset/CloseFile and tried the TFileStream hoping to have more luck but of course I didnt...

Thanks.
0
Comment
Question by:MannSoft
2 Comments
 
LVL 2

Accepted Solution

by:
bugroger earned 50 total points
ID: 6257504
Hi,

Look at these functions:

 - CreateFile
 - SetFilePointer
 - ReadFile / ReadFileEx
 - CloseHandle


Here is an example how your function look like:

Function GetMP3Tag(Mp3FilePath : string) : string;
Var
 Mp3File    : THandle;
 TagBuffer  : array[0..999] of char;
 BytesRead  : Dword;

Begin
 MP3File := createFile( PChar(Mp3File),
                        GENERIC_READ,
                        FILE_SHARE_READ,
                        NIL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        0);

 IF MP3File = INVALID_HANDLE_VALUE then
 Begin
  CloseHandle(Mp3File);
  ShowMessage('ERROR');
 End else
 Begin
  SetFilePointer(Mp3File, "TagOffset", NIL, FILE_BEGIN);
  ReadFile(Mp3File, TagBuffer[0], "BytesToRead", BytesRead, NIL);
  CloseHandle(Mp3File);
 End;
End;

GL
 Bug
0
 
LVL 6

Author Comment

by:MannSoft
ID: 6257872
I always do this...I ask a question and think "oh I should have tried this" and 10 minutes later I have the answer myself.  Using "fmOpenRead or fmShareDenyNone" as the file mode in the TFileScream.Create procedure did the trick.

But since you gave an answer already which may come in handy if I need to read a file using only the WinAPI in the future, I'll accept it.

Thanks

(PS: If you feel like answering another question, I could really use the method for getting the caption of the window which currently has focus (the topmost window I guess it would be).  I think I'll search through the help files for awhile longer before officially asking it for points just in case I find that one too :-) )
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now