【问题标题】:How to play a spotify music stream如何播放 Spotify 音乐流
【发布时间】:2012-07-12 12:50:31
【问题描述】:

首先,我是音频编程的新手,所以请耐心等待。

我正在尝试使用 NAudio 或 BASS.Net 或任何其他 .net 音频库播放 Spotify 音乐。

据我所知,libspotify 将音乐作为原始 PCM 数据提供。 what is the sample rate of spotify stream (libspotify)?

来自 spotify 文档: 样本以整数形式提供,请参阅 sp_audioformat。一帧由与通道数相同的样本数组成。 IE。交错在样本级别。

当我尝试播放歌曲时,spotify 使用 8192 字节缓冲区进行回调

频道 = 2

sample_rate = 44100

num_frames = 2048

我需要一些帮助来将此信息翻译成 NAudio 术语。

我也尝试过使用 Spotify 到 Bass.Net 示例 (BASSPlayer.cs)。但是我还没有从我的扬声器中听到一个音符。 我试过用 NAudio 和 Bass.NET 播放一首 mp3 歌曲,效果很好,所以扬声器音量还可以。 https://github.com/Alxandr/SpotiFire/blob/master/SpotiFire.Server/BASSPlayer.cs

【问题讨论】:

    标签: spotify naudio bass.dll


    【解决方案1】:

    NAudio 取得了突破。这就是我想出的,通过使用试错法。我不确定这是否是从 sampleRate/channels 计算参数的正确方法...

    但是这首歌正在播放:-)

    IWavePlayer waveOutDevice = new WaveOut();
    
    using (var pcmStream = new FileStream(PcmFile, FileMode.Open))
    {
        const int songDuration = 264000;
        const int sampleRate = 44100;
        const int channels = 2;
        var waveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, sampleRate * channels, 1, sampleRate * 2 * channels, channels, 16);
        var waveStream = new RawSourceWaveStream(pcmStream, waveFormat);
    
        waveOutDevice.Init(waveStream);
        waveOutDevice.Play();
        Thread.Sleep(songDuration);
        waveOutDevice.Stop();
        waveStream.Close();
        waveOutDevice.Dispose();
    }
    

    【讨论】:

    • 我知道这是一篇旧帖子。但是,PcmFile 是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多