Dr.Mezo
Dr.Mezo

Reputation: 869

Video Loop when it comes to the end

How to make the video to loop seamlessly as of now when it comes to an end of the clip and starts the clip again

`public class TvPlay extends Activity implements OnCompletionListener, OnErrorListener, OnPreparedListener {

    private VideoView mVideoView;
    private String url;
    private ProgressBar load;
    private TextView empty;
    private AdView mAdView;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);

// Vitamio.isInitialized(this); Vitamio.isInitialized(getApplicationContext());

                this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
                setContentView(R.layout.tvplay);
                mAdView = (AdView) findViewById(R.id.adView);
                mAdView.loadAd(new AdRequest.Builder().build());
                Log.d("url=", getIntent().getStringExtra("url"));
                url = getIntent().getStringExtra("url");
                init();

            }

    public void init() {
        load = (ProgressBar) this.findViewById(R.id.load);
        empty = (TextView) this.findViewById(R.id.empty);
        mVideoView = (VideoView) this.findViewById(R.id.surface_view);
        mVideoView.setOnCompletionListener(this);
        mVideoView.setOnPreparedListener(this);
        mVideoView.setOnErrorListener(this);
        Uri videoUri = Uri.parse(url);
        mVideoView.setVideoURI(videoUri);
        mVideoView.requestFocus();
        loading();
    }

    private void loading() {
        load.setVisibility(View.GONE);
        empty.setVisibility(View.GONE);
    }

    private void loadComplete(MediaPlayer arg0) {
        load.setVisibility(View.GONE);
        // vv.setVisibility(View.VISIBLE);
        empty.setVisibility(View.GONE);
        mVideoView.start();
        mVideoView.resume();
    }

    private void error(String msg) {
        load.setVisibility(View.GONE);
        mVideoView.setVisibility(View.GONE);
        empty.setVisibility(View.VISIBLE);
        if (msg != null)
            empty.setText(msg);
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        // TODO Auto-generated method stub
        Log.d("ONLINE TV", "Prepared");
        loadComplete(mp);
    }

    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        // TODO Auto-generated method stub
        Log.d("ONLINE TV", "Error");
        error("Unable to play this channel.");
        return false;
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        // TODO Auto-generated method stub
        Log.d("ONLINE TV", "Complete");
    }
}

`

Upvotes: 0

Views: 97

Answers (1)

steevoo
steevoo

Reputation: 631

this will make your video keep playing

 mVideoView.setOnPreparedListener(new OnPreparedListener() {

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

Upvotes: 0

Related Questions