Skip to content

Instantly share code, notes, and snippets.

@gdakram
Created May 23, 2014 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdakram/48c8a799da0b411af7f8 to your computer and use it in GitHub Desktop.
Save gdakram/48c8a799da0b411af7f8 to your computer and use it in GitHub Desktop.
media player with surface view example that scales with cropping
final SurfaceView sv = (SurfaceView) findViewById(R.id.splash_surface);
MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onPrepared(MediaPlayer mp) {
mp.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
mp.setDisplay(sv.getHolder());
mp.start();
}
});
try {
AssetFileDescriptor afd = getResources().openRawResourceFd(UiUtil.isTablet(MainActivity.this) ? R.raw.splash_td_tablet : R.raw.splash_td_phone);
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment