apply fullscreenmode again

This commit is contained in:
Christian Schabesberger 2024-07-23 13:26:27 +02:00
parent b26cf2b402
commit b5b75558b5
4 changed files with 97 additions and 59 deletions

View File

@ -72,6 +72,7 @@ interface VideoPlayerViewModel {
var minContentRatio: Float
var maxContentRatio: Float
var contentFitMode: ContentScale
var fullscreenListener: FullscreenListener?
fun initUIState(instanceState: Bundle)
fun play()
@ -80,6 +81,10 @@ interface VideoPlayerViewModel {
fun nextStream()
fun switchToFullscreen()
fun switchToEmbeddedView()
interface FullscreenListener {
fun onFullscreenToggle(isFullscreen: Boolean)
}
}
@HiltViewModel
@ -90,8 +95,11 @@ class VideoPlayerViewModelImpl @Inject constructor(
// private
private val mutableUiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
private var currentContentRatio = 1F
//interface
override var fullscreenListener: VideoPlayerViewModel.FullscreenListener? = null
override var newPlayer: NewPlayer? = null
set(value) {
field = value
@ -161,10 +169,12 @@ class VideoPlayerViewModelImpl @Inject constructor(
fun updateContentRatio(videoSize: VideoSize) {
val newRatio = videoSize.getRatio()
Log.d(TAG, "Update Content ratio: $newRatio")
val ratio = if(newRatio.isNaN()) currentContentRatio else newRatio
currentContentRatio = ratio
Log.d(TAG, "Update Content ratio: $ratio")
mutableUiState.update {
it.copy(
contentRatio = newRatio,
contentRatio = currentContentRatio,
uiRatio = getUiRatio()
)
}
@ -208,12 +218,14 @@ class VideoPlayerViewModelImpl @Inject constructor(
}
override fun switchToEmbeddedView() {
fullscreenListener?.onFullscreenToggle(false)
mutableUiState.update {
it.copy(fullscreen = false)
}
}
override fun switchToFullscreen() {
fullscreenListener?.onFullscreenToggle(true)
mutableUiState.update {
it.copy(fullscreen = true)
}
@ -237,6 +249,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
override var minContentRatio = 4F / 3F
override var maxContentRatio = 16F / 9F
override var contentFitMode = ContentScale.FIT_INSIDE
override var fullscreenListener: VideoPlayerViewModel.FullscreenListener? = null
override fun initUIState(instanceState: Bundle) {
println("dummy impl")

View File

@ -21,11 +21,14 @@
package net.newpipe.newplayer.testapp
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import dagger.hilt.android.AndroidEntryPoint
import net.newpipe.newplayer.NewPlayer
import net.newpipe.newplayer.VideoPlayerView
@ -48,56 +51,43 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
val video_view = findViewById<VideoPlayerView>(R.id.new_player_video_view)
val start_stream_button = findViewById<Button>(R.id.start_stream_button)
val buttons_layout = findViewById<View>(R.id.buttons_layout)
start_stream_button.setOnClickListener {
newPlayer.playWhenReady = true
newPlayer.setStream(getString(R.string.ccc_chromebooks_video))
}
video_view.viewModel = videoPlayerViewModel
videoPlayerViewModel.newPlayer = newPlayer
videoPlayerViewModel.maxContentRatio = 4F/3F
//videoPlayerViewModel.maxContentRatio = 4F/3F
videoPlayerViewModel.contentFitMode = ContentScale.FIT_INSIDE
/*
video_view.fullScreenToggleListener = object : VideoPlayerView.FullScreenToggleListener {
override fun fullscreenToggle(turnOn: Boolean) {
if (turnOn) {
println("gurken blub")
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
v.setPadding(
0, 0, 0, 0
)
insets
}
} else {
println("gurken blab")
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(
systemBars.left,
systemBars.top,
systemBars.right,
systemBars.bottom
)
insets
}
}
if (videoPlayerViewModel.uiState.value.fullscreen) {
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(0, 0, 0, 0)
insets
}
buttons_layout.visibility = View.GONE
} else {
buttons_layout.visibility = View.VISIBLE
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(
systemBars.left,
systemBars.top,
systemBars.right,
systemBars.bottom
)
insets
}
}
*/
newPlayer.playWhenReady = true
newPlayer.setStream(getString(R.string.ccc_chromebooks_video))
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(
systemBars.left,
systemBars.top,
systemBars.right,
systemBars.bottom
)
insets
}
}
}

View File

@ -34,7 +34,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBaseline_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/hw_view"
app:layout_constraintEnd_toStartOf="@+id/buttons_layout"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@ -52,16 +52,27 @@
</LinearLayout>
<TextView
android:id="@+id/hw_view"
<FrameLayout
android:id="@+id/buttons_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="Start Stream"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/player_column"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent" >
<Button
android:id="@+id/start_stream_button"
android:text="Start Stream"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -18,7 +18,6 @@
You should have received a copy of the GNU General Public License
along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
@ -27,25 +26,50 @@
android:layout_height="match_parent"
tools:context=".MainActivity">
<net.newpipe.newplayer.VideoPlayerView
android:id="@+id/new_player_video_view"
<FrameLayout
android:id="@+id/player_column"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/buttons_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:name="net.newpipe.newplayer.VideoPlayerFragment" />
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_weight="1">
<TextView
android:id="@+id/hw_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
<net.newpipe.newplayer.VideoPlayerView
android:id="@+id/new_player_video_view"
android:name="net.newpipe.newplayer.VideoPlayerFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</FrameLayout>
<FrameLayout
android:id="@id/buttons_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/player_column"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/new_player_video_view" />
app:layout_constraintVertical_weight="1">
<Button
android:id="@+id/start_stream_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Start Stream" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>