Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Streaming with ohLibSpotify and NAudio
05-02-2014, 08:10 PM
Post: #4
RE: Streaming with ohLibSpotify and NAudio
Hi,
thanks for helping me with my problem.

I think I'm getting closer. I updated my code based on your suggestions:

Code:
public void Play(Track track)
{
    _bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat());
    _bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(120);

    _session.PlayerLoad(track);
    _session.PlayerPlay(true);

    IWavePlayer waveOutDevice = new WaveOut();
    waveOutDevice.Init(_bufferedWaveProvider);
    waveOutDevice.Play();
}

public void MusicDeliveryCallback(SpotifySession session, AudioFormat format, IntPtr frames, int num_frames)
{
    //format.channels = 2, format.samplerate = 44100, format.sample_type = Int16NativeEndian
    //frames = ?
    //num_frames = 2048

    var size = num_frames * format.channels * 4;
    byte[] _copiedFrames = new byte[size];
    Marshal.Copy(frames, _copiedFrames, 0, size);   //Copy Pointer Bytes to _copiedFrames
    _bufferedWaveProvider.AddSamples(_copiedFrames, 0, size);
}

I'm getting sound output with this, but it's a strange noise with stutters. I think some values should be adjusted but don't know which ones. I tried to decrease the value of size which leads to no sound. I also tried to increase the value of size which leads to even faster stutters and noise.
Find all posts by this user


Messages In This Thread
RE: Streaming with ohLibSpotify and NAudio - freakimkaefig - 05-02-2014 08:10 PM

Forum Jump: