Exception "Access is denied" while opening a file

0

I'm getting this error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) while trying to open an audio file. The weird thing is that yesterday it worked and today it isn't even though I changed nothing.

public static void Merge(string firstFile, string secondFile, string destination, float fVolume, float sVolume)
{
    MixingSampleProvider mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2));

    AudioFileReader reader = new AudioFileReader(firstFile);
    reader.Volume = fVolume;
    //ISampleProvider provider = Resampler(reader);
    ISampleProvider provider;
    if (reader.WaveFormat.Channels == 1)
    {
        provider = MonoToStereo(reader);
    }
    else
    {
        provider = (ISampleProvider)reader;
    }
    mixer.AddMixerInput(provider);

    reader = new AudioFileReader(secondFile);
    reader.Volume = sVolume;
    //provider = Resampler(reader);
    if (reader.WaveFormat.Channels == 1)
    {
        provider = MonoToStereo(reader);
    }
    else
    {
        provider = (ISampleProvider)reader;
    }
    mixer.AddMixerInput(provider);

    var waveProvider = mixer.ToWaveProvider();
    WaveFileWriter.CreateWaveFile(destination, waveProvider);
}

The first line AudioFileReader reader = new AudioFileReader(firstFile); throws the exception. It can't be possible that access is denied because in the previous window of the app i played the exact same audio file but in this time i want to save it with another file. Why does it says that access is denied? My app worked just fine and now everything is a mess..

wpf
file
naudio
asked on Stack Overflow Feb 15, 2017 by EldarGoren • edited Jul 7, 2020 by Martijn Pieters

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0