naudio - 对象包含非原始或非blittable数据

时间:2012-06-11 23:30:48

标签: naudio

我正在编写一个包含简单MP3 / WAV媒体播放器区域的程序。

我已经遵循了NAudio示例程序中包含的代码,这是我创建的用于封装可播放音频文件的类:

public sealed class PlaybackContext : IDisposable {

    private String         _fileName;
    private DirectSoundOut _dsoundOut;
    private WaveStream     _waveStream;

    public PlaybackContext(String fileName) {

        _fileName  = fileName;
        _dsoundOut = new DirectSoundOut( DirectSoundOut.DSDEVID_DefaultPlayback );

        String ext = Path.GetExtension( fileName );
        if( ext.Equals(".mp3", StringComparison.OrdinalIgnoreCase) ) {

            _waveStream = new Mp3FileReader( fileName );

        } else if( ext.Equals(".wav", StringComparison.OrdinalIgnoreCase) ) {

            _waveStream = new WaveFileReader( fileName );
            switch( _waveStream.WaveFormat.Encoding ) {
                case WaveFormatEncoding.Pcm:
                case WaveFormatEncoding.IeeeFloat:
                    break;
                default:
                    _waveStream = new BlockAlignReductionStream( WaveFormatConversionStream.CreatePcmStream( _waveStream ) );
                    break;
            }
        }

        _dsoundOut.Init( _waveStream );
    }

    public void Play() {

        _dsoundOut.Play();
    }
            // hidden are the Pause/Stop/Dispose methods

它适用于MP3文件,但当我尝试播放任何Wave文件时,我得到了这个例外:

Object contains non-primitive or non-blittable data.
   System.ArgumentException
   at System.Runtime.InteropServices.GCHandle.InternalAlloc(Object value, GCHandleType type)
   at System.Runtime.InteropServices.GCHandle.Alloc(Object value, GCHandleType type)
   at NAudio.Wave.DirectSoundOut.InitializeDirectSound()
   at NAudio.Wave.DirectSoundOut.PlaybackThreadFunc()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

我找不到Google的任何内容,我的代码是针对x86编译的(因此这不是64位问题)。否则我就被困住了。

有什么想法吗?

0 个答案:

没有答案