From a7a221a697b16f6d041425321b5ae43cb3460d65 Mon Sep 17 00:00:00 2001 From: 2taezeat Date: Thu, 7 Dec 2023 21:41:22 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat=20:=20PlayerListener=20EVENT=5FTRACKS?= =?UTF-8?q?=5FCHANGED=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ohdodok/catchytape/feature/player/PlayerListener.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerListener.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerListener.kt index ccee55d..3ebf41a 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerListener.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerListener.kt @@ -13,7 +13,12 @@ class PlayerListener( listener.onPlayingChanged(player.isPlaying) } - events.containsAny(Player.EVENT_TIMELINE_CHANGED, Player.EVENT_MEDIA_ITEM_TRANSITION) -> { + events.contains(Player.EVENT_MEDIA_ITEM_TRANSITION) -> { + val durationMs = player.duration.toInt() + listener.onMediaItemChanged(player.currentMediaItemIndex, durationMs / millisecondsPerSecond) + } + + events.contains(Player.EVENT_TRACKS_CHANGED) -> { val durationMs = player.duration.toInt() listener.onMediaItemChanged(player.currentMediaItemIndex, durationMs / millisecondsPerSecond) } From 6acefd278af725fb80c0a7b79e6a2d4bb4157ae7 Mon Sep 17 00:00:00 2001 From: 2taezeat Date: Thu, 7 Dec 2023 21:41:49 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20:=20moveHeadMedia=20=EA=B0=9C?= =?UTF-8?q?=EB=B0=9C=20=EB=B0=8F=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ohdodok/catchytape/MainActivity.kt | 4 ++-- .../catchytape/feature/player/PlayerFragment.kt | 2 +- .../catchytape/feature/player/PlayerUtil.kt | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt b/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt index 32cda95..40d953c 100644 --- a/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt +++ b/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt @@ -27,8 +27,8 @@ import com.ohdodok.catchytape.feature.player.PlayerViewModel import com.ohdodok.catchytape.feature.player.getMediasWithMetaData import com.ohdodok.catchytape.feature.player.millisecondsPerSecond import com.ohdodok.catchytape.feature.player.moveNextMedia -import com.ohdodok.catchytape.feature.player.movePreviousMedia import com.ohdodok.catchytape.feature.player.navigateToPlayer +import com.ohdodok.catchytape.feature.player.onPreviousBtnClick import com.ohdodok.catchytape.mediasession.PlaybackService import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.delay @@ -188,7 +188,7 @@ class MainActivity : AppCompatActivity() { private fun setupPreviousButton() { binding.pcvController.setOnPreviousButtonClick { - player.movePreviousMedia() + player.onPreviousBtnClick() } } diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt index 2abc0d6..3f00850 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt @@ -66,7 +66,7 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla } binding.ibPrevious.setOnClickListener { - player.movePreviousMedia() + player.onPreviousBtnClick() } binding.btnAddToPlaylist.setOnClickListener { diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerUtil.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerUtil.kt index 5cffd9d..3ff5710 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerUtil.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerUtil.kt @@ -6,6 +6,9 @@ import androidx.media3.common.MediaMetadata import androidx.media3.exoplayer.ExoPlayer import com.ohdodok.catchytape.core.domain.model.Music + +private const val POSITION_MOVE_HEAD_STANDARD = 0.05 + fun ExoPlayer.moveNextMedia() { seekToNextMediaItem() if (isPlaying) { @@ -20,6 +23,19 @@ fun ExoPlayer.movePreviousMedia() { } } +fun ExoPlayer.moveHeadMedia() { + seekTo(0) + play() +} + +fun ExoPlayer.onPreviousBtnClick() { + if (currentPosition.toFloat() / duration.toFloat() < POSITION_MOVE_HEAD_STANDARD) { + movePreviousMedia() + } else { + moveHeadMedia() + } +} + fun getMediasWithMetaData(musics: List): List { val mediaItemBuilder = MediaItem.Builder() val mediaMetadataBuilder = MediaMetadata.Builder() From 2ff31c3500f3c6475d9159efc7cf9eb34d46f424 Mon Sep 17 00:00:00 2001 From: 2taezeat Date: Thu, 7 Dec 2023 21:42:34 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20:=20onMediaItemChanged=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=20=EC=8B=9C,currentPositionSecond=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=200=EC=9C=BC=EB=A1=9C=20=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ohdodok/catchytape/feature/player/PlayerViewModel.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt index ab15725..5004fd2 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt @@ -88,6 +88,7 @@ class PlayerViewModel @Inject constructor( it.copy( duration = duration, currentMusic = playlist.musics[index], + currentPositionSecond = 0, isNextEnable = playlist.musics.lastIndex != index, isPreviousEnable = index != 0 )