콘텐츠 플레이어
- 10초 이전/이후로 이동하는 기능 추가
This commit is contained in:
		| @@ -353,6 +353,26 @@ class AudioContentPlayerFragment( | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         binding.ivSeekForward10.setOnClickListener { | ||||
|             mediaController?.let { | ||||
|                 val sessionCommand = SessionCommand( | ||||
|                     "SEEK_FORWARD", | ||||
|                     Bundle.EMPTY | ||||
|                 ) | ||||
|                 it.sendCustomCommand(sessionCommand, Bundle.EMPTY) | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         binding.ivSeekBackward10.setOnClickListener { | ||||
|             mediaController?.let { | ||||
|                 val sessionCommand = SessionCommand( | ||||
|                     "SEEK_BACKWARD", | ||||
|                     Bundle.EMPTY | ||||
|                 ) | ||||
|                 it.sendCustomCommand(sessionCommand, Bundle.EMPTY) | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         binding.sbProgress.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||||
|             override fun onProgressChanged( | ||||
|                 seekBar: SeekBar?, | ||||
|   | ||||
| @@ -130,6 +130,8 @@ class AudioContentPlayerService : MediaSessionService() { | ||||
|                         .add(SessionCommand("PLAY_PREVIOUS_CONTENT", Bundle.EMPTY)) | ||||
|                         .add(SessionCommand("PLAY_SELECTED_CONTENT", Bundle.EMPTY)) | ||||
|                         .add(SessionCommand("GET_PLAYLIST", Bundle.EMPTY)) | ||||
|                         .add(SessionCommand("SEEK_FORWARD", Bundle.EMPTY)) | ||||
|                         .add(SessionCommand("SEEK_BACKWARD", Bundle.EMPTY)) | ||||
|                         .build() | ||||
|  | ||||
|                     return MediaSession.ConnectionResult.AcceptedResultBuilder(session) | ||||
| @@ -176,6 +178,16 @@ class AudioContentPlayerService : MediaSessionService() { | ||||
|                             Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS)) | ||||
|                         } | ||||
|  | ||||
|                         "SEEK_FORWARD" -> { | ||||
|                             playSeekForward() | ||||
|                             Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS)) | ||||
|                         } | ||||
|  | ||||
|                         "SEEK_BACKWARD" -> { | ||||
|                             playSeekBackward() | ||||
|                             Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS)) | ||||
|                         } | ||||
|  | ||||
|                         "GET_PLAYLIST" -> { | ||||
|                             val extras = Bundle().apply { | ||||
|                                 putParcelableArrayList( | ||||
| @@ -227,6 +239,25 @@ class AudioContentPlayerService : MediaSessionService() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun playSeekForward() { | ||||
|         val currentPosition = player!!.currentPosition | ||||
|         val duration = player!!.duration | ||||
|         var newPosition = currentPosition + SEEK_INTERVAL_MS | ||||
|         if (newPosition > duration) { | ||||
|             newPosition = duration | ||||
|         } | ||||
|         player!!.seekTo(newPosition) | ||||
|     } | ||||
|  | ||||
|     private fun playSeekBackward() { | ||||
|         val currentPosition = player!!.currentPosition | ||||
|         var newPosition = currentPosition - SEEK_INTERVAL_MS | ||||
|         if (newPosition < 0) { | ||||
|             newPosition = 0 | ||||
|         } | ||||
|         player!!.seekTo(newPosition) | ||||
|     } | ||||
|  | ||||
|     private fun urlGenerateSuccess( | ||||
|         content: AudioContentPlaylistContent, | ||||
|         contentUrl: String | ||||
| @@ -318,4 +349,8 @@ class AudioContentPlayerService : MediaSessionService() { | ||||
|                 ) | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     companion object { | ||||
|         private const val SEEK_INTERVAL_MS = 10 * 1000 | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								app/src/main/res/drawable-xxhdpi/ic_player_next_10.png
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								app/src/main/res/drawable-xxhdpi/ic_player_next_10.png
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.8 KiB | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 2.8 KiB | 
							
								
								
									
										
											BIN
										
									
								
								app/src/main/res/drawable-xxhdpi/ic_player_prev_10.png
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								app/src/main/res/drawable-xxhdpi/ic_player_prev_10.png
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.9 KiB | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 2.9 KiB | 
| @@ -24,9 +24,9 @@ | ||||
|         android:ellipsize="end" | ||||
|         android:fontFamily="@font/gmarket_sans_medium" | ||||
|         android:maxLines="2" | ||||
|         android:padding="5dp" | ||||
|         android:textColor="@color/color_eeeeee" | ||||
|         android:textSize="16sp" | ||||
|         android:padding="5dp" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toBottomOf="@+id/iv_close" | ||||
| @@ -142,6 +142,29 @@ | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="@+id/iv_play_or_pause" /> | ||||
|  | ||||
|     <ImageView | ||||
|         android:id="@+id/iv_seek_backward_10" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:contentDescription="@null" | ||||
|         android:src="@drawable/ic_player_prev_10" | ||||
|         app:layout_constraintBottom_toBottomOf="@+id/iv_play_or_pause" | ||||
|         app:layout_constraintEnd_toStartOf="@+id/iv_play_or_pause" | ||||
|         app:layout_constraintStart_toEndOf="@+id/iv_skip_back" | ||||
|         app:layout_constraintTop_toTopOf="@+id/iv_play_or_pause" /> | ||||
|  | ||||
|     <ImageView | ||||
|         android:id="@+id/iv_seek_forward_10" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:contentDescription="@null" | ||||
|         android:src="@drawable/ic_player_next_10" | ||||
|         app:layout_constraintBottom_toBottomOf="@+id/iv_play_or_pause" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintEnd_toStartOf="@+id/iv_skip_forward" | ||||
|         app:layout_constraintStart_toEndOf="@+id/iv_play_or_pause" | ||||
|         app:layout_constraintTop_toTopOf="@+id/iv_play_or_pause" /> | ||||
|  | ||||
|     <ImageView | ||||
|         android:id="@+id/iv_playlist" | ||||
|         android:layout_width="wrap_content" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user