Skip to content

startStream not working in web #324

Closed
@naveenbharadwaj19

Description

@naveenbharadwaj19

Package version
5.1.0

Environment

  • OS: windows
  • Browser : Chrome,edge

I've tried to listen to the stream once I start recording, but the problem is that I'm not receiving any data in the stream, and the print statement isn't getting invoked. I've tested the same app on Android with AudioEncoder.pcm16bits, and it's working fine.

class AudioRecorderWidget extends StatefulWidget {
  @override
  _AudioRecorderWidgetState createState() => _AudioRecorderWidgetState();
}

class _AudioRecorderWidgetState extends State<AudioRecorderWidget> {
  bool _isRecording = false;
  AudioRecorder recorder = AudioRecorder();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Audio Recorder'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: _isRecording ? null : _startRecording,
              child: Text('Start Recording'),
            ),
            SizedBox(height: 20),
            ElevatedButton(
              onPressed: _isRecording ? _stopRecording : null,
              child: Text('Stop Recording'),
            ),
          ],
        ),
      ),
    );
  }

  void _startRecording() async {
    bool isAvailable = await recorder.hasPermission();
    if (isAvailable) {
      setState(() {
        _isRecording = true;
      });
      var stream = await recorder
          .startStream(const RecordConfig(encoder: AudioEncoder.pcm16bits,
          ));

      stream.listen((event) {
        print("listening....");
      });
    } else {
      // Handle permissions not granted
      print('Permissions not granted');
    }
  }

  void _stopRecording() async {
    setState(() {
      _isRecording = false;
    });
    await recorder.stop();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions