Skip to content

Commit

Permalink
fix(app): remove thread-synchronisation from Player volume update
Browse files Browse the repository at this point in the history
fixes #594
fixes #593
  • Loading branch information
ashutoshgngwr committed Apr 23, 2021
1 parent cd43a45 commit 14f45e9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.ashutoshgngwr.noice.fragment
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -85,14 +86,8 @@ class PresetFragment : Fragment() {
fun onPlayerManagerUpdate(event: MediaPlayerService.OnPlayerManagerUpdateEvent) {
val oldPresetPos = activePresetPos
activePresetPos = Preset.from("", event.players.values).let { dataSet.indexOf(it) }

if (activePresetPos != oldPresetPos) {
adapter?.notifyItemChanged(oldPresetPos)

if (activePresetPos > -1) {
adapter?.notifyItemChanged(activePresetPos)
}
}
adapter?.notifyItemChanged(oldPresetPos)
adapter?.notifyItemChanged(activePresetPos)
}

private fun updateEmptyListIndicatorVisibility() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ class Player(val soundKey: String, playbackStrategyFactory: PlaybackStrategyFact
* Sets the volume for the [Player] using current [PlaybackStrategy].
*/
fun setVolume(volume: Int) {
handler.post {
this.volume = volume
this.playbackStrategy.setVolume(volume.toFloat() / MAX_VOLUME)
}
this.volume = volume
this.playbackStrategy.setVolume(volume.toFloat() / MAX_VOLUME)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,11 @@ class PlayerManager(private val context: Context) :
handler.removeCallbacksAndMessages(DELAYED_STOP_CALLBACK_TOKEN)
state = State.PLAYING
players.values.forEach { it.play() }
notifyChanges()
} else if (!playbackDelayed) {
// request audio focus only if audio focus is not delayed from any previous requests
requestAudioFocus()
}

notifyChanges()
}

/**
Expand Down Expand Up @@ -372,6 +371,6 @@ class PlayerManager(private val context: Context) :
}

mediaSession.setPlaybackState(playbackStateBuilder.build())
onPlayerUpdateListener()
onPlayerUpdateListener.invoke()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class PlayerTest {
@Test
fun testSetVolume() {
player.setVolume(16)
ShadowLooper.runUiThreadTasks()
verify(exactly = 1) { mockPlaybackStrategy.setVolume(16f / Player.MAX_VOLUME) }
assertEquals(16, player.volume)
}
Expand Down

0 comments on commit 14f45e9

Please sign in to comment.