KC Chai
KC Chai

Reputation: 1617

VideoView (Can't create handler inside thread)

I'm trying to make my VideoView to work with Asynctask. However, there are some errors I couldnt understand. Could anyone please check on my codes? I'm getting this error "java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()"

@Override
        protected Void doInBackground(Void... params) {
            try {
                getWindow().setFormat(PixelFormat.TRANSLUCENT);
                MediaController mediaController = new MediaController(
                        MainActivity.this);
                mediaController.setAnchorView(videoView);

                Uri video = Uri.parse(videoPath);
                videoView.setMediaController(mediaController);
                videoView.setVideoURI(video);
                videoView.requestFocus();
                videoView.setOnPreparedListener(new OnPreparedListener() {

                    public void onPrepared(MediaPlayer mp) {

                        pDialog.dismiss();
                        videoView.start();
                    }
                });
            } catch (Exception e) {

                System.out.println("Video Play Error :" + e.toString());
                // finish();
            }
            return null;

        }

Upvotes: 0

Views: 717

Answers (1)

Sanober Malik
Sanober Malik

Reputation: 2805

You can't update view on doInBackground method. move the code for updating the view on onPostExecute method.

Upvotes: 1

Related Questions