feat: Updated exoplayer

This commit is contained in:
Stefan Schüller 2022-04-30 14:47:44 +02:00
parent 528132c47d
commit 9c45c76ec0
6 changed files with 134 additions and 219 deletions

View File

@ -55,6 +55,12 @@ android {
vectorDrawables { vectorDrawables {
useSupportLibrary true useSupportLibrary true
} }
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
} }
signingConfigs { signingConfigs {
release { release {
@ -132,6 +138,9 @@ dependencies {
implementation "com.google.android.exoplayer:exoplayer:$exo_player_version" implementation "com.google.android.exoplayer:exoplayer:$exo_player_version"
implementation "com.google.android.exoplayer:exoplayer-core:$exo_player_version" implementation "com.google.android.exoplayer:exoplayer-core:$exo_player_version"
implementation "com.google.android.exoplayer:exoplayer-hls:$exo_player_version" implementation "com.google.android.exoplayer:exoplayer-hls:$exo_player_version"
implementation "com.google.android.exoplayer:exoplayer-dash:$exo_player_version"
implementation "com.google.android.exoplayer:exoplayer-rtsp:$exo_player_version"
implementation "com.google.android.exoplayer:exoplayer-transformer:$exo_player_version"
implementation "com.google.android.exoplayer:exoplayer-ui:$exo_player_version" implementation "com.google.android.exoplayer:exoplayer-ui:$exo_player_version"
// Compose dependencies // Compose dependencies

View File

@ -16,6 +16,7 @@ import android.widget.FrameLayout
import android.widget.ImageButton import android.widget.ImageButton
import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalConfiguration
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import com.google.android.exoplayer2.ui.StyledPlayerView
import net.schueller.peertube.R import net.schueller.peertube.R
import net.schueller.peertube.feature_video.presentation.video.events.VideoPlayEvent import net.schueller.peertube.feature_video.presentation.video.events.VideoPlayEvent
import net.schueller.peertube.feature_video.presentation.video.VideoPlayViewModel import net.schueller.peertube.feature_video.presentation.video.VideoPlayViewModel
@ -58,7 +59,7 @@ fun VideoScreen(
Log.v("VideoScreen", "playerView assign") Log.v("VideoScreen", "playerView assign")
PlayerView.switchTargetView( StyledPlayerView.switchTargetView(
player, player,
PlayerViewPool.currentPlayerView, PlayerViewPool.currentPlayerView,
playerView playerView
@ -78,7 +79,7 @@ fun VideoScreen(
// Video More Button // Video More Button
val videoMoreButton = playerView.findViewById<FrameLayout>(R.id.exo_more_button) val videoMoreButton = playerView.findViewById<ImageButton>(R.id.exo_more)
videoMoreButton.setOnClickListener { videoMoreButton.setOnClickListener {
viewModel.onEvent(VideoPlayEvent.MoreButton) viewModel.onEvent(VideoPlayEvent.MoreButton)
} }

View File

@ -4,22 +4,23 @@ import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.core.util.Pools import androidx.core.util.Pools
import com.google.android.exoplayer2.ui.PlayerView import com.google.android.exoplayer2.ui.PlayerView
import com.google.android.exoplayer2.ui.StyledPlayerView
import net.schueller.peertube.R import net.schueller.peertube.R
object PlayerViewPool { object PlayerViewPool {
var currentPlayerView: PlayerView? = null var currentPlayerView: StyledPlayerView? = null
private val playerViewPool = Pools.SimplePool<PlayerView>(2) private val playerViewPool = Pools.SimplePool<StyledPlayerView>(2)
fun get(context: Context): PlayerView { fun get(context: Context): StyledPlayerView {
return playerViewPool.acquire() ?: createPlayerView(context) return playerViewPool.acquire() ?: createPlayerView(context)
} }
fun release(player: PlayerView) { fun release(player: StyledPlayerView) {
playerViewPool.release(player) playerViewPool.release(player)
} }
private fun createPlayerView(context: Context): PlayerView { private fun createPlayerView(context: Context): StyledPlayerView {
return (LayoutInflater.from(context).inflate(R.layout.exoplayer_texture_view, null, false) as PlayerView) return (LayoutInflater.from(context).inflate(R.layout.exoplayer_texture_view, null, false) as StyledPlayerView)
} }
} }

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.exoplayer2.ui.PlayerView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.exoplayer2.ui.StyledPlayerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/playerView" android:id="@+id/playerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -11,6 +13,7 @@
app:show_buffering="when_playing" app:show_buffering="when_playing"
app:shutter_background_color="@android:color/black" app:shutter_background_color="@android:color/black"
app:surface_type="surface_view" app:surface_type="surface_view"
app:show_subtitle_button="true"
app:use_controller="true" app:use_controller="true"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
app:controller_layout_id="@layout/video_playback_controls" app:controller_layout_id="@layout/video_playback_controls"

View File

@ -1,230 +1,131 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <merge xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#CC000000"
android:layoutDirection="ltr"
android:orientation="vertical"
tools:targetApi="32">
<FrameLayout <View android:id="@id/exo_controls_background"
android:id="@+id/exo_more_button" android:layout_width="match_parent"
android:layout_width="42dp" android:layout_height="match_parent"
android:layout_height="42dp" android:layout_gravity="center"
android:layout_gravity="end"> android:background="@color/exo_black_opacity_60"/>
<ImageButton <FrameLayout android:id="@id/exo_bottom_bar"
android:clickable="false" android:layout_width="match_parent"
android:id="@+id/exo_more" android:layout_height="@dimen/exo_styled_bottom_bar_height"
android:layout_width="24dp" android:layout_marginTop="@dimen/exo_styled_bottom_bar_margin_top"
android:layout_height="24dp" android:layout_gravity="bottom"
android:layout_gravity="center" android:background="@color/exo_bottom_bar_background"
android:adjustViewBounds="true" android:layoutDirection="ltr">
android:scaleType="fitCenter"
android:background="@android:color/transparent" <LinearLayout android:id="@id/exo_time"
android:contentDescription="More" android:layout_width="wrap_content"
android:src="@drawable/ic_more_vertical" android:layout_height="wrap_content"
/> android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingRight="@dimen/exo_styled_bottom_bar_time_padding"
android:layout_gravity="center_vertical|start"
android:layoutDirection="ltr">
<TextView android:id="@id/exo_position"
style="@style/ExoStyledControls.TimeText.Position"/>
<TextView
style="@style/ExoStyledControls.TimeText.Separator"/>
<TextView android:id="@id/exo_duration"
style="@style/ExoStyledControls.TimeText.Duration"/>
</LinearLayout>
<LinearLayout android:id="@id/exo_basic_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layoutDirection="ltr">
<ImageButton android:id="@+id/exo_more"
style="@style/ExoStyledControls.Button.Bottom.Settings"/>
<FrameLayout
android:id="@+id/exo_fullscreen_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="end">
<ImageButton
android:clickable="false"
android:id="@+id/exo_fullscreen_enable"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="Fullscreen"
android:src="@drawable/ic_maximize"
android:visibility="gone"
/>
<ImageButton
android:clickable="false"
android:id="@+id/exo_fullscreen_disable"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="Exit Fullscreen"
android:src="@drawable/ic_maximize"
android:visibility="gone"
/>
</FrameLayout>
</LinearLayout>
</FrameLayout> </FrameLayout>
<View android:id="@id/exo_progress_placeholder"
<Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/exo_styled_progress_layout_height"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/exo_styled_progress_margin_bottom"/>
<LinearLayout android:id="@id/exo_minimal_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/exo_styled_minimal_controls_margin_bottom"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="8dp"> android:gravity="center_vertical"
<Space android:layoutDirection="ltr">
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="@id/exo_rew"
android:layout_width="72sp"
android:layout_height="52sp"
android:layout_gravity="start"
android:background="@android:color/transparent"
android:contentDescription="@string/exo_controls_rewind_description"
android:scaleType="center"
android:src="@drawable/ic_rewind" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="@id/exo_repeat_toggle"
style="@style/ExoMediaButton" />
<ImageButton <ImageButton android:id="@id/exo_minimal_fullscreen"
android:id="@id/exo_play" style="@style/ExoStyledControls.Button.Bottom.FullScreen"/>
android:contentDescription="@string/exo_controls_play_description"
android:src="@drawable/ic_play"
android:layout_height="52sp"
android:layout_width="72sp"
android:scaleType="center"
android:background="@android:color/transparent"
/>
<ImageButton
android:id="@id/exo_pause"
android:contentDescription="@string/exo_controls_pause_description"
android:src="@drawable/ic_pause"
android:layout_height="52sp"
android:layout_width="72sp"
android:scaleType="center"
android:background="@android:color/transparent"
/>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="@id/exo_ffwd"
android:layout_width="72sp"
android:layout_height="52sp"
android:layout_gravity="end"
android:background="@android:color/transparent"
android:contentDescription="@string/exo_controls_fastforward_description"
android:scaleType="center"
android:src="@drawable/ic_fast_forward" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout> </LinearLayout>
<LinearLayout
<Space android:id="@id/exo_center_controls"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_gravity="center"
android:gravity="bottom" android:background="@android:color/transparent"
android:orientation="horizontal"> android:gravity="center"
android:padding="@dimen/exo_styled_controls_padding">
<TextView <ImageButton android:id="@id/exo_rew"
android:id="@id/exo_position" style="@style/ExoStyledControls.Button.Center.RewWithAmount"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_gravity="center"
android:paddingStart="12dp"
android:paddingEnd="2dp"
android:textColor="#FFFFFF"
android:textSize="14sp" />
<TextView <ImageButton android:id="@id/exo_play_pause"
android:layout_width="wrap_content" style="@style/ExoStyledControls.Button.Center.PlayPause"/>
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#BABABA"
android:textSize="14sp"
android:includeFontPadding="false"
android:text="@string/player_time_seperator" />
<TextView <ImageButton android:id="@id/exo_ffwd"
android:id="@id/exo_duration" style="@style/ExoStyledControls.Button.Center.FfwdWithAmount"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:includeFontPadding="false"
android:paddingStart="2dp"
android:paddingEnd="6dp"
android:textColor="#BABABA"
android:textSize="14sp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/exo_fullscreen_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="end">
<ImageButton
android:clickable="false"
android:id="@+id/exo_fullscreen_enable"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="Fullscreen"
android:src="@drawable/ic_maximize"
android:visibility="gone"
/>
<ImageButton
android:clickable="false"
android:id="@+id/exo_fullscreen_disable"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="Exit Fullscreen"
android:src="@drawable/ic_maximize"
android:visibility="gone"
/>
</FrameLayout>
</LinearLayout> </LinearLayout>
<LinearLayout </merge>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-12dp"
android:gravity="bottom"
android:orientation="horizontal">
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@id/exo_progress"
android:layout_width="0dp"
android:layout_height="26dp"
android:layout_weight="1"
app:played_color="?attr/colorPrimary" />
</LinearLayout>
<!-- <LinearLayout-->
<!-- android:visibility="gone"-->
<!-- android:id="@+id/exo_torrent_status"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content">-->
<!-- <ProgressBar-->
<!-- android:id="@+id/torrent_progress"-->
<!-- style="?android:attr/progressBarStyleHorizontal"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:indeterminate="false"-->
<!-- android:max="100" />-->
<!-- </LinearLayout>-->
</LinearLayout>

View File

@ -3,7 +3,7 @@ buildscript {
ext { ext {
compose_version = '1.2.0-alpha08' compose_version = '1.2.0-alpha08'
exo_player_version = '2.17.1' exo_player_version = '2.17.1'
koltin_version = '1.6.10' koltin_version = '1.6.20'
room_version = '2.4.2' room_version = '2.4.2'
} }
repositories { repositories {