Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Streaming with ohLibSpotify and NAudio
06-02-2014, 03:19 PM
Post: #5
RE: Streaming with ohLibSpotify and NAudio
From a quick glance:

1. Use size = num_frames * format.channels * 2. (16-bit samples mean that you have two bytes per sample.)

2. Set stats.samples = _bufferedWaveProvider.BufferedBytes /2. See my answer to your StackOverflow question. You need to tell libspotify how many samples are in your buffer. If you keep telling libspotify a constant number it might assume you aren't playing audio and stop giving you any until you tell it your buffer is running out. (That said, I'm not sure what heuristics it actually uses. I seem to recall that if you feed it bad data it tends to ignore you and just play on regardless.)

3. Your MusicDeliveryCallback is supposed to return an int, telling libspotify how many frames you consumed. I'm not sure how you've managing to use a method that returns void - perhaps you could show more of the code? In this example, you should return num_frames. (Note that AddSamples will by default discard samples if you try to over-fill your buffer. Ideally you would avoid that by not consuming all the bytes from libspotify. If you return a value less than num_frames it will send you the unconsumed frames again on the next call.)

I *think* that should work, but I'm not sure based on what you've described. Is it possible libspotify is just providing you with silence? Is the track valid and loaded? Does the track start with a lot of silence or is it just really quiet? Perhaps you should try printing out the contents of the array. Is it all 0s? Can you verify that your callback is being invoked regularly?
Visit this user's website Find all posts by this user


Messages In This Thread
RE: Streaming with ohLibSpotify and NAudio - andreww - 06-02-2014 03:19 PM

Forum Jump: