custom player interface: add progress-bar, rewind/forward
This commit is contained in:
		| @ -17,7 +17,7 @@ import com.google.android.exoplayer2.upstream.DataSource | ||||
| import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory | ||||
| import com.google.android.exoplayer2.util.Util | ||||
| import kotlinx.android.synthetic.main.activity_player.* | ||||
|  | ||||
| import kotlinx.android.synthetic.main.player_controls.* | ||||
|  | ||||
| class PlayerActivity : AppCompatActivity() { | ||||
|  | ||||
| @ -30,6 +30,8 @@ class PlayerActivity : AppCompatActivity() { | ||||
|     private var currentWindow = 0 | ||||
|     private var playbackPosition: Long = 0 | ||||
|  | ||||
|     private val rwdTime = 10000 | ||||
|     private val fwdTime = 10000 | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
| @ -41,8 +43,9 @@ class PlayerActivity : AppCompatActivity() { | ||||
|             playbackPosition = it.getLong(getString(R.string.state_resume_position)) | ||||
|             playWhenReady = it.getBoolean(getString(R.string.state_is_playing)) | ||||
|         } | ||||
|  | ||||
|         streamUrl = intent.getStringExtra(getString(R.string.intent_stream_url)).toString() | ||||
|  | ||||
|         initActions() | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -112,6 +115,12 @@ class PlayerActivity : AppCompatActivity() { | ||||
|                     ExoPlayer.STATE_BUFFERING -> View.VISIBLE | ||||
|                     else -> View.GONE | ||||
|                 } | ||||
|  | ||||
|                 exo_play_pause.visibility = when (loading.visibility) { | ||||
|                     View.GONE -> View.VISIBLE | ||||
|                     View.VISIBLE -> View.INVISIBLE | ||||
|                     else -> View.VISIBLE | ||||
|                 } | ||||
|             } | ||||
|         }) | ||||
|  | ||||
| @ -123,6 +132,16 @@ class PlayerActivity : AppCompatActivity() { | ||||
|         video_view.player = player | ||||
|     } | ||||
|  | ||||
|     private fun initActions() { | ||||
|         exo_rew_10.setOnClickListener { | ||||
|             player.seekTo(player.currentPosition - rwdTime) | ||||
|         } | ||||
|  | ||||
|         exo_ffwd_10.setOnClickListener { | ||||
|             player.seekTo(player.currentPosition + fwdTime) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun releasePlayer(){ | ||||
|         playbackPosition = player.currentPosition | ||||
|         currentWindow = player.currentWindowIndex | ||||
|  | ||||
| @ -0,0 +1,15 @@ | ||||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:width="24dp" | ||||
|     android:height="24dp" | ||||
|     android:viewportWidth="24" | ||||
|     android:viewportHeight="24"> | ||||
|   <path | ||||
|       android:fillColor="@android:color/white" | ||||
|       android:pathData="M18,13c0,3.31 -2.69,6 -6,6s-6,-2.69 -6,-6s2.69,-6 6,-6v4l5,-5l-5,-5v4c-4.42,0 -8,3.58 -8,8c0,4.42 3.58,8 8,8s8,-3.58 8,-8H18z"/> | ||||
|   <path | ||||
|       android:fillColor="@android:color/white" | ||||
|       android:pathData="M10.86,15.94l0,-4.27l-0.09,0l-1.77,0.63l0,0.69l1.01,-0.31l0,3.26z"/> | ||||
|   <path | ||||
|       android:fillColor="@android:color/white" | ||||
|       android:pathData="M12.25,13.44v0.74c0,1.9 1.31,1.82 1.44,1.82c0.14,0 1.44,0.09 1.44,-1.82v-0.74c0,-1.9 -1.31,-1.82 -1.44,-1.82C13.55,11.62 12.25,11.53 12.25,13.44zM14.29,13.32v0.97c0,0.77 -0.21,1.03 -0.59,1.03c-0.38,0 -0.6,-0.26 -0.6,-1.03v-0.97c0,-0.75 0.22,-1.01 0.59,-1.01C14.07,12.3 14.29,12.57 14.29,13.32z"/> | ||||
| </vector> | ||||
							
								
								
									
										15
									
								
								app/src/main/res/drawable/exo_styled_controls_rewind.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/src/main/res/drawable/exo_styled_controls_rewind.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:width="24dp" | ||||
|     android:height="24dp" | ||||
|     android:viewportWidth="24" | ||||
|     android:viewportHeight="24"> | ||||
|   <path | ||||
|       android:fillColor="@android:color/white" | ||||
|       android:pathData="M11.99,5V1l-5,5l5,5V7c3.31,0 6,2.69 6,6s-2.69,6 -6,6s-6,-2.69 -6,-6h-2c0,4.42 3.58,8 8,8s8,-3.58 8,-8S16.41,5 11.99,5z"/> | ||||
|   <path | ||||
|       android:fillColor="@android:color/white" | ||||
|       android:pathData="M10.89,16h-0.85v-3.26l-1.01,0.31v-0.69l1.77,-0.63h0.09V16z"/> | ||||
|   <path | ||||
|       android:fillColor="@android:color/white" | ||||
|       android:pathData="M15.17,14.24c0,0.32 -0.03,0.6 -0.1,0.82s-0.17,0.42 -0.29,0.57s-0.28,0.26 -0.45,0.33s-0.37,0.1 -0.59,0.1s-0.41,-0.03 -0.59,-0.1s-0.33,-0.18 -0.46,-0.33s-0.23,-0.34 -0.3,-0.57s-0.11,-0.5 -0.11,-0.82V13.5c0,-0.32 0.03,-0.6 0.1,-0.82s0.17,-0.42 0.29,-0.57s0.28,-0.26 0.45,-0.33s0.37,-0.1 0.59,-0.1s0.41,0.03 0.59,0.1c0.18,0.07 0.33,0.18 0.46,0.33s0.23,0.34 0.3,0.57s0.11,0.5 0.11,0.82V14.24zM14.32,13.38c0,-0.19 -0.01,-0.35 -0.04,-0.48s-0.07,-0.23 -0.12,-0.31s-0.11,-0.14 -0.19,-0.17s-0.16,-0.05 -0.25,-0.05s-0.18,0.02 -0.25,0.05s-0.14,0.09 -0.19,0.17s-0.09,0.18 -0.12,0.31s-0.04,0.29 -0.04,0.48v0.97c0,0.19 0.01,0.35 0.04,0.48s0.07,0.24 0.12,0.32s0.11,0.14 0.19,0.17s0.16,0.05 0.25,0.05s0.18,-0.02 0.25,-0.05s0.14,-0.09 0.19,-0.17s0.09,-0.19 0.11,-0.32s0.04,-0.29 0.04,-0.48V13.38z"/> | ||||
| </vector> | ||||
| @ -14,8 +14,8 @@ | ||||
|         android:layout_height="match_parent" | ||||
|         android:layout_gravity="center" | ||||
|         app:fastforward_increment="10000" | ||||
|         app:rewind_increment="10000"/> | ||||
|         <!--app:controller_layout_id="@layout/player_controls"/>--> | ||||
|         app:rewind_increment="10000" | ||||
|         app:controller_layout_id="@layout/player_controls"/> | ||||
|  | ||||
|     <com.google.android.material.progressindicator.ProgressIndicator | ||||
|         android:id="@+id/loading" | ||||
|  | ||||
| @ -22,8 +22,10 @@ | ||||
|         <ImageButton | ||||
|             android:id="@+id/exo_rew_10" | ||||
|             style="@style/ExoStyledControls.Button.Center.RewWithAmount" | ||||
|             android:layout_width="52dp" | ||||
|             android:layout_height="52dp" /> | ||||
|             android:layout_width="42dp" | ||||
|             android:layout_height="42dp" | ||||
|             android:tint="@color/exo_white"/> | ||||
|  | ||||
|  | ||||
|         <Space | ||||
|             android:layout_width="0dp" | ||||
| @ -45,8 +47,8 @@ | ||||
|         <ImageButton | ||||
|             android:id="@+id/exo_ffwd_10" | ||||
|             style="@style/ExoStyledControls.Button.Center.FfwdWithAmount" | ||||
|             android:layout_width="52dp" | ||||
|             android:layout_height="52dp" /> | ||||
|             android:layout_width="42dp" | ||||
|             android:layout_height="42dp" /> | ||||
|  | ||||
|         <Space | ||||
|             android:layout_width="0dp" | ||||
| @ -58,6 +60,8 @@ | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_gravity="bottom" | ||||
|         android:layout_marginStart="7dp" | ||||
|         android:layout_marginEnd="7dp" | ||||
|         android:layout_marginBottom="@dimen/exo_styled_progress_margin_bottom"> | ||||
|  | ||||
|         <TextView | ||||
| @ -83,22 +87,5 @@ | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
|     </androidx.constraintlayout.widget.ConstraintLayout> | ||||
|  | ||||
|     <LinearLayout | ||||
|         android:id="@+id/exo_time" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_gravity="bottom" | ||||
|         android:layout_marginBottom="@dimen/exo_styled_progress_margin_bottom" | ||||
|         android:orientation="horizontal" | ||||
|         tools:visibility="gone"> | ||||
|  | ||||
|  | ||||
|     </LinearLayout> | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| </FrameLayout> | ||||
| @ -12,6 +12,8 @@ | ||||
|         <item name="android:windowActionBar">false</item> | ||||
|         <item name="android:windowFullscreen">true</item> | ||||
|         <item name="android:windowContentOverlay">@null</item> | ||||
|         <item name="android:windowTranslucentStatus">true</item> | ||||
|         <item name="android:windowTranslucentNavigation">true</item> | ||||
|     </style> | ||||
|  | ||||
|     <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user