Sound control in android fragment - android

If I add two Fragment to one Activity, each playing different media, is there a way to mute the sound coming from one Fragment while the other plays full volume?
From my research, it seems you can only control the devices volume with code, thus if two media are playing, they'll inherit the same volume.
Any idea about getting around this?

you can set volume for every mediaplayer. api

Related

Android: AudioManager for audio, is there a equivalent for Video

For android, I've researched for controlling Audio using AudioManager. Will there be one for video which I can control the video player to play/stop/pause.
The purpose of AudioManager isn't really to control audio playback, but to control such properties as volume, audio mode, and so on. If there is a media player in the background, that doesn't really mean that you control it, you can only send certain requests to the AudioManager which cause the system either to take some actions regarding the audio, or to send some events, which the audio player may respond to. So you don't have direct control over the other application.
Likewise, there is no system service which will make the video pause. The best equivalent of AudioManager you have which controls what is shown on the screen is WindowManager, but I think it's obvious that it can't be used to make a video player pause.
Your best bet for controlling an external video player would be to look up its intents, it may have some ways to control the playback from outside. This, of course, will be application specific.
There is no such API like VideoManager
You can handle videos through Primary API MediaPlayer and also see this useful article of multiple ways to handle videos

Android, control the volume of a background sound

How can I control the volume of a background sound?
I'm making a game, and in some states I want to increase or decrease the background sound.
I have tried some things with MediaPlayer and SoundPool, but it did't do what I wanted.
I dont want to change the phone volume, but the volume of the sound. Is this possible? If yes how?
Cheers
You haven't told use what "some things with MediaPlayer and SoundPool" means, or shown us any code, so it's hard to say exactly what the problem might be.
If you want to make the volume keys modify the volume of your app's music rather than the voice call volume, you might be missing a call to setVolumeControlStream (e.g. setVolumeControlStream(AudioManager.STREAM_MUSIC);).
Refer to "Controlling Your App’s Volume and Playback" in the Android developer documentation for more information.
If you're using the MediaPlayer setVolume method, then keep in mind that the maximum volume you can set is 1.0 (i.e. the original volume of the audio data you're playing).

Issue with volume buttons in android app

My app plays sounds, but the volume buttons only seem to work if the sound is playing. Otherwise if you hit the volume buttons they change the ringer volume instead of the media volume. How can I make it so that while the app is running, hitting the volume buttons always change the media volume? Or is this considered bad practice?
Call this within your activities onCreate().
setVolumeControlStream (AudioManager.STREAM_MUSIC);

Is it possible to overlay custom audio on top of a video?

I want to be able to overlay an audio track onto a video all within the Android API. Is this possible?
I'm not sure if that's what you need, but if you're looking for doing this during playback (not changing the actual video file) you can create two mediaplayers, and set the volume of the one that plays video to 0 using setVolume method.

android embed default audio player in app/activity

I would like to know if it is possible to embed the default audio player into one of my activities. Or at least be able to embed the section that has the play/pause button and the audio track seek bar.
The reason I would like to embed it rather than open it in a new intent (like this:
Intent audioActivity = new Intent(Intent.ACTION_VIEW);
audioActivity.setDataAndType(Uri.parse(getAudioURL()), "audio/*");
startActivity(audioActivity);
)
is that I want the users to be able to read some content within the current activity while listening to the audio. I have been able to use a progress bar which updates based on the progress in the audio track, but this does not look good and i would rather have the look and feel of the default audio player. I know the default video/audio players are not documented very well but if this is at all possible I would like to know. Thanks!
Hi, I would like to know if it is possible to embed the default audio player into one of my activities.
No, sorry.
First, there is no such thing as "the default audio player" as a single entity. Each device has its own "default audio player".
Second, even if there were a single universal "default audio player", there is no way in Android to embed some other application's UI into your own.
Or at least be able to embed the section that has the play/pause button and the audio track seek bar.
No, sorry. See above.
I think what you're looking for is MediaController. This answer has a good example of how to use this, though I'm not sure if it is possible to have the controls displaying all the time (they disappear after 3 seconds in the example):
How can I show a MediaController while playing audio in Android?
There's another discussion of it here:
How to implement an audio player for Android using MediaPlayer And MediaController?

Categories

Resources