Move to media3: buggy!

This commit is contained in:
Matthieu 2022-06-07 20:26:14 +02:00
parent f08bec487b
commit f1d43a0cdc
6 changed files with 81 additions and 41 deletions

View File

@ -110,13 +110,13 @@ dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation "androidx.browser:browser:1.4.0"
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'androidx.paging:paging-runtime-ktx:3.1.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
@ -128,12 +128,44 @@ dependencies {
implementation "androidx.activity:activity-ktx:1.4.0"
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation 'androidx.work:work-runtime-ktx:2.7.1'
implementation 'androidx.media2:media2-widget:1.2.1'
implementation 'androidx.media2:media2-player:1.2.1'
def media3_version = "1.0.0-alpha03"
// For media playback using ExoPlayer
implementation "androidx.media3:media3-exoplayer:$media3_version"
// For DASH playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
// For HLS playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
// For RTSP playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-rtsp:$media3_version"
// For loading data using the OkHttp network stack
implementation "androidx.media3:media3-datasource-okhttp:$media3_version"
// For building media playback UIs
implementation "androidx.media3:media3-ui:$media3_version"
// For exposing and controlling media sessions
implementation "androidx.media3:media3-session:$media3_version"
// For extracting data from media containers
implementation "androidx.media3:media3-extractor:$media3_version"
// For scheduling background operations using Jetpack Work's WorkManager with ExoPlayer
implementation "androidx.media3:media3-exoplayer-workmanager:$media3_version"
// For transforming media files
implementation "androidx.media3:media3-transformer:$media3_version"
// Common functionality for loading data
implementation "androidx.media3:media3-datasource:$media3_version"
// Common functionality used across multiple media libraries
implementation "androidx.media3:media3-common:$media3_version"
// Use the most recent version of CameraX
def cameraX_version = '1.1.0-beta02'
def cameraX_version = '1.1.0-rc01'
implementation "androidx.camera:camera-core:$cameraX_version"
implementation "androidx.camera:camera-camera2:$cameraX_version"
// CameraX Lifecycle library
@ -154,7 +186,7 @@ dependencies {
*/
implementation 'com.google.android.material:material:1.5.0'
implementation 'com.google.android.material:material:1.6.0'
//Dagger (dependency injection)
implementation 'com.google.dagger:dagger-android:2.40.5'
@ -163,7 +195,7 @@ dependencies {
kapt 'com.google.dagger:dagger-android-processor:2.40.5'
kapt 'com.google.dagger:dagger-compiler:2.40.5'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
@ -227,7 +259,7 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0'
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.9.2'
}

View File

@ -303,7 +303,6 @@ class LoginActivity : BaseActivity() {
}
}
@OptIn(ExperimentalPagingApi::class)
private suspend fun storeUser(accessToken: String, refreshToken: String?, clientId: String, clientSecret: String, instance: String) {
try {
val user = pixelfedAPI.verifyCredentials("Bearer $accessToken")

View File

@ -10,17 +10,21 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.media.AudioAttributesCompat
import androidx.media2.common.MediaMetadata
import androidx.media2.common.UriMediaItem
import androidx.media2.player.MediaPlayer
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.MediaSession
import org.pixeldroid.app.databinding.ActivityMediaviewerBinding
import org.pixeldroid.app.utils.BaseActivity
import kotlin.random.Random
class MediaViewerActivity : BaseActivity() {
private lateinit var mediaPlayer: MediaPlayer
private lateinit var mediaPlayer: ExoPlayer
private lateinit var session: MediaSession
private lateinit var binding: ActivityMediaviewerBinding
companion object {
const val VIDEO_URL_TAG = "video_url_mediavieweractivity"
const val VIDEO_DESCRIPTION_TAG = "video_description_mediavieweractivity"
@ -41,15 +45,14 @@ class MediaViewerActivity : BaseActivity() {
val uri: String = intent.getStringExtra(VIDEO_URL_TAG).orEmpty()
val description: String? = intent.getStringExtra(VIDEO_DESCRIPTION_TAG)
val mediaItem: UriMediaItem = UriMediaItem.Builder(uri.toUri()).build()
mediaItem.metadata = MediaMetadata.Builder()
.putString(MediaMetadata.METADATA_KEY_TITLE, description ?: "")
.build()
val mediaItem: MediaItem = MediaItem.Builder().setUri(uri)
.setMediaMetadata(MediaMetadata.Builder().setTitle(description).build()).build()
mediaPlayer = ExoPlayer.Builder(this).build()
mediaPlayer = MediaPlayer(this)
mediaPlayer.setMediaItem(mediaItem)
binding.videoView.mediaControlView?.setOnFullScreenListener{ view, fullscreen ->
binding.videoView.setControllerOnFullScreenModeChangedListener { fullscreen ->
val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView)
if (!fullscreen) {
// Configure the behavior of the hidden system bars
@ -74,17 +77,9 @@ class MediaViewerActivity : BaseActivity() {
}
}
// Configure audio
mediaPlayer.setAudioAttributes(AudioAttributesCompat.Builder()
.setLegacyStreamType(STREAM_MUSIC)
.setUsage(AudioAttributesCompat.USAGE_MEDIA)
.setContentType(AudioAttributesCompat.CONTENT_TYPE_MOVIE)
.build()
)
mediaPlayer.prepare()
binding.videoView.setPlayer(mediaPlayer)
binding.videoView.player = mediaPlayer
// Start actually playing the video
mediaPlayer.play()
@ -93,10 +88,21 @@ class MediaViewerActivity : BaseActivity() {
override fun onPause() {
super.onPause()
mediaPlayer.pause()
binding.videoView.onPause()
}
override fun onDestroy() {
super.onDestroy()
mediaPlayer.close()
override fun onResume() {
super.onResume()
binding.videoView.onResume()
mediaPlayer.play()
}
override fun onStop() {
super.onStop()
binding.videoView.player = null
}
override fun onStart() {
super.onStart()
binding.videoView.player = mediaPlayer
}
}

View File

@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.media2.widget.VideoView
<androidx.media3.ui.PlayerView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" />
android:background="#000000"
app:use_artwork="true" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

View File

@ -1,7 +1,7 @@
#Sat Sep 18 21:24:34 CEST 2021
#Mon May 16 20:35:20 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
distributionSha256Sum=f581709a9c35e9cb92e16f585d2c4bc99b2b1a5f85d2badbd3dc6bff59e1e6dd
distributionSha256Sum=29e49b10984e585d8118b7d0bc452f944e386458df27371b49b4ac1dec4b7fda