Skip to content

Commit

Permalink
[FEAT/#93] 스트레칭모드 분리 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Jan 7, 2025
1 parent 43119a7 commit 642ee9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.rememberLottieComposition
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.kkkk.presentation.main.rhythm.RhythmState.Companion.STRETCH_MUSIC_FILE
import com.kkkk.presentation.main.rhythm.RhythmState.Companion.findMusicByBpm
import com.kkkk.presentation.main.rhythm.RhythmViewModel.Companion.FLOAT_80
import com.kkkk.presentation.main.rhythm.component.RhythmBottomSheet
Expand Down Expand Up @@ -78,7 +79,9 @@ fun RhythmRoute(
val lottieLoading by rememberLottieComposition(
LottieCompositionSpec.RawRes(R.raw.stempo_loading)
)
val animationSpeed = remember(rhythmState.bpm) { rhythmState.bpm / FLOAT_80 }
val animationSpeed = remember(rhythmState.selectedMode, rhythmState.bpm) {
if (rhythmState.selectedMode == RhythmMode.RHYTHM) rhythmState.bpm / FLOAT_80 else 0.75F
}

val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -113,12 +116,23 @@ fun RhythmRoute(
}
}

LaunchedEffect(rhythmState.selectedMode) {
viewModel.updateIsPlayerLoaded(false)
}

LaunchedEffect(rhythmState.isPlayerLoaded) {
if (!rhythmState.isPlayerLoaded) {
viewModel.setMusicPlayer(
soundPoolFile = File(context.filesDir, rhythmState.filename),
mediaPlayerAfd = context.resources.openRawResourceFd(findMusicByBpm(rhythmState.bpm))
)
if (rhythmState.selectedMode == RhythmMode.RHYTHM) {
viewModel.setMusicPlayer(
soundPoolFile = File(context.filesDir, rhythmState.filename),
mediaPlayerAfd = context.resources.openRawResourceFd(findMusicByBpm(rhythmState.bpm))
)
} else {
viewModel.setMusicPlayer(
soundPoolFile = File(context.filesDir, STRETCH_MUSIC_FILE),
mediaPlayerAfd = context.resources.openRawResourceFd(R.raw.music_stretch)
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ data class RhythmState(
const val MIN_BIT = 2
const val MAX_BIT = 8

const val STRETCH_MUSIC_FILE = "stempo_bpm_60_bit_2"

fun findMusicByBpm(bpm: Int) = when (bpm / 20) {
3 -> R.raw.music_bpm_60
4 -> R.raw.music_bpm_80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ constructor(

private fun playMediaPlayerWithSpeed() {
mediaPlayer.apply {
playbackParams = PlaybackParams().setSpeed(findSpeedByBpm(rhythmState.value.bpm))
if (rhythmState.value.selectedMode == RhythmMode.RHYTHM) {
playbackParams = PlaybackParams().setSpeed(findSpeedByBpm(rhythmState.value.bpm))
}
}.start()
}

Expand All @@ -173,7 +175,9 @@ constructor(
async { if (beatStream != 0) soundPool.pause(beatStream) },
async { mediaPlayer.pause() }
).awaitAll()
if (isDialogNeeded) showDialog(true)
if (isDialogNeeded && rhythmState.value.selectedMode == RhythmMode.RHYTHM) {
showDialog(true)
}
}
}

Expand Down

0 comments on commit 642ee9e

Please sign in to comment.