Control device media volume using Seekbar in Sketchware App
1 minute read
The Seekbar can be set to control media volume of device, when any media is playing, with the use of simple codes in add source directly block in Sketchware.
It only works if any audio is playing, otherwise it doesn't change the device audio volume.
In LOGIC area, in onCreate event add following code in end using add source directly block:
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); seekbar1.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
Create a More block and put following code in it using an add source directly block.
}
AudioManager audioManager;
private void nothing() {
In Seekbar onProgressChanged event add following code using add source directly block:
textview1.setText("Music Volume : " + _progressValue);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, _progressValue, 0);
That's all. Save and run the project. You should be able to change the volume of any music playing in device using the Seekbar.
It only works if any audio is playing, otherwise it doesn't change the device audio volume.