Esempio n. 1
0
        private static int MusicDeliveryCallback(IntPtr sessionPtr, IntPtr formatPtr, IntPtr framesPtr, int num_frames)
        {
            Session s = GetSession(sessionPtr);

            if (s == null)
            {
                return(0);
            }

            int consumed = 0;

            byte[] samplesBytes = null;
            libspotify.sp_audioformat format = (libspotify.sp_audioformat)Marshal.PtrToStructure(formatPtr, typeof(libspotify.sp_audioformat));

            if (num_frames > 0)
            {
                samplesBytes = new byte[num_frames * format.channels * 2];
                Marshal.Copy(framesPtr, samplesBytes, 0, samplesBytes.Length);
            }
            else
            {
                samplesBytes = new byte[0];
            }

            if (s.OnMusicDelivery != null)
            {
                MusicDeliveryEventArgs e = new MusicDeliveryEventArgs(format.channels, format.sample_rate, samplesBytes, num_frames);
                s.OnMusicDelivery(s, e);

                consumed = e.ConsumedFrames;
            }

            return(consumed);
        }
Esempio n. 2
0
        void HandleOnMusicDelivery(Session sender, MusicDeliveryEventArgs e)
        {
            try
            {
                // Write to LAME.
                LameEncoder.Write(e.Samples);

                // Don't forget to set how many frames we consumed
                e.ConsumedFrames = e.Frames;
            }
            catch (Exception ex)
            {
            #if DEBUG
                if (Log.IsErrorEnabled)
                    Log.Error("Exception", ex);
            #endif
            }
        }
Esempio n. 3
0
        void SpotifySession_OnMusicDelivery(Session sender, MusicDeliveryEventArgs e)
        {
            if (e.Samples.Length > 0)
            {

                if (player == null)
                {
                    //player = new AlsaPlayer(e.Rate / 2); // Buffer 500ms of audio
                    player = new BassPlayer();

                    Console.WriteLine("Player created");
                }

                // Don't forget to set how many frames we consumed
                e.ConsumedFrames = player.EnqueueSamples(new AudioData(e.Channels, e.Rate-12, e.Samples, e.Frames));

                /*X.Maximum = (float)currentTrack.Duration;
                X.Value  +=10;*/

            }
            else
            {
                e.ConsumedFrames = 0;
            }
        }
Esempio n. 4
0
        private static int MusicDeliveryCallback(IntPtr sessionPtr, IntPtr formatPtr, IntPtr framesPtr, int num_frames)
        {
            Session s = GetSession(sessionPtr);
            if (s == null)
                return 0;

            int consumed = 0;

            byte[] samplesBytes = null;
            libspotify.sp_audioformat format = (libspotify.sp_audioformat)Marshal.PtrToStructure(formatPtr, typeof(libspotify.sp_audioformat));

            if(num_frames > 0)
            {
                samplesBytes = new byte[num_frames * format.channels * 2];
                Marshal.Copy(framesPtr, samplesBytes, 0, samplesBytes.Length);
            }
            else
                samplesBytes = new byte[0];

            if(s.OnMusicDelivery != null)
            {
                MusicDeliveryEventArgs e = new MusicDeliveryEventArgs(format.channels, format.sample_rate, samplesBytes, num_frames);
                s.OnMusicDelivery(s, e);

                consumed = e.ConsumedFrames;
            }

            return consumed;
        }
Esempio n. 5
0
 void session_MusicDeliver(ISession sender, MusicDeliveryEventArgs e)
 {
     e.ConsumedFrames = player.EnqueueSamples(e.Channels, e.Rate, e.Samples, e.Frames);
 }
Esempio n. 6
0
		static void HandleOnMusicDelivery(Session sender, MusicDeliveryEventArgs e)
		{
			if(e.Samples.Length > 0)
			{
				if(player == null)
				{
                    if (IsWindows())
                    {
                        // Use BASS on Windows.                        
                        player = new BASSPlayer();
                        Console.WriteLine("BASSPlayer created");
                    }
                    else
                    {
                        player = new AlsaPlayer(e.Rate / 2); // Buffer 500ms of audio
                        Console.WriteLine("AlsaPlayer created with buffer size {0} frames", e.Rate / 2);
                    }
				}
				
				// Don't forget to set how many frames we consumed
				e.ConsumedFrames = player.EnqueueSamples(e.Channels, e.Rate, e.Samples, e.Frames);
			}
			else
			{
				e.ConsumedFrames = 0;
			}
		}