Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Streaming with ohLibSpotify and NAudio
28-01-2014, 08:18 PM
Post: #1
Question Streaming with ohLibSpotify and NAudio
Hi,
i'm trying to stream music from ohLibSpotify and play it with NAudio. I also posted a question in StackOverflow.

At first i create a new PlaylistContainer at the LoggedIn callback and open a existing Playlist in the ContainerLoaded callback. After that i call an implemented Play Method with the first Track of the Playlist:
Code:
public void Play(Track track)
{
    session.PlayerLoad(track);
    session.PlayerPlay(true);
}

I implemented the MusicDelivery callback from ohLibSpotify:
Code:
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

    byte[] frames_copy = new byte[num_frames];
    Marshal.Copy(frames, frames_copy, 0, num_frames);

    bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(format.sample_rate, format.channels));
    bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(40);            
    bufferedWaveProvider.AddSamples(frames_copy, 0, num_frames);
    bufferedWaveProvider.Read(frames_copy, 0, num_frames);

    if (_waveOutDeviceInitialized == false)
    {
        IWavePlayer waveOutDevice = new WaveOut();
        waveOutDevice.Init(bufferedWaveProvider);
        waveOutDevice.Play();
        _waveOutDeviceInitialized = true;
    }
}

And overwrote the stats in GetAudioBufferStats:
Code:
public override void GetAudioBufferStats(SpotifySession session, out AudioBufferStats stats)
{
    stats.samples = 2048 / 2;   //???
    stats.stutter = 0;          //???
}

The program doesn't produce any errors, but i also can't hear music from the speakers. Can anybody help me with my problem?
Find all posts by this user


Messages In This Thread
Streaming with ohLibSpotify and NAudio - freakimkaefig - 28-01-2014 08:18 PM

Forum Jump: