Author Topic: Opening file but preventing write access  (Read 311 times)

Chris Oakley

  • Posts: 160
Opening file but preventing write access
« on: 20 Jul '21 - 10:04 »
Is it possible to open an audio file for playback in Windows but prevent the file being written to while it's open?

We've discovered that if you open a file and start playing it then open the file in something like Notepad++, do a select all and delete everything, then save the file, the audio stops playing.

I can see benefits of being able to do this, but there are also cons, so is there a way to control this?

Ian @ un4seen

  • Administrator
  • Posts: 23890
Re: Opening file but preventing write access
« Reply #1 on: 20 Jul '21 - 18:06 »
BASS doesn't currently provide that option but perhaps you can implement it yourself by opening the file without FILE_SHARE_WRITE sharing mode enabled at the same time. For example, like this:

Code: [Select]
fhandle = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
stream = BASS_StreamCreate(false, filename, 0, 0, 0);

Chris Oakley

  • Posts: 160
Re: Opening file but preventing write access
« Reply #2 on: 21 Jul '21 - 09:59 »
That's interesting. I'll give that a try Ian. Thanks for the tip.