The document discusses various techniques for playing video on Android, including:
- Using VideoView for versions below Android 4.0 and TextureView for 4.0 and above
- Implementing callbacks like onPreparedListener and onCompletionListener to control media playback
- Retrieving video frames using MediaMetadataRetriever for previewing or loading screens
- Integrating with the native YouTube player
- Controlling audio playback and volume
- Caching video for improved performance
16. {
"id": 117,
"name": "Hamstring Hanging Stretch",
"description": "Position yourself lying on your front on a flat, raised
surface. Allow the lower part of your leg to hang off the edge. Let the weight
of your foot straighten your knee.",
"sets": 3,
"reps": 8,
"hold_duration": 10,
"rest": 30,
"created": "2013-12-02 22:03:21",
"modified": "2013-12-23 16:59:02",
"video": {
"id": 132,
"url": "/ddaf3d7d59b4dd09fae6d34e760236d9/320p-16to9.mp4",
"hold_time_seconds": 4.3,
"loop_time_start_seconds": 0,
"loop_time_end_seconds": 0,
"etag": "b38f39cebe21487dd2ed123d16065d7b"
}
}
29. implement TextureView.SurfaceTextureListener
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
!
!
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface)
!
!
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)
!
!
public void onSurfaceTextureUpdated(SurfaceTexture surface)
30. public void onSurfaceTextureAvailable(SurfaceTexture surfaceT, int width, int height) {
Surface surface = new Surface(surfaceT);
try {
mediaPlayer.setDataSource(path);
} catch (Exception e) {
}
!
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.start();
}
});
!
mediaPlayer.setSurface(surface);
!
mediaPlayer.prepareAsync();
}
35. MediaController
• Just a view containing media controls
• Implement all callbacks with setMediaPlayer();
• start(), pause(), seekTo() etc callbacks
• Hook these up to your MediaPlayer:
public void start() {
mediaPlayer.start();
}
!
public void pause() {
mediaPlayer.pause();
}
!
public void seekTo(int i) {
mediaPlayer.seekTo(i);
}
36. MediaMetadataRetriever
• Get a frame as a Bitmap
• Useful when waiting for video to load or when usingVideoView
metadataRetriever.setDataSource(ctx, path);
!
Bitmap bitmap = metadataRetriever.getFrameAtTime(0L, MediaMetadataRetriever.OPTION_CLOSEST);
!
if (bitmap != null) {
BitmapDrawable previewBitmap = new BitmapDrawable(this.getResources(), bitmap);
imageView.setImageDrawable(previewBitmap);
}
39. In Summary
• Think about your content
• “I need shiny 1080p”
• Resolution/user dependent content?
• Be nice, cache (and cache hard) if possible
• Assume nothing and be prepared
• TextureView when 4.0
• VideoView when <4.0
• Test
• Test
• Test
• Test
• Test
• Test