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

What's hot (20)

PDF
Getting started with open source game playing AIs
Melvin Zhang
 
TXT
Tic tac toe
jo pakson
 
PPTX
Cookies
amuthadeepa
 
PPTX
Nvvp streams-3
Josh Wyatt
 
PPTX
Cookie and session
Aashish Ghale
 
ODP
Od DV kazete do DVD-a
StarFox83
 
PDF
The JSON Architecture - BucharestJS / July
Constantin Dumitrescu
 
PPT
3-in-1 YSlow
Stoyan Stefanov
 
PPTX
자바스터디 4
jangpd007
 
KEY
Fluent plugin-dstat
shunsuke Mikami
 
KEY
About memcached
ChangQi Lin
 
DOCX
Python
HungTrinh69
 
PDF
Can you hear me now?
Ida Aalen
 
PPT
Nodejs quick start
Guangyao Cao
 
PPTX
Web sockets
bodokaiser
 
DOCX
Proxy server ubuntu 12.04
Tio Aldiansyah
 
PPT
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
PDF
大勢でピンポンできるのは、だれ?
Sachirou Inoue
 
PPTX
Tying it all together in real time - Connect.JS / Ti.Connect
joshcjensen
 
Getting started with open source game playing AIs
Melvin Zhang
 
Tic tac toe
jo pakson
 
Cookies
amuthadeepa
 
Nvvp streams-3
Josh Wyatt
 
Cookie and session
Aashish Ghale
 
Od DV kazete do DVD-a
StarFox83
 
The JSON Architecture - BucharestJS / July
Constantin Dumitrescu
 
3-in-1 YSlow
Stoyan Stefanov
 
자바스터디 4
jangpd007
 
Fluent plugin-dstat
shunsuke Mikami
 
About memcached
ChangQi Lin
 
Python
HungTrinh69
 
Can you hear me now?
Ida Aalen
 
Nodejs quick start
Guangyao Cao
 
Web sockets
bodokaiser
 
Proxy server ubuntu 12.04
Tio Aldiansyah
 
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
大勢でピンポンできるのは、だれ?
Sachirou Inoue
 
Tying it all together in real time - Connect.JS / Ti.Connect
joshcjensen
 

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

PDF
How to-save-video-list
phanhung20
 
PDF
Non stop random2b
phanhung20
 
PDF
20141030 html5j-firefox os-deviceapi
Noritada Shimizu
 
PDF
HTML5 Multimedia Accessibility
brucelawson
 
PDF
Craft 2019 - “The Upside Down” Of The Web - Video technologies
Máté Nádasdi
 
PPTX
Video service
doyley_2000
 
PDF
watchOS 2でゲーム作ってみた話
Kohki Miki
 
PDF
Browsers with Wings
Remy Sharp
 
PDF
Multimedia on the web - HTML5 video and audio
Christian Heilmann
 
PDF
Building Video Applications with YouTube APIs
Jarek Wilkiewicz
 
PDF
Google's HTML5 Work: what's next?
Patrick Chanezon
 
PDF
WebRTC Standards & Implementation Q&A - All about browser interoperability
Amir Zmora
 
PDF
Fii Practic Frontend - BeeNear - laborator 4
BeeNear
 
PPTX
Playing Video with ExoPlayer : Android Bangkok 2018
Minseo Chayabanjonglerd
 
PDF
Pebble Watch iOS SDK Overview
Matthew Morey
 
PPTX
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
Amitesh Madhur
 
PDF
HTML5: where flash isn't needed anymore
Remy Sharp
 
PDF
HTML5 multimedia - where we are, where we're going
brucelawson
 
KEY
Web Apps
Tim Wray
 
PDF
Html5 Open Video Tutorial
Silvia Pfeiffer
 
How to-save-video-list
phanhung20
 
Non stop random2b
phanhung20
 
20141030 html5j-firefox os-deviceapi
Noritada Shimizu
 
HTML5 Multimedia Accessibility
brucelawson
 
Craft 2019 - “The Upside Down” Of The Web - Video technologies
Máté Nádasdi
 
Video service
doyley_2000
 
watchOS 2でゲーム作ってみた話
Kohki Miki
 
Browsers with Wings
Remy Sharp
 
Multimedia on the web - HTML5 video and audio
Christian Heilmann
 
Building Video Applications with YouTube APIs
Jarek Wilkiewicz
 
Google's HTML5 Work: what's next?
Patrick Chanezon
 
WebRTC Standards & Implementation Q&A - All about browser interoperability
Amir Zmora
 
Fii Practic Frontend - BeeNear - laborator 4
BeeNear
 
Playing Video with ExoPlayer : Android Bangkok 2018
Minseo Chayabanjonglerd
 
Pebble Watch iOS SDK Overview
Matthew Morey
 
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
Amitesh Madhur
 
HTML5: where flash isn't needed anymore
Remy Sharp
 
HTML5 multimedia - where we are, where we're going
brucelawson
 
Web Apps
Tim Wray
 
Html5 Open Video Tutorial
Silvia Pfeiffer
 
Ad

Recently uploaded (8)

PPTX
The Intersection of Emoji and NFT. What can be the Consequences?
Refit Global
 
PDF
Building Smart, Scalable Solutions with Android App Development
Brancosoft Private Limited
 
PPT
lect 1 Introduction.ppt11112222333344455
212231
 
PPT
lec2 wireless transmission exlaining.ppt
212231
 
PPTX
Mobile Apps Helping Business Grow in 2025
Infylo Techsolutions
 
PDF
💡 Digital Marketing Decoded: Mastering Online Growth Strategies for 2025 🚀
marketingaura24
 
PDF
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
PDF
INTERLINGUAL SYNTACTIC PARSING: AN OPTIMIZED HEAD-DRIVEN PARSING FOR ENGLISH ...
kevig
 
The Intersection of Emoji and NFT. What can be the Consequences?
Refit Global
 
Building Smart, Scalable Solutions with Android App Development
Brancosoft Private Limited
 
lect 1 Introduction.ppt11112222333344455
212231
 
lec2 wireless transmission exlaining.ppt
212231
 
Mobile Apps Helping Business Grow in 2025
Infylo Techsolutions
 
💡 Digital Marketing Decoded: Mastering Online Growth Strategies for 2025 🚀
marketingaura24
 
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
INTERLINGUAL SYNTACTIC PARSING: AN OPTIMIZED HEAD-DRIVEN PARSING FOR ENGLISH ...
kevig
 
Ad

Videos on Android - Stuff What I Learned