/// <summary> /// Callback function /// </summary> /// <param name="objptr"></param> /// <param name="user_data"></param> /// <param name="msg"></param> /// <param name="param1"></param> /// <param name="param2"></param> /// <returns></returns> /// <remarks></remarks> public int MyCallbackFunc(uint objptr, int user_data, TCallbackMessage msg, uint param1, uint param2) { switch (msg) { case TCallbackMessage.MsgEnterVolumeSlideAsync: SetText("EnterFadeAsync"); break; case TCallbackMessage.MsgExitVolumeSlideAsync: SetText("ExitFadeAsync"); FadeFinished = true; break; case TCallbackMessage.MsgStreamBufferDoneAsync: BufferCounter = BufferCounter + 1; SetText("StreamBufferDoneAsync: " + System.Convert.ToString(BufferCounter)); // read more data and push into stream byte[] stream_data = null; int small_chunk = 100000; stream_data = br.ReadBytes(small_chunk); if (stream_data.Length > 0) { player.PushDataToStream(ref stream_data, System.Convert.ToUInt32(stream_data.Length)); } else { byte[] tempMemNewData1 = null; player.PushDataToStream(ref tempMemNewData1, 0); } break; case TCallbackMessage.MsgNextSongAsync: { SetText("MsgNextSongAsync: " + System.Convert.ToString(param1)); NextSong = true; } break; } return 0; }
/// <summary> /// Gets called on average every 500ms. This is a console application, so no SynchronizationContext /// available. This means this function is called on theNetConnection thread /// watch out for that.! /// </summary> private void NC_OnTick(object sender) { // feed zplay with data received from netstream // Minimum buffer voordat we starten met afspelen TStreamStatus status = new TStreamStatus(); zPlay.GetStatus(ref status); // Not playing and buffer has enough data to examine mp3 to start playing if (!status.fPlay && zPlayBuffer.UsedBytes >= 8192) { byte[] tmpBuffer = new byte[8192]; zPlayBuffer.Read(tmpBuffer, 8192); if (!(zPlay.OpenStream(true, true, ref tmpBuffer, 8192, TStreamFormat.sfMp3))) { // Got an error with libzplay Console.WriteLine(zPlay.GetError()); return; } // Start playing audio zPlay.StartPlayback(); } else if (status.fPlay && zPlayBuffer.UsedBytes > 0) { int bufRead = Convert.ToInt32(zPlayBuffer.UsedBytes); byte[] tmpBuffer = new byte[bufRead]; zPlayBuffer.Read(tmpBuffer, bufRead); // Push data into libzplay so it can continue playing audio if (!zPlay.PushDataToStream(ref tmpBuffer, Convert.ToUInt32(bufRead))) { // Got an error with libzplay Console.WriteLine(zPlay.GetError()); return; } } }