-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement setBalance
feature for android
#1413
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
We should move the individual implementations to WrappedPlayer to save much code. No need to add an extra map
method, which makes this a bit more complicated than it is :)
Also remove this line, to enable Android tests for Balance.
Also you may can change parity table for balance
to support Android as well :)
response.notImplemented() | ||
val balance = call.argument<Double>("balance") ?: error("Balance is required") | ||
player.balance = balance.toFloat() | ||
|
||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plz remove return
statement, so that the call returns 1
in case it succeeds.
Also remove unnecessary empty line :)
@@ -48,6 +48,15 @@ class WrappedPlayer internal constructor( | |||
} | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add extra empty line, to better separate setters
@@ -16,6 +16,7 @@ interface Player { | |||
fun release() | |||
|
|||
fun setVolume(volume: Float) | |||
fun setBalance(balance: Float) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather change the interface to:
fun setVolume(leftVolume: Float, rightVolume: Float)
and remove the setBalance
method.
That way we can remove the redundant code in SoundPoolPlayer
and MediaPlayerPlayer
and move the calculation to WrappedPlayer
. Then also there's no need to keep track of volume
and balance
in their implementation.
// | ||
private var volume = 1.0f; | ||
private var balance = 0.0f; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, if moved to WrappedPlayer
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, if moved to WrappedPlayer
val rightVolume = map(balance,-1.0f,1.0f,0.0f,1.0f) * volume; | ||
|
||
mediaPlayer.setVolume(leftVolume, rightVolume) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, if moved to WrappedPlayer
/* Keep track of latest volume and balance */ | ||
private var volume = 1.0f; | ||
private var balance = 0.0f; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, if moved to WrappedPlayer
} | ||
|
||
private fun map(x: Float, inMin: Float, inMax: Float, outMin: Float, outMax: Float): Float { | ||
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, if moved to WrappedPlayer
if (field != value) { | ||
field = value | ||
if (!released) { | ||
player?.setBalance(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here call, or at least that's my interpretation of the balance feature:
val leftVolume = min(1, 1 - value)
val rightVolume = min(1, 1 + value)
player?.setVolume(leftVolume, rightVolume)
@ritheshSalyan do you plan on continue working on this? Thanks for your support :D |
Closing in favor of #1444 |
Description
Added the
setBalance
feature for android.Checklist
fix:
,feat:
,docs:
,chore:
etc).///
, where necessary.Breaking Change
Related Issues