Skip to content

Commit

Permalink
Build 1.4.2+ : less switching issue
Browse files Browse the repository at this point in the history
  • Loading branch information
legendsayantan committed Jun 13, 2024
1 parent 4d4c0fd commit 8798e4f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ class VolumeBarAdapter(
//spawn radiobuttons
holder.outputGroup.removeAllViews()
getDevices().forEach { device ->
val rButton = RadioButton(context)
showDevice(rButton, device)
rButton.setOnClickListener {
setDeviceFor(position, device)
showDevice(holder.outputName, device)
if ((device?.id?:-1) != currentItem.outputDevice){
val rButton = RadioButton(context)
showDevice(rButton, device)
rButton.setOnClickListener {
setDeviceFor(position, device)
showDevice(holder.outputName, device)
}
holder.outputGroup.addView(rButton)
}
holder.outputGroup.addView(rButton)
}
}
}
Expand Down
32 changes: 21 additions & 11 deletions app/src/main/java/com/legendsayantan/adbtools/lib/PlayBackThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,27 @@ class PlayBackThread(
return mPlayers.contains(deviceId)
}

fun createOutput(device:AudioDeviceInfo?=null){
fun createOutput(
device:AudioDeviceInfo?=null,
startVolume:Float=targetVolume
, bal:Float?=null,
bands:Array<Float> = arrayOf()
){
mPlayers[device?.id?:-1] = AudioPlayer(
AudioManager.STREAM_MUSIC,
SAMPLE_RATE, CHANNEL,
ENCODING, BUF_SIZE,
AudioTrack.MODE_STREAM
).also {
it.setCurrentVolume(targetVolume)
it.playbackRate = SAMPLE_RATE
it.preferredDevice = device
it.play()
).also { player ->
player.setCurrentVolume(startVolume)
player.playbackRate = SAMPLE_RATE
player.preferredDevice = device
player.play()
try {
it.equalizer.enabled = true
player.equalizer.enabled = true
}catch (_:Exception){}
bal?.let { player.setBalance(bal) }
bands.forEachIndexed { index, fl -> player.setBand(index,fl) }
}
}

Expand All @@ -132,10 +139,13 @@ class PlayBackThread(
}

fun switchOutputDevice(key:AudioOutputKey, newDevice:AudioDeviceInfo?){
val playerKey = if(mPlayers.contains(key.outputDevice)) key.outputDevice else -1
mPlayers[playerKey]?.preferredDevice = newDevice
mPlayers[newDevice?.id?:-1] = mPlayers[playerKey]!!
mPlayers.remove(playerKey)
mPlayers[key.outputDevice]?.let {
val vol = it.volume*100f
val balance = it.getBalance()
val bands = it.savedBands
createOutput(newDevice,vol,balance,bands)
deleteOutput(key.outputDevice)
}
}
fun getLatency(): Float {
return notiUpdateTime.toFloat() / loadedCycles.coerceAtLeast(1).also { loadedCycles = 0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ class SoundMasterService : Service() {
var dev = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).filter {
it.type !in arrayOf(7, 18, 25)
}
if(dev.find { it?.type in 3..4 }!=null) dev = dev.filter { it?.type !in 1..2 }
if(dev.all { it?.type in 1..2 }) dev = dev.filter { it?.type!=1 }
//block builtin outputs
if(dev.any { it?.type in 3..4 }) dev = dev.filter { it?.type !in 1..2 }
//block earpiece only
if(dev.all { it?.type in 1..2 } || dev.any { it?.type==8 }) dev = dev.filter { it?.type!=1 }
listOf(null) + dev
}

Expand Down Expand Up @@ -154,6 +156,7 @@ class SoundMasterService : Service() {
thread?.deleteOutput(key.outputDevice)
if(thread?.mPlayers?.size==0){
packageThreads.remove(key.pkg)
apps.remove(key)
}
}
}
Expand Down

0 comments on commit 8798e4f

Please sign in to comment.