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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With