Skip to main content
 首页 » 编程设计

c#之如何使用 CSCore.Streams.FadeInOut

2024年02月13日13zengkefu

我想使用类 CSCore.Streams.FadeInOut ,包含在 CSCore-Library 中.我想淡入和淡出我播放的歌曲。但我不知道如何使用它。有人知道吗?

请您参考如下方法:

正如您已经提到的,您可以使用 FadeInOut 类。查看此示例:

    IWaveSource source = CodecFactory.Instance.GetCodec(@"C:\Temp\test.mp3"); 
    using (var fadeInOut = new FadeInOut(source, 1.0f)) 
    { 
        using (var soundOut = new WasapiOut()) 
        { 
            soundOut.Initialize(fadeInOut.ToWaveSource()); 
            soundOut.Play(); 
 
            Thread.Sleep(1000); 
 
            fadeInOut.StartFading(2, 0.0f); //reduce the volume to 0.0f over 2 seconds 
 
            Thread.Sleep(3000); 
 
            fadeInOut.StopFading(); //stop fading 
            fadeInOut.StartFading(2, 1.0f); //fade the volume to 1.0f over 2 seconds 
 
            Console.ReadKey(); 
        } 
    }