Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView setVideoURI blocks UI thread

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.

like image 322
Micky Avatar asked Jul 02 '14 10:07

Micky


2 Answers

VideoView.setVideoURI() starts a new thread for media playback, but it is the media decoding part which causes extra delay.The only solution that might be ok for you is using some NDK hacks, but doesn't worths for me

like image 92
Stanojevic Dalibor Avatar answered Nov 19 '22 09:11

Stanojevic Dalibor


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");
    }
});

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

like image 2
user3005339 Avatar answered Nov 19 '22 09:11

user3005339