user3220781
user3220781

Reputation: 51

VideoView not looping video only on Galaxy s4

In my application I use a VideoView to stream video files,and I make the VideoView loop videos using the MediaPlayer.setLooping(true).

Here is some of the code -

videoView.setVideoPath(url);
videoView.setOnPreparedListener(new OnPreparedListener() {

@Override
public void onPrepared(MediaPlayer mp) {
    if (shouldLoopVideo) {
        mp.setLooping(true);
    }

    videoView.start();
}
 });

This code is working perfectly for all devices but the Galaxy s4 android 4.2.2 I tested on many devices, and many android versions, but the only ones that fail are the galaxy s4.

The device will play the video once, and stop (After calling the onCompletion listener).

Upvotes: 4

Views: 1806

Answers (3)

Pritesh Vishwakarma
Pritesh Vishwakarma

Reputation: 348

here is my code which work from android J to android O device

  VideoView vv = (VideoView)findViewById(R.id.vv);
        vv.setZOrderOnTop(true);

        try {
            MediaController mediacontroller = new MediaController(this);
            mediacontroller.setAnchorView(vv);

            Uri uri = Uri.parse(_video_link);
            vv.setMediaController(mediacontroller);
            vv.setVideoURI(uri);
            vv.seekTo(1);

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        vv.requestFocus();
        vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {

                mp.setLooping(true);
                vv.start();

            }
        });
        vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp)
            {
                vv.resume();
            }
        });

Upvotes: 0

Alex
Alex

Reputation: 177

It is a bug of Android 4.4.2. My workaround:

private String mVideoPath;
private VideoView mVideoView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mVideoPath = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.backvideo;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);


    mVideoView = (VideoView) view.findViewById(R.id.videoBackground);
    mVideoView.setVideoURI(Uri.parse(mVideoPath));
    mVideoView.setKeepScreenOn(true);


    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
        @Override
        public void onCompletion(MediaPlayer mp) {
            mVideoView.setVideoURI(Uri.parse(mVideoPath));
            mVideoView.start();
        }
    });

    mVideoView.start();
}


@Override
public void onPause() {
    super.onPause();
    mVideoView.pause();
}

@Override
public void onResume() {
    super.onResume();
    mVideoView.setVideoURI(Uri.parse(mVideoPath));
    mVideoView.start();
}

Upvotes: 2

k2s
k2s

Reputation: 750

I am having the same problem. Works on other devices, but not on Galaxy S4.

Is there some known solution for this problem.

My current workaround is to call setVideoPath() in onCompletion() which doesn't seams to be right for me.

Upvotes: 0

Related Questions