Android Kotlin视频播放器技术求助:退出重进/息屏亮屏后视频黑屏仅音频播放,及ExoPlayer本地文件播放问题
I'm building an Android video playback app using Kotlin, following a tutorial focused on basic MediaPlayer implementation. Right now, the video plays perfectly on initial launch, but when I exit the app and re-enter, or wake the screen after it's turned off, the video display goes completely black—yet the audio continues to play without any issues.
I tried overriding the core lifecycle methods onStart(), onResume(), and onRestart() to attempt restoring the video playback state, here's the code I added:
override fun onStart() { super.onStart() print("hello") onPrepared(mediaPlayer) mediaPlayer.start() } override fun onResume() { super.onResume() print("hello") onPrepared(mediaPlayer) mediaPlayer.start() } override fun onRestart() { super.onRestart() print("hello") onPrepared(mediaPlayer) mediaPlayer.start() }
Unfortunately, this approach didn't fix the black screen problem. My goal is to achieve behavior similar to YouTube, where the video resumes playing properly (with visible content) when re-entering the app.
I also tried switching to ExoPlayer as an alternative, but I couldn't get it to successfully play local video files.
Does anyone have practical suggestions or solutions for either (or both) of these issues? Thanks in advance for your help!
内容的提问来源于stack exchange,提问作者Melli Flour

