rip out view init foo again

This commit is contained in:
Christian Schabesberger 2024-07-19 14:32:06 +02:00
parent d526527e94
commit be54682b93
5 changed files with 10 additions and 30 deletions

View File

@ -45,9 +45,6 @@ class VideoPlayerView : FrameLayout {
get() = videoPlayerFragment.minLayoutRatio
set(value) {videoPlayerFragment.minLayoutRatio = value}
var newPlayer:NewPlayer?
set(value) {videoPlayerFragment.newPlayer = value}
get() = videoPlayerFragment.newPlayer
@JvmOverloads
constructor(

View File

@ -41,24 +41,15 @@ import net.newpipe.newplayer.internal.model.VideoPlayerViewModelImpl
import net.newpipe.newplayer.internal.ui.VideoPlayerUI
import net.newpipe.newplayer.internal.ui.theme.VideoPlayerTheme
private const val TAG = "VideoPlayerFragment"
@AndroidEntryPoint
class VideoPlayerFragment() : Fragment() {
private val TAG = "VideoPlayerFragment"
private val viewModel: VideoPlayerViewModel by viewModels<VideoPlayerViewModelImpl>()
private var currentVideoRatio = 0F
private lateinit var composeView: ComposeView
var newPlayer: NewPlayer? = null
set(value) {
if(context != null) {
viewModel.newPlayer = value
} else {
field = value
}
}
get() = viewModel.newPlayer ?: field
var minLayoutRatio = 4F / 3F
set(value) {
if (value <= 0 && maxLayoutRatio < minLayoutRatio)
@ -98,11 +89,6 @@ class VideoPlayerFragment() : Fragment() {
val view = inflater.inflate(R.layout.video_player_framgent, container, false)
composeView = view.findViewById(R.id.player_copose_view)
// late init player in case player was set before fragment was attached to a context
if (viewModel.newPlayer == null) {
viewModel.newPlayer = newPlayer
}
viewModel.listener = object : VideoPlayerViewModel.Listener {
override fun requestUpdateLayoutRatio(videoRatio: Float) {
currentVideoRatio = videoRatio

View File

@ -87,7 +87,8 @@ interface VideoPlayerViewModel {
@HiltViewModel
class VideoPlayerViewModelImpl @Inject constructor(
private val savedStateHandle: SavedStateHandle,
application: Application
application: Application,
override var newPlayer: NewPlayer?
) : AndroidViewModel(application), VideoPlayerViewModel {
// private
@ -99,20 +100,20 @@ class VideoPlayerViewModelImpl @Inject constructor(
override val uiState = mutableUiState.asStateFlow()
override val events: SharedFlow<VideoPlayerViewModel.Events> = mutableEvent
override var listener: VideoPlayerViewModel.Listener? = null
override var newPlayer: NewPlayer? = null
set(value) {
field = value
installExoPlayer()
}
override val player:Player?
get() = newPlayer?.player
init {
installExoPlayer()
}
private fun installExoPlayer() {
player?.let { player ->
player.addListener(object : Player.Listener {
override fun onIsPlayingChanged(isPlaying: Boolean) {
super.onIsPlayingChanged(isPlaying)
println("gurken playerstate: $isPlaying")
mutableUiState.update {
it.copy(playing = isPlaying)
}
@ -163,7 +164,6 @@ class VideoPlayerViewModelImpl @Inject constructor(
}
override fun play() {
println("gurken player: $newPlayer")
newPlayer?.play()
}

View File

@ -112,13 +112,11 @@ fun VideoPlayerUI(
modifier = Modifier.fillMaxSize(),
factory = { context ->
SurfaceView(context).also { view ->
println("gurken attach player: ${viewModel.player}")
viewModel.player?.setVideoSurfaceView(view)
}
}, update = { view ->
when (lifecycle) {
Lifecycle.Event.ON_RESUME -> {
println("gurken reattach player: ${viewModel.player}")
viewModel.player?.setVideoSurfaceView(view)
}

View File

@ -43,7 +43,6 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
val video_view = findViewById<VideoPlayerView>(R.id.new_player_video_view)
video_view.newPlayer = newPlayer
newPlayer.playWhenReady = true
newPlayer.setStream(getString(R.string.ccc_chromebooks_video))