This app is working fine when the app is opened or the app is on the screen. Volume is changing when app activity is opened. But when app is running on background, volume is not changing with slider. If I set the stream to alarm/ringtone, it works fine. But I am facing problem when the stream mode is Music. This code also works on android 11 or less. But it only facing problem with android 12. How can I run the program on android 12?
audioManager = (AudioManager) alarm_service.this.getSystemService(Context.AUDIO_SERVICE);
set_sound=customView.findViewById(R.id.sound_line);
set_sound.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, AudioManager.FLAG_SHOW_UI);
v.vibrate(20);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
seekBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
seekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
seekBar.getProgressDrawable().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN);
seekBar.getThumb().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN);
}
});
Related
I am working on android app where i want to increase the Zoom level of camera. Actually i want to make the camera zoom like the Google Play Store app mention in the link.
Mega zoom camera android app
I can use the Mobile phone zoom feature but it is very low if i compare it with the zoom function provided in the above given app.
Below is the code where i control zoom with zoom-control button
zoomSeekBar.setOnSeekBarChangeListener(null);
zoomSeekBar.setMax(preview.getMaxZoom());
zoomSeekBar.setProgress(preview.getMaxZoom()-preview.getCameraController().getZoom());
zoomSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
preview.zoomTo(preview.getMaxZoom() - progress);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
I need my in-app volume seekbar to change the volume of the audio in my app only. I need it to be totally separate from the main volume of the device. Everything I find changes the device volume when I change the slider in my app.
I want users to have the option of playing audio in my app at a low volume, but maybe still have their device turned up so phone calls and alarms and such could still be at their normal high volume.
How can I make a seekbar in my app only control audio in my app and not bother other device volumes? Here is the code I am using:
Called in onCreate method:
VolumeControls();
Outside of that:
private void VolumeControls() {
final TextView txtView = (TextView)findViewById(R.id.textView1);
SeekBar seekBar = (SeekBar)findViewById(R.id.sbVolume);
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
seekBar.setMax(audioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
seekBar.setProgress(audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC));
txtView.setText(String.valueOf(audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC)));
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar arg0){
}
public void onStartTrackingTouch(SeekBar arg0){
}
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2)
{
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
progress, 0);
txtView.setText(String.valueOf(progress));
}
});
}
Below is the code of the seekbar for my audio player. Currently, I am able to move it along, but once I lift my finger, it returns to the original song duration again. How can I navigate to any time of the song through the seekbar?
//initialize seekbar
seekbar = (SeekBar)findViewById(R.id.seekBar1);
seekbar.setClickable(false); //this should be set to true, correct?
Below is where seekbar is involved, in play button onclick
public void play(View view){
mediaPlayer.start();
finalTime = mediaPlayer.getDuration();
startTime = mediaPlayer.getCurrentPosition();
if(oneTimeOnly == 0){
seekbar.setMax((int) finalTime);
oneTimeOnly = 1;
}
seekbar.setProgress((int)startTime);
}
And it is also involved in UpdateSongTime method
private Runnable UpdateSongTime = new Runnable() {
public void run() {
startTime = mediaPlayer.getCurrentPosition();
startTimeField.setText(String.format("%d:%02d",
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime)))
);
seekbar.setProgress((int)startTime);
myHandler.postDelayed(this, 100);
}
};
Implement SeekBar.OnSeekBarChangeListener. This interface contains three callbacks you can use for managing your audio player:
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// MediaPlayer.seekTo(progress)
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// MediaPlayer.pause()
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// MediaPlayer.seekTo(seekBar.getProgress())
}
In addition, you may want to have your UpdateSongRunnable pause its updates between onStartTrackingTouch() and onStopTrackingTouch(), otherwise it will continue to try to update while you have your finger on the seekbar.
You need to implement the OnSeekBarChangeListener. When you perform certain acts with the SeekBar, these interface's methods are invoked. For example you say you want to move the track playback to a certain time according to where your end-user lifts up her finger. Override the onStartTrackingTouch (SeekBar seekBar) to (if you wish) pause the music and the onStopTrackingTouch (SeekBar seekBar) to start the music again at the time you desire.
Note: The seek bar is passed as a parameter in order for you to check at what time did the user lift her finger up.
I'm using seekbars to adjust the ringtone volume, but it doesn't seem to work on gingerbread. It works fine on 4.1.
ringerVlmSeekBar
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar arg0) {
}
public void onStartTrackingTouch(SeekBar arg0) {
}
//When progress level of seekbar2 is changed
public void onProgressChanged(SeekBar arg0,
int progress, boolean arg2) {
audioManager.setStreamVolume(
AudioManager.STREAM_RING, progress, 0);
}
});
Well since I didn't get any answers or comments, here's the reason that I discovered: different versions of android have different ways of linking the audio streams, which means that on my android 2.3 device, you can't change the notification volume and ringer volume independently. Hopefully this will help anyone who has this same issue.
Im developing one application which used SeekBar to control volume in
MediaPlayer. The problem is when i move the seek bar at that time only the
volume is increased, rest of
the time default volume was set. Here is my code
seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
//Log.i("Seek Bar", "" + validBpm);
mp.setVolume(left, right);
}
public void onStartTrackingTouch(SeekBar seekBar)
{
left=left+20;
right=right+20;
mp.setVolume(left, right);
}
public void onStopTrackingTouch(SeekBar seekBar) {
left=left-20;
right=right-20;
mp.setVolume(left, right);
}
});
Looks like a simple fix although your original questions verbiage is really difficult to understand.
You're trying to use your own formula to set the volume and it doesn't look like those 2 methods are a good place to do it. Those two methods should only fire once, since they are only a startTouch or finishTouch.
You need to be using the "progress" integer provided from the onProgressChanged method to set the volume to the mediaplayer accordingly. This integer is the value of where the user set the seekBar.