apply fullscreenmode again
This commit is contained in:
parent
b26cf2b402
commit
b5b75558b5
|
@ -72,6 +72,7 @@ interface VideoPlayerViewModel {
|
||||||
var minContentRatio: Float
|
var minContentRatio: Float
|
||||||
var maxContentRatio: Float
|
var maxContentRatio: Float
|
||||||
var contentFitMode: ContentScale
|
var contentFitMode: ContentScale
|
||||||
|
var fullscreenListener: FullscreenListener?
|
||||||
|
|
||||||
fun initUIState(instanceState: Bundle)
|
fun initUIState(instanceState: Bundle)
|
||||||
fun play()
|
fun play()
|
||||||
|
@ -80,6 +81,10 @@ interface VideoPlayerViewModel {
|
||||||
fun nextStream()
|
fun nextStream()
|
||||||
fun switchToFullscreen()
|
fun switchToFullscreen()
|
||||||
fun switchToEmbeddedView()
|
fun switchToEmbeddedView()
|
||||||
|
|
||||||
|
interface FullscreenListener {
|
||||||
|
fun onFullscreenToggle(isFullscreen: Boolean)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
|
@ -90,8 +95,11 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
|
|
||||||
// private
|
// private
|
||||||
private val mutableUiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
|
private val mutableUiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
|
||||||
|
private var currentContentRatio = 1F
|
||||||
|
|
||||||
//interface
|
//interface
|
||||||
|
override var fullscreenListener: VideoPlayerViewModel.FullscreenListener? = null
|
||||||
|
|
||||||
override var newPlayer: NewPlayer? = null
|
override var newPlayer: NewPlayer? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
@ -161,10 +169,12 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
|
|
||||||
fun updateContentRatio(videoSize: VideoSize) {
|
fun updateContentRatio(videoSize: VideoSize) {
|
||||||
val newRatio = videoSize.getRatio()
|
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 {
|
mutableUiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
contentRatio = newRatio,
|
contentRatio = currentContentRatio,
|
||||||
uiRatio = getUiRatio()
|
uiRatio = getUiRatio()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -208,12 +218,14 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun switchToEmbeddedView() {
|
override fun switchToEmbeddedView() {
|
||||||
|
fullscreenListener?.onFullscreenToggle(false)
|
||||||
mutableUiState.update {
|
mutableUiState.update {
|
||||||
it.copy(fullscreen = false)
|
it.copy(fullscreen = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun switchToFullscreen() {
|
override fun switchToFullscreen() {
|
||||||
|
fullscreenListener?.onFullscreenToggle(true)
|
||||||
mutableUiState.update {
|
mutableUiState.update {
|
||||||
it.copy(fullscreen = true)
|
it.copy(fullscreen = true)
|
||||||
}
|
}
|
||||||
|
@ -237,6 +249,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
override var minContentRatio = 4F / 3F
|
override var minContentRatio = 4F / 3F
|
||||||
override var maxContentRatio = 16F / 9F
|
override var maxContentRatio = 16F / 9F
|
||||||
override var contentFitMode = ContentScale.FIT_INSIDE
|
override var contentFitMode = ContentScale.FIT_INSIDE
|
||||||
|
override var fullscreenListener: VideoPlayerViewModel.FullscreenListener? = null
|
||||||
|
|
||||||
override fun initUIState(instanceState: Bundle) {
|
override fun initUIState(instanceState: Bundle) {
|
||||||
println("dummy impl")
|
println("dummy impl")
|
||||||
|
|
|
@ -21,11 +21,14 @@
|
||||||
package net.newpipe.newplayer.testapp
|
package net.newpipe.newplayer.testapp
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.Button
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import net.newpipe.newplayer.NewPlayer
|
import net.newpipe.newplayer.NewPlayer
|
||||||
import net.newpipe.newplayer.VideoPlayerView
|
import net.newpipe.newplayer.VideoPlayerView
|
||||||
|
@ -48,56 +51,43 @@ class MainActivity : AppCompatActivity() {
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
val video_view = findViewById<VideoPlayerView>(R.id.new_player_video_view)
|
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
|
video_view.viewModel = videoPlayerViewModel
|
||||||
videoPlayerViewModel.newPlayer = newPlayer
|
videoPlayerViewModel.newPlayer = newPlayer
|
||||||
|
|
||||||
videoPlayerViewModel.maxContentRatio = 4F/3F
|
//videoPlayerViewModel.maxContentRatio = 4F/3F
|
||||||
videoPlayerViewModel.contentFitMode = ContentScale.FIT_INSIDE
|
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 {
|
if (videoPlayerViewModel.uiState.value.fullscreen) {
|
||||||
println("gurken blab")
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
v.setPadding(0, 0, 0, 0)
|
||||||
v.setPadding(
|
insets
|
||||||
systemBars.left,
|
|
||||||
systemBars.top,
|
|
||||||
systemBars.right,
|
|
||||||
systemBars.bottom
|
|
||||||
)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,7 +34,7 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layout_constraintBaseline_toBottomOf="parent"
|
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_constraintHorizontal_weight="1"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
@ -52,16 +52,27 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/hw_view"
|
<FrameLayout
|
||||||
|
android:id="@+id/buttons_layout"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Hello World!"
|
android:text="Start Stream"
|
||||||
app:layout_constraintHorizontal_weight="1"
|
app:layout_constraintHorizontal_weight="1"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@id/player_column"
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -18,7 +18,6 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
|
along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<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"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
@ -27,25 +26,50 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:minHeight="200dp"
|
app:layout_constraintBottom_toTopOf="@+id/buttons_layout"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
android:name="net.newpipe.newplayer.VideoPlayerFragment" />
|
app:layout_constraintVertical_bias="0.0"
|
||||||
|
app:layout_constraintVertical_weight="1">
|
||||||
|
|
||||||
<TextView
|
<net.newpipe.newplayer.VideoPlayerView
|
||||||
android:id="@+id/hw_view"
|
android:id="@+id/new_player_video_view"
|
||||||
android:layout_width="wrap_content"
|
android:name="net.newpipe.newplayer.VideoPlayerFragment"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:text="Hello World!"
|
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_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/player_column"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue