player UI stuff

This commit is contained in:
LagradOst 2021-05-24 10:51:16 +02:00
parent 3d2f00313b
commit 5e5e4a4ca5
11 changed files with 188 additions and 38 deletions

View file

@ -1,7 +1,10 @@
package com.lagradost.cloudstream3.ui.player package com.lagradost.cloudstream3.ui.player
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.app.Activity import android.app.Activity
import android.content.Context.AUDIO_SERVICE import android.content.Context.AUDIO_SERVICE
import android.content.SharedPreferences
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.database.ContentObserver import android.database.ContentObserver
import android.media.AudioManager import android.media.AudioManager
@ -15,6 +18,8 @@ import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.view.ViewGroup import android.view.ViewGroup
import android.view.animation.AlphaAnimation import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.Toast import android.widget.Toast
import android.widget.Toast.LENGTH_LONG import android.widget.Toast.LENGTH_LONG
@ -49,6 +54,7 @@ import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSession import javax.net.ssl.SSLSession
import kotlin.concurrent.thread import kotlin.concurrent.thread
//http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4 //http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
const val STATE_RESUME_WINDOW = "resumeWindow" const val STATE_RESUME_WINDOW = "resumeWindow"
const val STATE_RESUME_POSITION = "resumePosition" const val STATE_RESUME_POSITION = "resumePosition"
@ -96,6 +102,8 @@ class PlayerFragment : Fragment() {
private var isLoading = true private var isLoading = true
private lateinit var exoPlayer: SimpleExoPlayer private lateinit var exoPlayer: SimpleExoPlayer
private lateinit var settingsManager: SharedPreferences
private fun seekTime(time: Long) { private fun seekTime(time: Long) {
exoPlayer.seekTo(maxOf(minOf(exoPlayer.currentPosition + time, exoPlayer.duration), 0)) exoPlayer.seekTo(maxOf(minOf(exoPlayer.currentPosition + time, exoPlayer.duration), 0))
} }
@ -220,6 +228,38 @@ class PlayerFragment : Fragment() {
} }
println(episodes) println(episodes)
settingsManager = PreferenceManager.getDefaultSharedPreferences(activity)
val fastForwardTime = settingsManager.getInt("fast_forward_button_time", 10)
exo_rew_text.text = fastForwardTime.toString()
exo_ffwd_text.text = fastForwardTime.toString()
exo_rew.setOnClickListener {
val rotateLeft = AnimationUtils.loadAnimation(context, R.anim.rotate_left)
exo_rew.startAnimation(rotateLeft)
val goLeft = AnimationUtils.loadAnimation(context, R.anim.go_left)
goLeft.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation?) {
}
override fun onAnimationRepeat(animation: Animation?) {
}
override fun onAnimationEnd(animation: Animation?) {
exo_rew_text.text = "$fastForwardTime"
}
})
exo_rew_text.startAnimation(goLeft)
exo_rew_text.text = "-$fastForwardTime"
seekTime(fastForwardTime * -1000L)
}
exo_ffwd.setOnClickListener {
val rotateRight = AnimationUtils.loadAnimation(context, R.anim.rotate_right)
exo_ffwd.startAnimation(rotateRight)
seekTime(fastForwardTime * 1000L)
}
} }
fun getCurrentUrl(): ExtractorLink { fun getCurrentUrl(): ExtractorLink {
@ -280,6 +320,7 @@ class PlayerFragment : Fragment() {
private var currentWindow = 0 private var currentWindow = 0
private var playbackPosition: Long = 0 private var playbackPosition: Long = 0
//http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4 //http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
private fun initPlayer() { private fun initPlayer() {
println("INIT PLAYER") println("INIT PLAYER")
@ -292,7 +333,7 @@ class PlayerFragment : Fragment() {
//MainActivity.popCurrentPage() //MainActivity.popCurrentPage()
} }
} else { } else {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(activity)
try { try {
activity?.runOnUiThread { activity?.runOnUiThread {
val isOnline = val isOnline =

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
>
<translate
android:fromXDelta="0"
android:toXDelta="-200"
android:duration="200"
>
</translate>
</set>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
>
<translate
android:fromXDelta="0"
android:toXDelta="100"
>
</translate>
</set>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
>
<rotate android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50"
/>
<rotate android:fromDegrees="0"
android:toDegrees="90"
android:startOffset="50"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50"
/>
<scale android:fromXScale="1.0" android:fromYScale="0.9"
android:toXScale="1.0" android:toYScale="0.9"
android:pivotX="50%" android:pivotY="50%"
android:duration="50"/>
<scale android:fromXScale="0.9" android:fromYScale="1"
android:toXScale="0.9" android:toYScale="1"
android:pivotX="50%" android:pivotY="50%"
android:duration="50" android:startOffset="50"/>
</set>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
>
<rotate android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50"
/>
<rotate android:fromDegrees="0"
android:toDegrees="-90"
android:startOffset="50"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50"
/>
<scale android:fromXScale="1.0" android:fromYScale="0.9"
android:toXScale="1.0" android:toYScale="0.9"
android:pivotX="50%" android:pivotY="50%"
android:duration="50"/>
<scale android:fromXScale="0.9" android:fromYScale="1"
android:toXScale="0.9" android:toYScale="1"
android:pivotX="50%" android:pivotY="50%"
android:duration="50" android:startOffset="50"/>
</set>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/video_ripple">
<item android:drawable="@drawable/netflix_pause" android:height="70dp" android:width="70dp" android:gravity="center">
</item>
</layer-list>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/video_ripple">
<item android:drawable="@drawable/netflix_play" android:height="70dp" android:width="70dp" android:gravity="center">
</item>
</layer-list>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" <ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/video_ripple"> android:color="@color/video_ripple">
<item android:id="@android:id/mask"> <item android:id="@android:id/mask" android:gravity="center">
<shape android:shape="oval"> <shape android:shape="oval">
<solid android:color="@color/video_ripple"/> <solid android:color="@color/video_ripple"/>
</shape> </shape>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" <ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/video_ripple"> android:color="@color/video_ripple">
<item android:id="@android:id/mask" android:height="40dp" android:width="40dp" android:left="5dp" android:top="5dp"> <item android:id="@android:id/mask" android:height="35dp" android:width="35dp" android:gravity="center">
<shape android:shape="oval"> <shape android:shape="oval">
<solid android:color="@color/video_ripple"/> <solid android:color="@color/video_ripple"/>
</shape> </shape>

View file

@ -193,8 +193,9 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="100dp"
android:gravity="center"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_gravity="center" android:layout_gravity="center"
android:id="@+id/centerMenu" android:id="@+id/centerMenu"
@ -203,23 +204,26 @@
<FrameLayout android:layout_width="wrap_content" <FrameLayout android:layout_width="wrap_content"
android:layout_marginEnd="140dp" android:layout_marginEnd="140dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_height="wrap_content"> android:layout_height="wrap_content" tools:ignore="RtlSymmetry">
<TextView <TextView
android:id="@+id/exo_rew_text" android:id="@+id/exo_rew_text"
android:textColor="@color/white" android:textColor="@color/white"
android:text="@string/player_skip_button_text" android:text="@string/player_skip_button_text"
android:textSize="15sp" android:textSize="19sp"
android:layout_gravity="center" android:layout_gravity="center"
android:textFontWeight="900" android:textFontWeight="900"
android:gravity="center" android:gravity="center"
android:layout_width="40dp"
android:layout_width="wrap_content"
android:layout_height="40dp"> android:layout_height="40dp">
</TextView> </TextView>
<ImageButton <ImageButton
android:id="@id/exo_rew" android:id="@id/exo_rew"
android:layout_height="50dp" android:layout_height="70dp"
android:layout_width="50dp" android:layout_width="70dp"
android:padding="5dp" android:layout_gravity="center"
android:padding="10dp"
android:background="@drawable/video_tap_button_skip" android:background="@drawable/video_tap_button_skip"
android:src="@drawable/netflix_skip_back" android:src="@drawable/netflix_skip_back"
android:scaleType="fitCenter" android:scaleType="fitCenter"
@ -234,21 +238,21 @@
<ImageButton <ImageButton
android:id="@id/exo_play" android:id="@id/exo_play"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:layout_height="70dp" android:layout_height="100dp"
android:layout_width="70dp" android:layout_width="100dp"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@drawable/video_tap_button_always_white" android:background="@drawable/video_tap_button_always_white"
android:foreground="@drawable/netflix_play" android:foreground="@drawable/video_play"
android:clickable="true" android:clickable="true"
android:focusable="true"/> android:focusable="true"/>
<ImageButton <ImageButton
android:id="@id/exo_pause" android:id="@id/exo_pause"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:layout_height="70dp" android:layout_height="100dp"
android:layout_width="70dp" android:layout_width="100dp"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@drawable/video_tap_button_always_white" android:background="@drawable/video_tap_button_always_white"
android:foreground="@drawable/netflix_pause" android:foreground="@drawable/video_pause"
android:clickable="true" android:clickable="true"
android:focusable="true"/> android:focusable="true"/>
@ -261,9 +265,9 @@
android:id="@+id/exo_ffwd_text" android:id="@+id/exo_ffwd_text"
android:textColor="@color/white" android:textColor="@color/white"
android:text="@string/player_skip_button_text" android:text="@string/player_skip_button_text"
android:textSize="15sp" android:textSize="19sp"
android:layout_gravity="center" android:layout_gravity="center"
android:textFontWeight="900" android:textStyle="bold"
android:gravity="center" android:gravity="center"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp"> android:layout_height="40dp">
@ -271,18 +275,15 @@
<ImageButton <ImageButton
android:layout_gravity="center" android:layout_gravity="center"
android:id="@id/exo_ffwd" android:id="@id/exo_ffwd"
android:layout_height="50dp" android:layout_height="70dp"
android:layout_width="50dp" android:layout_width="70dp"
android:padding="5dp" android:padding="10dp"
android:background="@drawable/video_tap_button_skip" android:background="@drawable/video_tap_button_skip"
android:src="@drawable/netflix_skip_forward" android:src="@drawable/netflix_skip_forward"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:tintMode="src_in" android:tintMode="src_in"
/> />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
@ -324,7 +325,6 @@
style="@style/ExoMediaButton.VR" style="@style/ExoMediaButton.VR"
android:tint="?attr/colorPrimaryDark" android:tint="?attr/colorPrimaryDark"
android:tintMode="src_in"/> android:tintMode="src_in"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -354,17 +354,23 @@
android:includeFontPadding="false" android:includeFontPadding="false"
android:paddingLeft="4dp" android:paddingLeft="4dp"
android:paddingRight="4dp" android:paddingRight="4dp"
android:gravity="end"
android:minWidth="50dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="14sp" android:textSize="14sp"
android:textStyle="bold"/> android:textStyle="normal"/>
<com.google.android.exoplayer2.ui.DefaultTimeBar <com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@id/exo_progress" android:id="@id/exo_progress"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="26dp" android:layout_height="30dp"
android:layout_weight="1" android:layout_weight="1"
app:played_color="?attr/colorPrimary" app:scrubber_enabled_size="24dp"
app:unplayed_color="@color/darkBar"/> app:scrubber_dragged_size="26dp"
app:scrubber_color="@color/videoColorPrimary"
app:bar_height="2dp"
app:played_color="@color/videoColorPrimary"
app:unplayed_color="@color/videoProgress"/>
<TextView <TextView
tools:text="23:20" tools:text="23:20"
@ -374,9 +380,10 @@
android:includeFontPadding="false" android:includeFontPadding="false"
android:paddingLeft="4dp" android:paddingLeft="4dp"
android:paddingRight="4dp" android:paddingRight="4dp"
android:minWidth="50dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="14sp" android:textSize="14sp"
android:textStyle="bold" android:textStyle="normal"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:layout_gravity="center" android:layout_gravity="center"
/> />
@ -387,6 +394,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="center" android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="10dp"
> >
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
@ -426,6 +435,8 @@
android:gravity="center" android:gravity="center"
android:paddingStart="10dp" android:paddingStart="10dp"
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:layout_gravity="center" android:layout_gravity="center"
android:textColor="@android:color/white" android:textColor="@android:color/white"
> >
@ -473,6 +484,9 @@
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:id="@+id/player_speed_text" android:id="@+id/player_speed_text"
android:layout_gravity="center" android:layout_gravity="center"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="@android:color/white" android:textColor="@android:color/white"
> >
</TextView> </TextView>
@ -517,6 +531,9 @@
android:text="Source" android:text="Source"
android:gravity="center" android:gravity="center"
android:paddingStart="10dp" android:paddingStart="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:layout_gravity="center" android:layout_gravity="center"
android:textColor="@android:color/white" android:textColor="@android:color/white"
@ -561,6 +578,9 @@
android:text="Skip OP" android:text="Skip OP"
android:gravity="start|center" android:gravity="start|center"
android:paddingStart="10dp" android:paddingStart="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:layout_gravity="center" android:layout_gravity="center"
android:textColor="@android:color/white" android:textColor="@android:color/white"
@ -671,8 +691,6 @@
android:progress="100" android:progress="100"
android:progressDrawable="@drawable/progress_drawable_vertical" android:progressDrawable="@drawable/progress_drawable_vertical"
> >
</ProgressBar> </ProgressBar>
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>

View file

@ -28,8 +28,10 @@
<color name="typeColor">#F54A3B</color> <color name="typeColor">#F54A3B</color>
<color name="typeColorBg">#4DF54A3B</color> <color name="typeColorBg">#4DF54A3B</color>
<color name="video_ripple">#80FFFFFF</color> <color name="video_ripple">#73FFFFFF</color>
<color name="black_overlay">#66000000</color> <color name="black_overlay">#66000000</color>
<color name="darkBarTransparent">#C0121212</color> <color name="darkBarTransparent">#C0121212</color>
<color name="darkBar">#121212</color> <color name="darkBar">#121212</color>
<color name="videoProgress">#66B5B5B5</color>
<color name="videoColorPrimary">#617EFF</color>
</resources> </resources>