Reputation: 80
I need to use microphone in my flutter web application. I tried the following code but it only works if i request camera
.
final perm = await html.window.navigator.permissions.query({"name": "camera"});
if (perm.state == "denied") {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("Oops! Camera access denied!"),
backgroundColor: Colors.orangeAccent,
));
return;
}
final stream = await html.window.navigator.getUserMedia(video: true);
Upvotes: 3
Views: 4570
Reputation: 11
// ignore: avoid_web_libraries_in_flutter
import 'dart:html';
final permissions = await window.navigator
.getUserMedia(
audio: true,
)
.then((value) => true);
print('permissionss $permissionss');
Upvotes: 1
Reputation: 329
try this :
PermissionStatus permission = await window.navigator.permissions.query({'name': 'microphone'});
now you know that you have permission or not. granted if have permission and prompt if not.(or denied if blocked) but in case of prompting dialog to get permission I use a trick and I send a request to get UserMedia for the first time and it's show the request dialog.
await navigator.mediaDevices.getUserMedia(mediaConstraints);
As far as I know the browsers are not support for sending direct request for permission and you should use some tricks to show the dialog like above.
Upvotes: 2