Android的VideoView setVideoURI块UI线程 [英] Android VideoView setVideoURI blocks UI thread

查看:1310
本文介绍了Android的VideoView setVideoURI块UI线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VideoView在Android上的setVideoURI方法似乎阻塞UI线程。当我把这种方法,在UI获得的laggy,即使是在快速设备。有没有在这里提高性能的一种方式?
唯一的其他线程与话题,我可以在这里找到:结果
<一href=\"https://groups.google.com/forum/#!topic/android-developers/eAAEAEDcksM\">https://groups.google.com/forum/#!topic/android-developers/eAAEAEDcksM

但它很老,也没有一个令人满意的答案。

The setVideoURI method of VideoView in Android seems to be blocking the UI thread. As soon as I call this method, the UI get's laggy, even on fast devices. Is there a way to improve performance here? The only other thread with that topic I could find here:
https://groups.google.com/forum/#!topic/android-developers/eAAEAEDcksM
but it's quite old and doesn't have a satisfying answer.

推荐答案

我所做的就是地方setVideoUri()方法与一个活套即一个处理程序。

What i did was place the setVideoUri() method into a handler with a looper i.e.

new Handler(Looper.myLooper()).post(new Runnable(){
    @Override
    public void run(){
        videoview.setVideoUri("uri");
    }
});

这运行在主UI线程之外code,但仍保留在钩子因此code可以在不引发异常被执行

this runs the code outside the main UI thread, but keeps it in a looper so the code can be executed without throwing an exception

这篇关于Android的VideoView setVideoURI块UI线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆