Last active
December 28, 2017 17:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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