gpt4 book ai didi

android - 如何在Timer中使用OpenGL

转载 作者:行者123 更新时间:2023-12-02 13:40:22 27 4
gpt4 key购买 nike

当我预先加载所有位图(带有测试数据)时,以下代码有效

for (bitmap in bitmaps){
feedInOpenGL(bitmap)
}
但是当我尝试使用计时器创建位图时,
timer!!.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
if (!recording) return
val bitmap = getNextBitmap()
feedInOpenGL(bitmap)
}
}, 0, frameDuration)
我无法停止MediaMuxer。当我尝试停止它时,它会
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tolotra.screenrecordexample, PID: 31248
java.lang.IllegalStateException: Failed to stop the muxer
at android.media.MediaMuxer.nativeStop(Native Method)
at android.media.MediaMuxer.stop(MediaMuxer.java:454)
at com.tolotra.screen_recorder.VideoBuilder._cleanUp(VideoBuilder.kt:292)
at com.tolotra.screen_recorder.VideoBuilder.finish(VideoBuilder.kt:95)
at com.tolotra.screen_recorder.ScreenRecorder$stop$1.run(ScreenRecorder.kt:156)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6734)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
挖完之后,我在某处读书

OpenGL always operates on a context that is made "current" and thecontext holds data in thread-local storage. This means it'sthread-specific. Therefore you always need to be aware from whichthread you're calling the OpenGL functions.


因此,我怀疑问题出在我的计时器上,因为它每次都会创建一个新线程。
如果我怀疑是真的,该如何使用计时器进行这项工作?

最佳答案

解决方案是在同一线程上运行OpenGL / MediaMuxer / MediaEncoder设置/启动/停止和计时器回调。
这是使用单线程执行器实现的

tpe = Executors.newSingleThreadExecutor()
tpe?.submit(Runnable {
this.recording = true;
_startRecorderWorker();
})
并在计时器中
 timer!!.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
if (!recording) return;
tpe?.submit(Runnable {
loop()
})

}
}, 0, frameDuration)

关于android - 如何在Timer中使用OpenGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64083313/

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