Add more functions
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package Audio;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public class AudioPlayer {
|
||||
Bass bass;
|
||||
int deviceid = -1;
|
||||
boolean inited = false;
|
||||
private final Bass bass;
|
||||
private int deviceid = -1;
|
||||
@Getter private boolean inited = false;
|
||||
|
||||
int playbackhandle = 0;
|
||||
float playbackvolume = 1.0f;
|
||||
@@ -48,13 +49,49 @@ public class AudioPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get BASS_DEVICEINFO for a device
|
||||
* @param device device id
|
||||
* @return BASS_DEVICEINFO object or null if failed
|
||||
*/
|
||||
public Bass.BASS_DEVICEINFO GetDeviceInfo(int device){
|
||||
Bass.BASS_DEVICEINFO info = new Bass.BASS_DEVICEINFO();
|
||||
if (bass.BASS_GetDeviceInfo(device, info)){
|
||||
return info;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Device ID with Name
|
||||
* @param name device name
|
||||
* @return device id, or -1 if not found
|
||||
*/
|
||||
public int FindDeviceIDWithName(String name){
|
||||
int result = -1;
|
||||
int ii = 1;
|
||||
while(true){
|
||||
Bass.BASS_DEVICEINFO info = new Bass.BASS_DEVICEINFO();
|
||||
if (bass.BASS_GetDeviceInfo(ii, info)){
|
||||
if (info.name.contains(name)){
|
||||
result = ii;
|
||||
break;
|
||||
}
|
||||
ii++;
|
||||
} else {
|
||||
// gak ada lagi
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open Output Device
|
||||
* @param device device id, starts from 1
|
||||
* @param freq output frequency
|
||||
* @return true if success
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean OpenDevice(int device, int freq){
|
||||
int flag = Bass.BASS_DEVICE_REINIT | Bass.BASS_DEVICE_16BITS | Bass.BASS_DEVICE_MONO | Bass.BASS_DEVICE_FREQ;
|
||||
boolean success = bass.BASS_Init(device, freq, flag);
|
||||
@@ -69,7 +106,8 @@ public class AudioPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Master Volume
|
||||
* Set Master Output Volume
|
||||
* Master Output Volume related to the system volume (Alsamixer on Linux, Volume Mixer on Windows)
|
||||
* @param value volume value, 0-100
|
||||
*/
|
||||
public void setMasterVolume(int value){
|
||||
@@ -84,7 +122,8 @@ public class AudioPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Master Volume
|
||||
* Get Master Output Volume
|
||||
* Master Output Volume related to the system volume (Alsamixer on Linux, Volume Mixer on Windows)
|
||||
* @return 0 - 100, or -1 if failed
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@@ -99,6 +138,11 @@ public class AudioPlayer {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playback Volume
|
||||
* is the volume of the currently playing audio file
|
||||
* @return 0 - 100
|
||||
*/
|
||||
public int getPlaybackvolume(){
|
||||
if (playbackvolume<0)
|
||||
return 0;
|
||||
@@ -108,6 +152,11 @@ public class AudioPlayer {
|
||||
return (int)(playbackvolume*100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Playback Volume
|
||||
* is the volume of the currently playing audio file
|
||||
* @param value 0 - 100
|
||||
*/
|
||||
public void setPlaybackvolume(int value){
|
||||
if (value<0) value = 0;
|
||||
if (value>100) value = 100;
|
||||
@@ -119,11 +168,17 @@ public class AudioPlayer {
|
||||
|
||||
private float lastplaybackvolume = 1.0f;
|
||||
|
||||
/**
|
||||
* Set Playback Volume to 0
|
||||
*/
|
||||
public void Mute(){
|
||||
lastplaybackvolume = playbackvolume;
|
||||
setPlaybackvolume(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Playback Volume to last volume before Mute
|
||||
*/
|
||||
public void Unmute(){
|
||||
setPlaybackvolume((int)lastplaybackvolume*100);
|
||||
}
|
||||
@@ -164,6 +219,12 @@ public class AudioPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play Audio File
|
||||
* @param prop AudioFileProperties object to play
|
||||
* @param looping set true to loop the audio file
|
||||
* @param event PlaybackEvent object to handle playback event
|
||||
*/
|
||||
public void PlayAudioFile(AudioFileProperties prop, boolean looping, PlaybackEvent event){
|
||||
if (inited){
|
||||
if (prop!=null){
|
||||
|
||||
Reference in New Issue
Block a user