PierfrancescoSoffritti / android-youtube-player

YouTube Player library for Android and Chromecast, stable and customizable.
https://pierfrancescosoffritti.github.io/android-youtube-player/
MIT License
3.44k stars 765 forks source link

HD Resolution Problem #1074

Open RMF09 opened 1 year ago

RMF09 commented 1 year ago

I have implemented this library into my jetpack compose app, the library is working to play youtube video, when I change the resolution of video to 1080p60, the video become lag every 3 seconds on my Nokia 6. Then I compared video from youtube app, that's work fine in 1080p60 resolution. Why this happened? I've configured manifest file to enable hardware acceleration, but nothing changes.

this is my code `

companion object {
    const val ID = "videoId"
    const val START_SECONDS = "startSeconds"
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    videoId = intent.getStringExtra(ID) ?: ""
    startSeconds = intent.getFloatExtra(START_SECONDS, 0f)
    setContent {
        JadwalMotoGPTheme {
            // A surface container using the 'background' color from the theme
            Surface(
                modifier = Modifier.fillMaxSize(),
                color = Dark
            ) {

                val activity = LocalContext.current as Activity
                val params = remember {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        val aspectRatio = Rational(16, 9)
                        PictureInPictureParams.Builder().setAspectRatio(aspectRatio).build()
                    } else {
                        null
                    }
                }

                var isPlay by remember {
                    mutableStateOf(false)
                }

                Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {

                    AndroidView(factory = { context ->
                        val view = YouTubePlayerView(context).apply {
                            addYouTubePlayerListener(
                                object : AbstractYouTubePlayerListener() {
                                    override fun onReady(youTubePlayer: YouTubePlayer) {
                                        super.onReady(youTubePlayer)
                                        this@VideoActivity.youTubePlayer = youTubePlayer
                                        youTubePlayer.loadVideo(
                                            videoId,
                                            startSeconds = startSeconds
                                        )
                                        isPlay = true
                                    }

                                }
                            )
                        }
                        view
                    })
                }

                val context = LocalContext.current

                if (context.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
                )
                    BackHandler(isPlay) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                            activity.enterPictureInPictureMode(params!!)
                        }
                    }
            }
        }
    }
}

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    videoId = intent?.getStringExtra(ID) ?: ""
    startSeconds = intent?.getFloatExtra(START_SECONDS, 0f) ?: 0f

    youTubePlayer?.loadVideo(videoId, startSeconds)
}}

`