Play audio to two different Audiodevices simultaneously with Naudio

久未见 提交于 2019-12-24 11:55:58

问题


I'm trying to figure out how to play music to two different audiodevices at the same time.

What I've done is to create a class that makes life easier for me when programming with Naudio, it has play mp3 & wav's, pause, stop etc etc.

What I'd love to have is the ability to chose what playback device the audiostream should be outputted to. Is there some way I can incorporate it like this:

Play to: Realtek HD audio 2nd output and Speakers (if it was plugged in)

Here's the "Play" function I created:

public void Play(string Searchpath, int Time = 0)
    {
        DisposeWave();
        string FileExtension = System.IO.Path.GetExtension(Searchpath);
        if (FileExtension == (".mp3"))
        {
            NAudio.Wave.WaveStream pcmstream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(Searchpath));
            stream = new NAudio.Wave.BlockAlignReductionStream(pcmstream);
        }
        else if (FileExtension == (".wav"))
        {
            NAudio.Wave.WaveStream pcmstream = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(Searchpath));
            stream = new NAudio.Wave.BlockAlignReductionStream(pcmstream);
        }

        output = new NAudio.Wave.DirectSoundOut();
        output.Init(stream);
        output.Play();

        Playbackstate = PlaybackState.Playing;
    }

Is there some page I can read up on this at?

Thank you

来源:https://stackoverflow.com/questions/20724897/play-audio-to-two-different-audiodevices-simultaneously-with-naudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!