简体   繁体   中英

setLooping(true) is not working in jellybean and kitkat

i am developing an app which play video from URL, to control video i also add mediacontroller.

i want that video play in endless loop, so i added following below code to mediaplayer

`mp.setLooping(true);` 

inside videoview.setOnPreparedListener method

But setLoop(true) method not working in jellybean and kitkat device. It work in Android M and above version. I not debug in android L because i do not have Emulator yet of it.

i also go through MediaPlayer document, they mentioned that setLooping(true) is added in API 1 but it not working in android K and J

help me to solve above problem

below is my full code

public void videoStup(final ProgressBar pb, final VideoView videoview)
    {
        pb.setVisibility(View.VISIBLE);

        try
        {
            MediaController mediacontroller = new MediaController(this);
            mediacontroller.setAnchorView(this.videoview);
            mediacontroller.setBackgroundResource(R.color.white);
            //mediacontroller.setVisibility(View.GONE);

            Uri video = Uri.parse(VideoURL);
            videoview.setMediaController(mediacontroller);
            videoview.setVideoURI(video);
            videoview.seekTo(100);

        } catch (Exception e)
        {
            Log.e(TAG, "error = "+e.getMessage());
            //e.printStackTrace();
        }

        videoview.requestFocus();
        videoview.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
                pb.setVisibility(View.GONE);
                videoview.start();
            }
        });
    }

i solved my problem with the help of below code, now it work in Android jellybean & Android Kitkat also

i only thing i need to called resume method after video complete.

here is my code

videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp)
        {

            Log.d(TAG,"onCompletion");
            videoview.resume();

        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM