在查看了这、这和这帖子之后,我了解到我必须使用NAudio之类的东西来播放stream音频,而且播放歌曲是通过以下方式完成的:
libspotify.sp_session_player_load(_sessionPtr, trackPtr);
libspotify.sp_session_player_play(_sessionPtr, true);现在,如果我正确理解,我将接收stream作为原始PCM数据。我怎样才能访问这些数据?
根据文档,我看到我必须填充libspotify.sp_audioformat
我该怎么做呢?从哪来的?
我正在查看这项目(Jamcast),他们做的事情如下:
libspotify.sp_audioformat format = (libspotify.sp_audioformat)Marshal.PtrToStructure(formatPtr, typeof(libspotify.sp_audioformat));有人能给我指明正确的方向吗?我完全不知道如何检索stream
发布于 2015-01-04 05:56:27
最后,我跟踪了这和这问题。他们帮了我很多忙。
我不得不这样做:
public static libspotify.sp_error LoadPlayer(IntPtr trackPtr)
{
bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat());
bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(120);
return libspotify.sp_session_player_load(_sessionPtr, trackPtr);
}
public static void Play()
{
libspotify.sp_session_player_play(_sessionPtr, true);
IWavePlayer waveOutDevice = new WaveOut();
waveOutDevice.Init(bufferedWaveProvider);
waveOutDevice.Play();
while (waveOutDevice.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(100);
}
}
private static int music_delivery(IntPtr sessionPtr, IntPtr formatPtr, IntPtr framesPtr, int num_frame)
{
if (num_frame == 0)
return 0;
libspotify.sp_audioformat format = (libspotify.sp_audioformat)Marshal.PtrToStructure(formatPtr, typeof(libspotify.sp_audioformat));
byte[] buffer = new byte[num_frame * sizeof(Int16) * format.channels];
Marshal.Copy(framesPtr, buffer, 0, buffer.Length);
bufferedWaveProvider.AddSamples(buffer, 0, num_frame * sizeof(Int16) * format.channels);
if (Session.OnAudioDataArrived != null)
Session.OnAudioDataArrived(buffer);
return num_frame;
}https://stackoverflow.com/questions/27762185
复制相似问题