Search code examples
c#audiowavnaudio

When I run my program that contain NAudio lib appear the following error that (WaveInterop.mmioStringToFOURCC) was not accessible


When I run my program that contains NAudio library the following error appear that was "not accessible due to its protection level".

public void ReadWaveHeader(Stream stream)
{
    this.dataChunkPosition = -1;
    this.waveFormat = null;
    this.riffChunks = new List<RiffChunk>();
    this.dataChunkLength = 0;

    BinaryReader br = new BinaryReader(stream);
    ReadRiffHeader(br);
    this.riffSize = br.ReadUInt32(); // Read the file size (minus 8 bytes)

    if (br.ReadInt32() != WaveInterop.mmioStringToFOURCC("WAVE", 0))
    {
        throw new FormatException("Not a WAVE file - no WAVE header");
    }

    if (isRf64)
    {
        ReadDs64Chunk(br);
    }

    int dataChunkID = WaveInterop.mmioStringToFOURCC("data", 0);
    int formatChunkId = WaveInterop.mmioStringToFOURCC("fmt ", 0);

    // Sometimes a file has more data than is specified after the RIFF header
    long stopPosition = Math.Min(riffSize + 8, stream.Length);

Solution

  • If it is a Windows Store application you are making, then you can't call mmioStringToFOURCC. The NAudio 1.7 NuGet package contains a preview quality Windows Store assembly that doesn't call mmioStringToFOURCC. However, NAudio's Windows Store support isn't quite complete yet.

    If you mean that you have a compile error because you are trying to call WaveInterop.mmioStringToFOURCC from outside of NAudio, then you can't because WaveInterop is internal to NAudio. Not all of the NAudio internals are made externally visible to keep the overall API surface area down. You could easily put the interop signature into your own code:

    [DllImport("winmm.dll")]
    public static extern int mmioStringToFOURCC([MarshalAs(UnmanagedType.LPStr)] String s, int flags);