Get list of available audio devices on iOS/Android with Flutter - flutter

In my flutter application I want to switch between headphone to speaker vice versa.
I am looking for a way to get the available audio devices and to switch them.
I found;
final mediaDevices = navigator.mediaDevices;
var devices = await mediaDevices.getSources();
It is not clear to me what this navigator is?
May I know whether there is a way to do this?

Add audio_service package to your project and use
List<AudioDevice> audioDevices = (await session.getDevices()).toList();
to get the list of audio devices present
refer: https://pub.dev/packages/audio_session

Related

How to mute mic in iOS so that yellow mic icon disappears

I'm working on an flutter app that uses a Janus WebRTC server to create voicechat rooms. The app has buttons to mute and unmute the microphone. But on iOS, even though i've already muted the mic by disabling the audiotracks, the native icon is still present.
My way of muting the mic is something like this.
myStream.getAudioTracks().forEach((track){
track.enabled = false;
});
I've also tried:
myStream.getAudioTracks().forEach((track){
track.setMicrophoneMute(true);
});
And even though it works and the mic is muted. The native microphone yellow icon keeps showing up.
Screenshot Here
I'm using a modified version of the package janus_client from this source: https://github.com/shivanshtalwar0/flutter_janus_client
It should work if you stop the tracks instead.
myStream.getAudioTracks().forEach((track){
track.stop();
});
This will make the icon go away but it will also stop the stream. This is of course not so good in case you want to unmute the stream again. Luckily calling getUserMedia() with the same parameters normally works without triggering another user prompt. That's still not ideal since unmuting will then not be instant anymore but it currently seems to be the only workaround to get rid of the icon.

Flutter - Audio Player

hello i am new to flutter
i am trying to play audio files from url or network but which to use because
i searched google it showed many but which one to use.
if possible can show an example on how to create like below image
i want to create an audio player like this
kindly help...
Thanks in Advance!!!
An answer that shows how to do everything in your screenshot would probably not fit in a StackOverflow answer (audio code, UI code, and how to extract audio wave data) but I will give you some hopefully useful pointers.
Using the just_audio plugin you can load audio from these kinds of URLs:
https://example.com/track.mp3 (any web URL)
file:///path/to/file.mp3 (any file URL with permissions)
asset:///path/to/asset.mp3 (any Flutter asset)
You will probably want a playlist, and here is how to define one:
final playlist = ConcatenatingAudioSource(children: [
AudioSource.uri(Uri.parse('https://example.com/track1.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track2.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track3.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track4.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track5.mp3')),
]);
Now to play that, you create a player:
final player = AudioPlayer();
Set the playlist:
await player.setAudioSource(playlist);
And then as the user clicks on things, you can perform these operations:
player.play();
player.pause();
player.seekToNext();
player.seekToPrevious();
player.seek(Duration(milliseconds: 48512), index: 3);
player.dispose(); // to release resources once finished
For the screen layout, note that just_audio includes an example which looks like this, and since there are many similarities to your own proposed layout, you may get some ideas by looking at its code:
Finally, for the audio wave display, there is another package called audio_wave. You can use it to display an audio wave, but the problem is that there is no plugin that I'm aware of that provides you access to the waveform data. If you really want a waveform, you could possibly use a fake waveform (if it's just meant to visually indicate position progress), otherwise either you or someone will need to write a plugin to decode an audio file into a list of samples.

How can I adjust microphone input levels in HoloLens?

In our communications app, some people's voices are too quiet. So we want to be able to change the system level of their microphone input.
I searched through all the Windows Universal App samples and Unity documentation and I couldn't find how to change the volume of the Windows microphone (on Windows or HoloLens).
I found that the property to adjust is the AudioDeviceController.VolumePercent property. The following code implements this:
MediaCapture mediaCapture = new MediaCapture();
var captureInitSettings = new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Audio
};
await mediaCapture.InitializeAsync(captureInitSettings);
mediaCapture.AudioDeviceController.VolumePercent = volumeLevel;
I confirmed that this code works on Desktop and HoloLens. It changes the system level, so it's automatically persisted, and would affect all apps.

Is it possible to stream endless audio in flutter?

I'm developing an online radio app in flutter and I'm looking for an audio player which supports endless audio streaming from a certain URL (e.g. http://us4.internet-radio.com:8258/stream?type=http). It is highly desirable for it to be supported both on iOS and Android.
Is there such an option in flutter?
From what I've found, there are no solutions that satisfy me needs. The closest one is fluttery_audio, but, apparently, it doesn't support endless audio.
I apologize for my jargon with 'endless audio streaming', I'm not really sure what's the technical name for an online radio player is.
Try with flutter_webview_plugin and hide it.
https://pub.dev/packages/flutter_webview_plugin
final flutterWebviewPlugin = new FlutterWebviewPlugin();
flutterWebviewPlugin.launch(url, hidden: true);
You can also try flutter radio package, Check working app here...
Source code

How to restrict use of third party camera app from your app

I have power cam app which is a third party camera app installed in my device. I am opening camera from my app, when i click on open camera button, it gives me choice of cameras like device camera along with power cam. I want that on clicking the open camera button, device camera should get open, in other words i want to restrict the user from using power cam from my app
If you want to run only the official camera, you can use the following intent (based on the official tutorial):
static final int REQUEST_IMAGE_CAPTURE = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.setPackage("com.android.camera");
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
Unfortunately, many devices come with custom preinstalled camera apps, and com.android.camera may not be available.
If you want to filter out specific packages that you don't like, you must prepare your own chooser dialog (see example here). You can skip the dialog if you know which package to choose. E.g. it is possible to filter the list to only include "system" packages. But even then, there is no guarantee that there will be only one system package that is registered to fulfill the MediaStore.ACTION_IMAGE_CAPTURE intent.