Skip to content

Instantly share code, notes, and snippets.

@gvr23
Last active December 28, 2017 17:48
Show Gist options
  • Save gvr23/eefea43acc6b363d7626daf814c695ac to your computer and use it in GitHub Desktop.
Save gvr23/eefea43acc6b363d7626daf814c695ac to your computer and use it in GitHub Desktop.
play a video without showing you and error if its longer than usual
ANDROID
===============================================================================================================================
protected void playVideo(String videoPath, VideoView vv){
try{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
vv.setVideoPath(videoPath);
vv.start();
vv.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
try {
mp.reset();
mp.setDataSource(Constantes.VIDEO_PROMOCION);
mp.prepare();
mp.start();
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
});
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
}catch(Exception e){
e.printStackTrace();
Toast.makeText(getApplicationContext() ,"No se cargo el video", Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment