Android的VideoView setVideoURI块UI线程线程、VideoView、Android、UI

由网友(爷鄙视你的智商、)分享简介:VideoView在Android上的setVideoURI方法似乎阻塞UI线程。当我把这种方法,在UI获得的laggy,即使是在快速设备。有没有在这里提高性能的一种方式?唯一的其他线程与话题,我可以在这里找到:结果https://groups.google.com/forum/#!topic/android-dev...

VideoView在Android上的setVideoURI方法似乎阻塞UI线程。当我把这种方法,在UI获得的laggy,即使是在快速设备。有没有在这里提高性能的一种方式?唯一的其他线程与话题,我可以在这里找到:结果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

阅读全文

相关推荐

最新文章