SlideShare a Scribd company logo
Videos on Android
Stuff What I Learned
Videos on Android - Stuff What I Learned
Videos on Android - Stuff What I Learned
In the beginning…
>200Videos
1080p H.264
~10MB
2GB
50MB-100MB / routine
0.5TB/month
Videos on Android - Stuff What I Learned
1GB/month
10MB → <1MB
Videos on Android - Stuff What I Learned
1GB/month → <10MB total
{
"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"
}
}
Let’s Code!
Both.
I hate this device. It’s great!
developer.android.com/guide/appendix/media-formats.html
Videos on Android - Stuff What I Learned
Video ViewSurfaceView
MediaPlayer
start()
pause()
seekTo()
getDuration()
setVideoURI()
setVideoPath()
setOnPreparedListener()
setOnCompletionListener()
vv.
vv.
vv.
vv.
vv.
vv.
vv.
vv.
VideoView vv = (VideoView) findViewById(R.id.videoView);	
vv.setVideoPath(path);	
!
vv.setOnPreparedListener (new OnPreparedListener() { 	
@Override	
public void onPrepared(MediaPlayer mp) {	
mp.setLooping(true);	
}	
});	
!
vv.start();
Videos on Android - Stuff What I Learned
Videos on Android - Stuff What I Learned
Disclaimer:This isn’t meant to happen.
–Android API Docs
“SurfaceView punches a hole in its window	

to allow its surface to be displayed.”
TextureView
• Android 4.0	

• Behaves as a regular view	

• OpenGL,Video etc
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)
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();	
}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceT) {	
	 	 mediaPlayer.release();	
	 	 return true;	
}
Videos on Android - Stuff What I Learned
Hey Mark, what aboutYouTube?
YouTubePlayer
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);	
}
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);	
}
Playing Audio?
!
setVolumeControlStream(AudioManager.STREAM_MUSIC);
Y U NO USE INTENT?!
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
Fin.
@mhemmings

More Related Content

PPTX
Php Basics part 1
TXT
Free youtubetomp3converter log
PDF
Memory Management in WordPress
PDF
Solaris 11 base box for Vagrant using Packer
PDF
Odata introduction-slides
PPTX
PHP Cookies and Sessions
PPT
Php ssession - cookies -introduction
DOCX
Laporan Praktikum 1 dev c++
Php Basics part 1
Free youtubetomp3converter log
Memory Management in WordPress
Solaris 11 base box for Vagrant using Packer
Odata introduction-slides
PHP Cookies and Sessions
Php ssession - cookies -introduction
Laporan Praktikum 1 dev c++

What's hot (20)

PDF
Getting started with open source game playing AIs
TXT
Tic tac toe
PPTX
Cookies
PPTX
Nvvp streams-3
PPTX
Cookie and session
ODP
Od DV kazete do DVD-a
PDF
The JSON Architecture - BucharestJS / July
PPT
3-in-1 YSlow
PPTX
자바스터디 4
KEY
Fluent plugin-dstat
KEY
About memcached
DOCX
Python
PDF
Can you hear me now?
PPT
Nodejs quick start
PPTX
Web sockets
DOCX
Proxy server ubuntu 12.04
PPT
PHP - Introduction to PHP Cookies and Sessions
PDF
大勢でピンポンできるのは、だれ?
PPTX
Tying it all together in real time - Connect.JS / Ti.Connect
Getting started with open source game playing AIs
Tic tac toe
Cookies
Nvvp streams-3
Cookie and session
Od DV kazete do DVD-a
The JSON Architecture - BucharestJS / July
3-in-1 YSlow
자바스터디 4
Fluent plugin-dstat
About memcached
Python
Can you hear me now?
Nodejs quick start
Web sockets
Proxy server ubuntu 12.04
PHP - Introduction to PHP Cookies and Sessions
大勢でピンポンできるのは、だれ?
Tying it all together in real time - Connect.JS / Ti.Connect
Ad

Similar to Videos on Android - Stuff What I Learned (20)

PDF
The unconventional devices for the Android video streaming
PDF
The unconventional devices for the video streaming in Android
PDF
IMPLEMENTING VOICE CONTROL WITH THE ANDROID MEDIA SESSION API ON AMAZON FIRE ...
PDF
Multi Streaming Player
KEY
Gtug
PDF
Android 3.0 Portland Java User Group 2011-03-15
PPT
Android Media Player Development
PDF
Android Multimedia Support
PDF
Android 3.1 - Portland Code Camp 2011
PPTX
Video service
PDF
Android Workshop 2013
KEY
HTML5 Video Presentation
PPTX
Android Training (Media)
DOCX
Android media-chapter 23
PDF
Android - Open Source Bridge 2011
PDF
Craft 2019 - “The Upside Down” Of The Web - Video technologies
PDF
What is so cool about Android 4.0
KEY
Android workshop
PPTX
Playing Video with ExoPlayer : Android Bangkok 2018
PDF
First meet with Android Auto
The unconventional devices for the Android video streaming
The unconventional devices for the video streaming in Android
IMPLEMENTING VOICE CONTROL WITH THE ANDROID MEDIA SESSION API ON AMAZON FIRE ...
Multi Streaming Player
Gtug
Android 3.0 Portland Java User Group 2011-03-15
Android Media Player Development
Android Multimedia Support
Android 3.1 - Portland Code Camp 2011
Video service
Android Workshop 2013
HTML5 Video Presentation
Android Training (Media)
Android media-chapter 23
Android - Open Source Bridge 2011
Craft 2019 - “The Upside Down” Of The Web - Video technologies
What is so cool about Android 4.0
Android workshop
Playing Video with ExoPlayer : Android Bangkok 2018
First meet with Android Auto
Ad

Recently uploaded (6)

PDF
heheheueueyeyeyegehehehhehshMedia-Literacy.pdf
DOC
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
PDF
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
DOC
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
PPTX
ASMS Telecommunication company Profile
PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
heheheueueyeyeyegehehehhehshMedia-Literacy.pdf
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
ASMS Telecommunication company Profile
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf

Videos on Android - Stuff What I Learned