如何发挥在C#中的MP3流 [英] How to play an MP3 stream in C#

查看:316
本文介绍了如何发挥在C#中的MP3流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的C#应用​​程序来播放MP3流。我有捕获波形音频,并将其转换成MP3一个服务器应用程序,然后将它写入到网络流。然后,客户端读取此流播放MP3。我曾试图与n音讯以下code的例子,但它会导致异常:

 使用行为(WaveStream blockAlignedStream =
                新BlockAlignReductionStream(
                    WaveFor​​matConversionStream.CreatePcmStream(
                        新Mp3FileReader(毫秒))))
            {
                使用(waveout的waveout的=新waveout的(WaveCallbackInfo.FunctionCallback()))
                {
                    waveOut.Init(blockAlignedStream);
                    waveOut.Play();
                    而(waveOut.PlaybackState == PlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                }
            }


解决方案

我已经贴在我的博客一篇文章,解释的如何播放使用n音讯一个MP3流。基本上你有一个线程下载MP3帧,DECOM pressing它们并将它们存储在 BufferedWaveProvider 。另一个线程然后播放使用 BufferedWaveProvider 作为输入。

I want to play an MP3 stream in my C# application. I have a server application that captures wave audio and converts it into MP3, then writes it to a network stream. The client then reads this stream to play the MP3. I have tried NAudio with the following code example, but it results in exception:

using (WaveStream blockAlignedStream =
                new BlockAlignReductionStream(
                    WaveFormatConversionStream.CreatePcmStream(
                        new Mp3FileReader(ms))))
            {
                using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
                {
                    waveOut.Init(blockAlignedStream);
                    waveOut.Play();                        
                    while (waveOut.PlaybackState == PlaybackState.Playing )                        
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                }
            }

解决方案

I have posted an article on my blog explaining how to play back an MP3 stream using NAudio. Essentially you have one thread downloading MP3 frames, decompressing them and storing them in a BufferedWaveProvider. Another thread then plays back using the BufferedWaveProvider as an input.

这篇关于如何发挥在C#中的MP3流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆