コード例 #1
0
        /// <summary>
        ///   Starts encoding using the given Parameters
        /// </summary>
        /// <param name = "stream"></param>
        /// <param name = "encoderParms"></param>
        public BASSError StartEncoding(int stream)
        {
            BaseEncoder encoder = SetEncoderSettings(stream);

            encoder.EncoderDirectory = _pathToEncoders;
            encoder.OutputFile       = _outFile;
            encoder.InputFile        = null; // Use stdin

            bool encoderHandle = encoder.Start(null, IntPtr.Zero, false);

            if (!encoderHandle)
            {
                return(Bass.BASS_ErrorGetCode());
            }

            long pos        = 0;
            long chanLength = Bass.BASS_ChannelGetLength(stream);

            _isAborted = false;

            byte[] encBuffer = new byte[60000]; // our encoding buffer
            while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING && !_isAborted)
            {
                // getting sample data will automatically feed the encoder
                int len = Bass.BASS_ChannelGetData(stream, encBuffer, encBuffer.Length);
                pos = Bass.BASS_ChannelGetPosition(stream);
                double percentComplete = pos / (double)chanLength * 100.0;

                // Send the message
                msg.MessageData["progress"] = percentComplete;
                queue.Send(msg);
            }

            encoder.Stop();
            return(BASSError.BASS_OK);
        }