本文介绍了n音讯播放也不会成功阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 n音讯以回放的文件[控制台],我无法弄清楚如何停止播放。当我打电话waveout.Stop()的code只是停止运行,waveout.Dispose()永远不会被调用。

有它的东西做的回调函数?如果是,我该如何解决这个问题?

 静态字符串MP3 = @Song.mp3的;
静态waveout的waveout的;
静态的WaveStream播放;
静态无效的主要(字串[] args)
{
    waveout的=新waveout的(WaveCallbackInfo.FunctionCallback());
    重放= OpenMp3Stream(MP3);
    waveout.Init(播放);
    waveout.Play();
    Console.WriteLine(入门);

    Thread.sleep代码(2 * 1000);

    Console.WriteLine(结束);
    如果(waveout.PlaybackState!= PlaybackState.Stopped)
        waveout.Stop();
    Console.WriteLine(停止);
    waveout.Dispose();
    Console.WriteLine(第一处置);
    playback.Dispose();
    Console.WriteLine(第二届处置);
}
私有静态WaveChannel32 OpenMp3Stream(字符串文件名)
{
    WaveChannel32的InputStream;
    的WaveStream mp3Reader =新Mp3FileReader(文件名);
    的WaveStream pcmStream = WaveFor​​matConversionStream.CreatePcmStream(mp3Reader);
    的WaveStream blockAlignedStream =新BlockAlignReductionStream(pcmStream);
    的InputStream =新WaveChannel32(blockAlignedStream);
    返回InputStream的;
}
 

解决方案

您说的code挂在调用waveOutReset?如果是这样,这是与函数回调和某些音频驱动程序的一个已知问题(SoundMAX的似乎特别容易受到这一点)。我在一个可能的修复到n音讯源$ C ​​$ CA几个月前检查,所以你可以尝试建立最新的code,看是否能解决问题。

When using NAudio to playback an MP3 file [in the console], I can't figure out how to stop the playback. When I call waveout.Stop() the code just stops running and waveout.Dispose() never gets called.

Has it something to do with the function callback? If it is, how do I fix it?

static string MP3 = @"song.mp3";
static WaveOut waveout;
static WaveStream playback;
static void Main(string[] args)
{
    waveout = new WaveOut(WaveCallbackInfo.FunctionCallback());
    playback = OpenMp3Stream(MP3);
    waveout.Init(playback);
    waveout.Play();
    Console.WriteLine("Started");

    Thread.Sleep(2 * 1000);

    Console.WriteLine("Ending");
    if (waveout.PlaybackState != PlaybackState.Stopped)
        waveout.Stop();
    Console.WriteLine("Stopped");
    waveout.Dispose();
    Console.WriteLine("1st dispose");
    playback.Dispose();
    Console.WriteLine("2nd dispose");
}
private static WaveChannel32 OpenMp3Stream(string fileName)
{
    WaveChannel32 inputStream;
    WaveStream mp3Reader = new Mp3FileReader(fileName);
    WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader);
    WaveStream blockAlignedStream = new BlockAlignReductionStream(pcmStream);
    inputStream = new WaveChannel32(blockAlignedStream);
    return inputStream;
}
解决方案

Are you saying the code hangs in the call to waveOutReset? If so, this is a known issue with function callbacks and certain audio drivers (SoundMAX seems particularly susceptible to this). I checked in a possible fix to the NAudio source code a couple of months ago, so you could try building the latest code and seeing if that fixes the issue.

这篇关于n音讯播放也不会成功阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 18:40