Audio and fullscreen video
This commit is contained in:
parent
03f83790f2
commit
77c895bbf2
|
@ -25,6 +25,7 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".posts.MediaViewerActivity"
|
android:name=".posts.MediaViewerActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity android:name=".postCreation.camera.CameraActivity" />
|
<activity android:name=".postCreation.camera.CameraActivity" />
|
||||||
<activity
|
<activity
|
||||||
|
|
|
@ -2,8 +2,14 @@ package org.pixeldroid.app.posts
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.media.AudioManager.STREAM_MUSIC
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
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.MediaMetadata
|
||||||
import androidx.media2.common.UriMediaItem
|
import androidx.media2.common.UriMediaItem
|
||||||
import androidx.media2.player.MediaPlayer
|
import androidx.media2.player.MediaPlayer
|
||||||
|
@ -12,6 +18,7 @@ import org.pixeldroid.app.utils.BaseActivity
|
||||||
|
|
||||||
class MediaViewerActivity : BaseActivity() {
|
class MediaViewerActivity : BaseActivity() {
|
||||||
|
|
||||||
|
private lateinit var mediaPlayer: MediaPlayer
|
||||||
private lateinit var binding: ActivityMediaviewerBinding
|
private lateinit var binding: ActivityMediaviewerBinding
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -39,8 +46,42 @@ class MediaViewerActivity : BaseActivity() {
|
||||||
.putString(MediaMetadata.METADATA_KEY_TITLE, description ?: "")
|
.putString(MediaMetadata.METADATA_KEY_TITLE, description ?: "")
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val mediaPlayer = MediaPlayer(this)
|
mediaPlayer = MediaPlayer(this)
|
||||||
mediaPlayer.setMediaItem(mediaItem)
|
mediaPlayer.setMediaItem(mediaItem)
|
||||||
|
|
||||||
|
binding.videoView.mediaControlView?.setOnFullScreenListener{ view, fullscreen ->
|
||||||
|
val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView)
|
||||||
|
if (!fullscreen) {
|
||||||
|
// Configure the behavior of the hidden system bars
|
||||||
|
windowInsetsController?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
// Hide both the status bar and the navigation bar
|
||||||
|
windowInsetsController?.show(WindowInsetsCompat.Type.systemBars())
|
||||||
|
supportActionBar?.show()
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
|
} else {
|
||||||
|
// Configure the behavior of the hidden system bars
|
||||||
|
windowInsetsController?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
// Hide both the status bar and the navigation bar
|
||||||
|
windowInsetsController?.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
|
|
||||||
|
requestedOrientation =
|
||||||
|
if (mediaPlayer.videoSize.height < mediaPlayer.videoSize.width) {
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||||
|
} else {
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
|
}
|
||||||
|
supportActionBar?.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure audio
|
||||||
|
mediaPlayer.setAudioAttributes(AudioAttributesCompat.Builder()
|
||||||
|
.setLegacyStreamType(STREAM_MUSIC)
|
||||||
|
.setUsage(AudioAttributesCompat.USAGE_MEDIA)
|
||||||
|
.setContentType(AudioAttributesCompat.CONTENT_TYPE_MOVIE)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
|
||||||
mediaPlayer.prepare()
|
mediaPlayer.prepare()
|
||||||
|
|
||||||
binding.videoView.setPlayer(mediaPlayer)
|
binding.videoView.setPlayer(mediaPlayer)
|
||||||
|
@ -48,4 +89,14 @@ class MediaViewerActivity : BaseActivity() {
|
||||||
// Start actually playing the video
|
// Start actually playing the video
|
||||||
mediaPlayer.play()
|
mediaPlayer.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
mediaPlayer.pause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
mediaPlayer.close()
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue