add player fullscreen on tilt

This commit is contained in:
Jannik 2020-10-11 14:14:38 +02:00
parent 2866d01c22
commit 8285b2bf62
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
3 changed files with 44 additions and 4 deletions

View File

@ -11,10 +11,15 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".PlayerActivity"></activity> <activity
android:name=".PlayerActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|layoutDirection"
android:theme="@style/AppTheme.AppCompat.Light.NoActionBar.FullScreen" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name"> android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -1,8 +1,12 @@
package org.mosad.teapod package org.mosad.teapod
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.View import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.MediaItem
@ -26,9 +30,11 @@ class PlayerActivity : AppCompatActivity() {
private var currentWindow = 0 private var currentWindow = 0
private var playbackPosition: Long = 0 private var playbackPosition: Long = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_player) setContentView(R.layout.activity_player)
hideBars() // Initial hide the bars
streamUrl = intent.getStringExtra("streamUrl").toString() streamUrl = intent.getStringExtra("streamUrl").toString()
} }
@ -68,7 +74,7 @@ class PlayerActivity : AppCompatActivity() {
private fun initPlayer() { private fun initPlayer() {
if (streamUrl.isEmpty()) { if (streamUrl.isEmpty()) {
println("no streamUrl set") Log.e(javaClass.name, "No stream url was set.")
return return
} }
@ -87,13 +93,18 @@ class PlayerActivity : AppCompatActivity() {
super.onPlaybackStateChanged(state) super.onPlaybackStateChanged(state)
loading.visibility = when (state) { loading.visibility = when (state) {
ExoPlayer.STATE_READY -> View.GONE ExoPlayer.STATE_READY -> View.GONE
ExoPlayer.STATE_BUFFERING -> View.VISIBLE ExoPlayer.STATE_BUFFERING -> View.VISIBLE
else -> View.GONE else -> View.GONE
} }
} }
}) })
// when the player controls get hidden, hide the bars too
video_view.setControllerVisibilityListener {
if (it == View.GONE) hideBars()
}
video_view.player = player video_view.player = player
} }
@ -104,4 +115,20 @@ class PlayerActivity : AppCompatActivity() {
player.release() player.release()
} }
/**
* hide the status and navigation bar
*/
private fun hideBars() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(false)
window.insetsController?.apply {
hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE
}
} else {
@Suppress("deprecation")
window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
}
}
} }

View File

@ -7,4 +7,12 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="AppTheme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources> </resources>