gpt4 book ai didi

android - Exoplayer 正在使用 PageTransformer 移除预览

转载 作者:行者123 更新时间:2023-12-04 10:55:09 25 4
gpt4 key购买 nike

我有一个带有 CubeTransformer 的 viewPager,它正在转换每个 fragment 。每个 fragment 内都有图像或视频 View (使用 Exoplayer)。当你试图通过转换来改变 framgnet 时,exoplayer 损失预览(我有一个黑屏),即使它没有播放。但是当你把状态改成正常后,预览又回来了

否则,如果您将删除 pageTransformer,审查不会消失。如何让预览始终在屏幕上?

CubeTransformer

class CubeTransformer : ViewPager.PageTransformer {
override fun transformPage(view: View, position: Float) {
if (view.visibility != View.VISIBLE) return

view.apply {
cameraDistance = (view.width * distanceMultiplier).toFloat()
pivotX = if (position < 0f) view.width.toFloat() else 0f
pivotY = view.height * 0.5f
rotationY = 90f * position

if (position < -1 || position > 1) {
alpha = 0f // item not visible
} else {
alpha = 1f
}
}
}

private companion object {
private const val distanceMultiplier: Int = 20
}
}

视频 View

class VideoView(context: Context) : ConstraintLayout(context, null) {
private val player = ExoPlayerFactory.newSimpleInstance(context, DefaultTrackSelector(), DefaultLoadControl())
private val dataSourceFactory = DefaultDataSourceFactory(context, "android")

private lateinit var model: Model

init {
inflate(context, R.layout.story_item_video, this)
video_view.player = player
video_view.keepScreenOn = true
video_view.setBackgroundColor(Color.TRANSPARENT)
video_view.setShutterBackgroundColor(Color.TRANSPARENT)
}

fun setData(model: Model?) {
if (model== null) return

this.model = model

val mediaSource = HlsMediaSource
.Factory(dataSourceFactory)
.setExtractorFactory(DefaultHlsExtractorFactory())
.createMediaSource(Uri.parse(model.streamLink))

player.playWhenReady = true
player.prepare(mediaSource)

player.addListener(object: Player.EventListener {
override fun onPlaybackParametersChanged(playbackParameters: PlaybackParameters?) {
}

override fun onSeekProcessed() {}

override fun onTracksChanged(trackGroups: TrackGroupArray?, trackSelections: TrackSelectionArray?) {
}

override fun onPlayerError(error: ExoPlaybackException?) {
}

override fun onLoadingChanged(isLoading: Boolean) {
}

override fun onPositionDiscontinuity(reason: Int) {
}

override fun onRepeatModeChanged(repeatMode: Int) {
}

override fun onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean) {
}

override fun onTimelineChanged(timeline: Timeline?, manifest: Any?, reason: Int) {
}

override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {

}
})
}
}

最佳答案

经过一天的搜索,我找到了问题的答案。您只需要将 app:surface_type="texture_view" 添加到您的 PlayerView

关于android - Exoplayer 正在使用 PageTransformer 移除预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59253434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com