Exemplo n.º 1
0
        private WaveStream CreateInputStream()
        {
            WaveChannel32 inputStream;

            Stream stream = Subsonic.StreamSong(currentSong.id);

            // Try to move this filling of memory stream into the background...
            Stream ms = new MemoryStream();

            byte[] buffer = new byte[32768];
            int    read;

            while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                playerThread.ReportProgress(50);

                ms.Write(buffer, 0, read);
            }

            ms.Position = 0;

            WaveStream mp3Reader          = new Mp3FileReader(ms);
            WaveStream pcmStream          = WaveFormatConversionStream.CreatePcmStream(mp3Reader);
            WaveStream blockAlignedStream = new BlockAlignReductionStream(pcmStream);

            inputStream = new WaveChannel32(blockAlignedStream);

            // we are not going into a mixer so we don't need to zero pad
            //((WaveChannel32)inputStream).PadWithZeroes = false;
            volumeStream = inputStream;

            //var meteringStream = new MeteringStream(inputStream, inputStream.WaveFormat.SampleRate / 10);
            //meteringStream.StreamVolume += new EventHandler<StreamVolumeEventArgs>(meteringStream_StreamVolume);

            return(volumeStream);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method that plays whatever the current song is
        /// </summary>
        private void playSong()
        {
            skipThis = false;
            Stream stream = Subsonic.StreamSong(currentSong.id);

            // Try to move this filling of memory stream into the background...
            Stream ms = new MemoryStream();

            byte[] buffer = new byte[32768];
            int    read;

            while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                playerThread.ReportProgress(50);

                ms.Write(buffer, 0, read);
            }

            ms.Position = 0;
            Mp3FileReader mp3Reader          = new Mp3FileReader(ms);
            WaveStream    blockAlignedStream =
                new BlockAlignReductionStream(
                    WaveFormatConversionStream.CreatePcmStream(mp3Reader));
            WaveOut waveOut;

            waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
            waveOut.Init(blockAlignedStream);
            waveOut.Play();
            playState = PlaybackState.Playing;
            bool songEnd = false;

            while (playState != PlaybackState.Stopped && !songEnd && !skipThis)
            {
                if (waveOut.PlaybackState == PlaybackState.Stopped)
                {
                    songEnd = true;
                }
                else
                {
                    switch (playState)
                    {
                    case PlaybackState.Paused:
                        waveOut.Pause();
                        break;

                    case PlaybackState.Playing:
                        if (waveOut.PlaybackState != PlaybackState.Playing)
                        {
                            waveOut.Play();
                        }
                        else
                        {
                            int progress = (int)(100.0 * mp3Reader.CurrentTime.TotalSeconds / mp3Reader.TotalTime.TotalSeconds);
                            playerThread.ReportProgress(progress);
                            Thread.Sleep(100);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            //if (playState == PlaybackState.Stopped)
            waveOut.Stop();
            //waveOut.Dispose();
        }