Example #1
0
        /// <summary>
        /// Reads a frame from the MP3 stream.  Returns whether the operation was successful.  If it wasn't,
        /// the source stream is probably at its end.
        /// </summary>
        private bool ReadFrame()
        {
            // Read a frame from the bitstream.
            javazoom.jl.decoder.Header header = JZBitStream.readFrame();
            if (header == null)
            {
                return(false);
            }

            // Set the channel count and frequency values for the stream.
            ChannelCountRep = (header.mode() == javazoom.jl.decoder.Header.SINGLE_CHANNEL)?(short)1:(short)2;
            FrequencyRep    = header.frequency();

            // Decode the frame.
            javazoom.jl.decoder.Obuffer decoderOutput = JZDecoder.decodeFrame(header, JZBitStream);

            // Apparently, the way JavaZoom sets the output buffer
            // on the decoder is a bit dodgy. Even though
            // this exception should never happen, we test to be sure.
            if (decoderOutput != QueueOBuffer)
            {
                throw new System.ApplicationException("Output buffers are different.");
            }

            // And we're done.
            JZBitStream.closeFrame();
            return(true);
        }
Example #2
0
        /// <summary>
        /// Reads a frame from the MP3 stream.  Returns whether the operation was successful.  If it wasn't,
        /// the source stream is probably at its end.
        /// </summary>
        private bool ReadFrame()
        {
            javazoom.jl.decoder.Header header;
            try
            {
                ////System.Diagnostics.Trace.WriteLine("ReadFrame -BitStream read frame");
                // Read a frame from the bitstream.
                header = JZBitStream.readFrame();
                if (header == null)
                {
                    return(false);
                }
                ////System.Diagnostics.Trace.WriteLine("ReadFrame -BitStream read frame - done");
            }
            catch (Exception e)
            {
                return(false);
            }

            try
            {
                ////System.Diagnostics.Trace.WriteLine("ReadFrame -BitStream sort out ChannelCountRep");
                // Set the channel count and frequency values for the stream.
                if (header.mode() == javazoom.jl.decoder.Header.SINGLE_CHANNEL)
                {
                    ChannelCountRep = (short)1;
                }
                else
                {
                    ChannelCountRep = (short)2;
                }
                ////System.Diagnostics.Trace.WriteLine("ReadFrame - get frequency");
                FrequencyRep = header.frequency();
                ////System.Diagnostics.Trace.WriteLine("ReadFrame - decode frame");
                // Decode the frame.
                javazoom.jl.decoder.Obuffer decoderOutput = JZDecoder.decodeFrame(header, JZBitStream);
                // Apparently, the way JavaZoom sets the output buffer
                // on the decoder is a bit dodgy. Even though
                // this exception should never happen, we test to be sure.
                ////System.Diagnostics.Trace.WriteLine("ReadFrame - check to see if out buffers are different");
                if (decoderOutput != QueueOBuffer)
                {
                    throw new System.ApplicationException("Output buffers are different.");
                }

                // And we're done.
            }
            finally
            {
                ////System.Diagnostics.Trace.WriteLine("ReadFrame - close the frame");
                // No resource leaks please!
                if (JZBitStream != null)
                {
                    JZBitStream.closeFrame();
                }
            }
            ////System.Diagnostics.Trace.WriteLine("ReadFrame - end");
            return(true);
        }