Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startStream not working in web #324

Closed
naveenbharadwaj19 opened this issue May 27, 2024 · 6 comments
Closed

startStream not working in web #324

naveenbharadwaj19 opened this issue May 27, 2024 · 6 comments

Comments

@naveenbharadwaj19
Copy link

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();
  }
}
@llfbandit
Copy link
Owner

Does your browser logs something in the console? No exception in your _startRecording method?
Which version of record_web do you use? Current version is 1.1.1

I can't reproduce it.

@naveenbharadwaj19
Copy link
Author

I'm not getting any logs. I've added try and catch no exception found. Where to find record_web version? i've added only record package

 void _startRecording() async {
    try {
      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');
    }
    } catch (e) {
      print("error in start recording : $e");
    }
    
  }

@llfbandit
Copy link
Owner

You can find record_web reference in your pubspec.lock file.
Do you also reproduce it with the example project?

I will need more info otherwise I won't be able to help you here...

@naveenbharadwaj19
Copy link
Author

record_web:
dependency: transitive
description:
name: record_web
sha256: "0ef370d1e6553ad33c39dd03103b374e7861f3518b0533e64c94d73f988a5ffa"
url: "https://pub.dev"
source: hosted
version: "1.1.0"

No i haven't tried with example project

@DanieleMarchei
Copy link

I had the same problem with my code and the example project.
The issue was that my Flutter SDK version was too old, so I ran

flutter upgrade --force

and then

flutter pub get

After that, the example project and my code started working on the browser too.

@llfbandit
Copy link
Owner

This issue should be resolved with 1.1.1 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants