Exemple #1
0
        protected override void OnOpen()
        {
            _validated = Context.QueryString["token"] == _token;
            if (!_validated)
            {
                Context.WebSocket.Close(4000);
            }
            _capture = new WasapiLoopbackCapture(0, new WaveFormat());
            _capture.Initialize();
            _capture.Start();
            var wsStream = new WebSocketStream(this);

            Console.WriteLine($"Captured audio format: {_capture.WaveFormat}");
            IWriteable encoder = null;

            switch (_format)
            {
            case AudioFormat.AAC:
                encoder = new AacEncoder(_capture.WaveFormat, wsStream, 128000,
                                         TranscodeContainerTypes.MFTranscodeContainerType_ADTS);
                break;

            case AudioFormat.MP3:
                encoder = MediaFoundationEncoder.CreateMP3Encoder(_capture.WaveFormat, wsStream, 320000);
                break;
            }

            _capture.DataAvailable += (sender, e) => { encoder?.Write(e.Data, e.Offset, e.ByteCount); };
        }
        protected override void OnOpen()
        {
            _validated = Context.QueryString["token"] == _token;
            var capture = new WasapiLoopbackCapture();

            capture.Initialize();
            capture.Start();
            var wsStream = new WebSocketStream(this);
            var encoder  = MediaFoundationEncoder.CreateMP3Encoder(capture.WaveFormat, wsStream);

            capture.DataAvailable += (sender, e) => encoder.Write(e.Data, e.Offset, e.ByteCount);
        }