Created
May 23, 2014 06:44
-
-
Save gdakram/48c8a799da0b411af7f8 to your computer and use it in GitHub Desktop.
media player with surface view example that scales with cropping
This file contains hidden or 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
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