Hello, i am about to make an Audiomanager Library, but to have clearer code, i would like to nest the SetVolume Member
A.I:
So i would like to be able to aml.SetVolume.Music for STREAM_MUSIC or aml.SetVolume.Ringer for STREAM_RING
instead of aml.SetVolumeMusic or aml.SetVolumeRinger
Here is part of my code for the Library:
Any Hints or better code Example, something like an empty Library with nested Member Placeholders or such would be much appreciated.
A.I:
B4X:
dim aml as AudioManagerLib 'that would be my lib
aml.initialize("") 'no events
aml.SetVolume.Music ' keep in mind that ".Music" Part, for not it is aml.SetVolumeMusic
So i would like to be able to aml.SetVolume.Music for STREAM_MUSIC or aml.SetVolume.Ringer for STREAM_RING
instead of aml.SetVolumeMusic or aml.SetVolumeRinger
Here is part of my code for the Library:
B4X:
import android.media.AudioManager;
import android.view.KeyEvent;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@Version(value = 1)
@ShortName("AudioManagerLib")
public class AudioManagerLib {private AudioManager mAudioManager;
public AudioManagerLib() {
}
/**
* Minimum APK is 19 for this Method
* Just type (""), no events in this Library
* Example:
* <code> Dim aml as AudioManagerLib</code>
* <code> aml.initialize("")</code>
*/
public void initialize(final BA ba, String EventName){
mAudioManager = (AudioManager)ba.applicationContext.getSystemService(ba.applicationContext.AUDIO_SERVICE);
}
/**
* Minimum APK is 19 for this Method
* Toggles Play/Pause Audio from any active Player
* Example:
* <code> Dim aml as AudioManagerLib</code>
* <code> aml.initialize("")</code>
* <code> aml.TogglePLayPause</code>
*/
public void TogglePLayPause() {
KeyEvent downEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
mAudioManager.dispatchMediaKeyEvent(downEvent);
KeyEvent upEvent = new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
mAudioManager.dispatchMediaKeyEvent(upEvent);
}
public void SetVolumeMusic(int i){
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0);
}
}
Any Hints or better code Example, something like an empty Library with nested Member Placeholders or such would be much appreciated.