SlideShare a Scribd company logo
Video Streaming 
from the native Android player 
to uncoventional devices 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Open Reply & Android Lab 
• Reply is today a leading IT Services Company 
• Operates in Italy, Germany, UK, Benelux, USA and Brasil. 
• Open Reply is the company of Reply Group focused on open source software, 
multichannel web solutions and mobile applications. 
• Based in Rome, Open Reply’s Android Lab is a young team of over 20 engineers 100% 
focused on Android development. 
• We are specialised in broadcasting, banking and Android OS Customisation. 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Presentation Millestones 
• Playing a content on your handheld device. 
• Entertaiment tailored for the user with 
• Easiest way to enjoy online video and music on user TV on 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Android multimedia framework 
• Android support for playing several media types from media file stored inside the 
application (raw resources, standalone files) or for OTT streaming. 
• Documentation of the media framework is enough just for simple test case. 
• Underneath MediaPlayer Framework documentation is kind of nightmare (lot of 
events and error are not documented at all). 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Supported type 
HttpLiveStreaming Protocol 3 is supported by Android 4.0. Best implementation is in 
Kitkat. 
Google seems putting all his efforts to support new media type ( SmoothStreaming, 
Dynamic adaptive streaming) 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Playing a video 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
VideoView 
Three different approaches 
Mediaplayer 
& 
SurfaceView 
ExoPlayer
MediaPlayer code example 
android.widget.VideoView 
//1. Find the view from the layout 
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview); 
//2. Setup video url 
myVideoView.setVideoURI(Uri.parse(SrcPath)); 
//3. Setup Video controller 
myVideoView.setMediaController(new MediaController(this)); 
//4. Start playing 
myVideoView.requestFocus(); 
myVideoView.start(); 
Programmer doesn’t directly 
handle the MediaPlayer 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
MediaPlayer code example 
android.media.Mediaplayer 
//0. Get SurfaceView and its holder 
mPreview = (SurfaceView)findViewById(R.id.surfaceView); 
holder = mPreview.getHolder(); 
//1. Create MediaPlayer object: 
mp = new MediaPlayer(); 
//2. Add SurfaceHolder callback - Aware when SurfaceView is created 
holder.addCallback(new SurfaceHolder.Callback(){ .... 
@Override 
public void surfaceCreated(SurfaceHolder holder) { 
android.view.SurfaceView 
//3. Attach the surface to the player 
mp.setDisplay(holder); 
try { 
mp.setDataSource(filepath); 
//4. Prepare the Mediaplayer in sync or async mode ( prepareAsync() ) 
mp.prepare(); 
} catch (Exception e) {// Catch the exception} 
//5. Start the player 
mp.start(); 
}... 
}); 
& 
Application creates SurfaceView and MediaPlayer. 
More control on MediaPlayer state 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
MediaPlayer code example 
// 1. Instantiate the player. 
player = ExoPlayer.Factory.newInstance(RENDERER_COUNT); 
// 2. Construct renderers. 
ExoPlayer 
MediaCodecVideoTrackRenderer videoRenderer = … 
MediaCodecAudioTrackRenderer audioRenderer = ... 
// 3. Inject the renderers through prepare. 
player.prepare(videoRenderer, audioRenderer); 
// 4. Pass the surface to the video renderer. 
player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface); 
// 5. Start playback. 
player.setPlayWhenReady(true); 
... 
player.release(); // Release when everything is done! 
Pre-built player that can be extend. 
Implement features not currently 
supported in the normal mediaplayer. 
Droidcon London – 2014 – Matteo Bonifazi e Alessandro Martellucci
What kind of Mediaplayer exist? 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
• Built-in players 
ü AwesomePlayer (default player selected) 
ü NuPlayer (Apple HLS) 
• Extra player factories can be registered 
• DIY mediaplayer 
ü Demuxing: android.media.mediaExtractor 
ü Decoding: android.media.MediaCodec 
ü Video rendering: android.media.MediaCodec 
ü Audio rendering: android.media.AudioTrack 
ü Implement the interface frameworks/av/include/media/MediaPlayerInterface.h
Android TV 
Entertainment tailored for you 
Source:h)p://www.televisedrevolu4on.com/ 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Nexus Player 
Source:h)p://www.televisedrevolu4on.com/ 
Asus device – 235 g 
1.8GHz Quad Core, Intel® Atom™ 
Imagination PowerVR Series 6 
Graphics 2D/3D Engine 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
1GB RAM 
8GB storage
Android TV app 
features 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
• Android 
TV 
devices 
have 
Android 
Lollipop 
5.0 
on 
board. 
• Android 
TV 
has 
inside 
the 
same 
Android 
mul4media 
framework 
of 
normal 
devices. 
• Android 
TV 
app 
can 
be 
built 
on 
API 
17 
towards. 
• Based 
on 
Leanback 
Android 
Support 
library
10 feet experience 
Smartphone 5” 
320 dp 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
TV Full HD 30” 
320 dpi 
10 feet 
16 inches
Manifest features 
Support landscape 
Portrait activity are forbidden 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Manifest features 
No touch screen 
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/> 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Manifest features 
Limit sensor 
<uses-feature android:name="android.hardware.sensor.accelerometer” 
android:required="false" /> 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Keep calm and lean back!! 
Provides built-in tailored for 10 feet experience 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Leanback support library 
<uses-feature android:name="android.software.leanback" 
android:required="true" /> 
<application 
android:allowBackup="false” 
android:label="@string/app_name” 
android:theme="@style/Theme.Leanback" > 
<activity 
android:name="MainActivity” 
android:screenOrientation="landscape" > 
<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LEANBACK_LAUNCHER" /> 
</intent-filter> 
</activity> 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Leanback support library 
Model View Presenter 
Model 
Presenter 
View 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Leanback UI component 
BroswerFragment 
allows the developer “to create a primary layout for browsing categories and rows of 
media items [with a minimum of code]” 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Leanback UI component 
DetailFragment 
Display information about the content that the user has selected 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Chromecast 
a cast-ready device for multi-screen experience 
source: www.google.it 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Chromecast 
hardware specifications 
source: www.pcworld.com 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Chromecast 
components 
• Google Cast technology 
• Multi-Screen experiece 
• Google Cast SDK 
• Sender Application 
• Android app 
• iOS app 
• Chrome app 
• Receiver Application 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
• Default Media Receiver 
• Styled Media Receiver 
• Custom Media Receiver
Android Client Application 
library dependencies 
• Minimum SDK version supported by Google Cast is 9 (Gingerbread) 
• MediaRouter API of android-support-v7 
• Google Play Services 
• AppCompat API of android-support-v7 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Android Client Application 
typical sender application flow 
• Sender app starts MediaRouter device discovery: MediaRouter.addCallback 
• MediaRouter informs sender app of the route the user selected: MediaRouter.Callback.onRouteSelected 
• Sender app retrieves CastDevice instance: CastDevice.getFromBundle 
• Sender app creates and uses GoogleApiClient: GoogleApiClient.Builder 
source: developers.google.com 
• Sender app launches the receiver app: Cast.CastApi.launchApplication 
• Sender app creates a communication channel: Cast.CastApi.setMessageReceivedCallbacks 
• Sender sends a message to the receiver over the communication channel: Cast.CastApi.sendMessage 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Cast-Ready Device Discovery 
capabilities 
Remote 
Playback 
Live 
Audio 
Live 
Video 
MediaRouteSelector.Builder mediaRouteSelectorBuilder = new MediaRouteSelector.Builder(); 
mediaRouteSelectorBuilder.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); 
mediaRouteSelectorBuilder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO); 
mediaRouteSelectorBuilder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO); 
MediaRouterSelector mediaRouterSelector = mediaRouterSelectorBuilder.build(); 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Media Cast Button 
easy approach for discovering 
source: developers.google.com source: developers.google.com 
public boolean onCreateOptionsMenu(Menu menu) { 
MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item); 
MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) 
MenuItemCompat.getActionProvider(mediaRouteMenuItem); 
mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector); …. } 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Receiver Application 
what a mistery? 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
What is? 
HTML5 and Javascript application 
What does it do? 
Display the media content on TV 
Message handling 
Which type? 
Default 
Media 
Receiver 
Styled 
Media 
Receiver 
Custom 
Media 
Receiver
Default Media Receiver 
simplest 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
• Off-the-shelf 
• No UI customization 
• No registration 
Source: developers.google.com
Styled Media Receiver 
simple and customizable 
• Similar to Default Media Player 
• CSS UI customization 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
• Registration 
Source: developers.google.com
Custom Media Receiver (1/3) 
whatever you want 
• Fully Web Applicaiton 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
• Debug(able) at 9222 
• Registration 
Source: developers.google.com
Custom Media Receiver (2/3) 
example 
<html> 
<head> 
<title>Example minimum receiver</title> 
<script src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script> 
</head> 
<body> 
<video id='media'/> 
<script> 
window.mediaElement = document.getElementById('media'); 
window.mediaManager = new cast.receiver.MediaManager(window.mediaElement); 
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance(); 
window.castReceiverManager.start(); 
</script> 
</body> 
</html> 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Custom Media Receiver (3/3) 
advanced features 
• Video Codification/Decodification 
• H.264 High Profile Level 4.1, 4.2 and 5 
• VP8 
• Adaptive Bitrate Streaming 
• HTTP Live Streaming (HLS) 
• Dynamic Adaptive Streaming over HTTP (MPEG-DASH) 
• Smooth Streaming 
• Digital Rights Management 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
• Play Ready DRM 
• Widevine DRM 
• Media Player Library
Channel, Namespace and Protocol (1/2) 
communication 
• Protocol: a set of well-known messages 
• Namespace: a labeled protocol 
• Channel: the communication layer 
class CustomChannel implements Cast.MessageReceivedCallback { 
public String getNamespace() { return “urn:x-cast:com.channel.custom”; } 
@Override 
public void onMessageReceiver(CastDevice castDevice, String namespace, String message) { … } 
} 
… 
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mCustomChannel.getNamespace(), 
mCustomChannel); 
… 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Channel, Namespace and Protocol (2/2) 
communication 
• Media Namespace: urn:x-cast:com.google.media.cast 
• RemoteMediaPlayer 
• MediaManager 
RECEIVER MEDIA CHANNEL 
window.mediaManager = new cast.receiver.MediaManager(window.mediaElement); 
… 
CLIENT MEDIA CHANNEL 
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, 
mRemoteMediaPlayer.getNamespace(), mCustomChannel); 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 
…
Google Api Client and Media Route Provider 
manufacturing 
Source: developers.google.com 
CastDevice selectedCastDevice = CastDevice.getFromBundle(selectedRouteInfo.getExtras); 
Cast.CastOptions.Builder apiOptionsBuilder = new Cast.CastOptions.Builder(selectedCastDevice, …); 
googleApiClient = new GoogleApiClient.Builder().addApi(Cast.API, apiOptionsBuilder.build()).build(); 
googleApiClient.connect(); 
Cast.CastApi.launchApplication(googleApiClient, applicationId, launchOptions); 
Cast.CastApi.joinApplication(googleApiClient); 
Cast.CastApi.stopApplication(googleApiClient); 
Cast.CastApi.leaveApplication(googleApiClient); 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
RemoteMediaPlayer 
…finally 
MediaInfo mediaInfo = new MediaInfo.Builder("http://your.server.com/video.mp4") 
.setContentType("video/mp4") 
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) 
.setMetadata(mediaMetadata) 
.build(); 
… 
mRemoteMediaPlayer = new RemoteMediaPlayer(); 
mRemoteMediaPlayer.load(mApiClient, mediaInfo, true); 
… 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Enjoy the video 
Source: www.huffingtonpost.ca 
Thank you to all of you 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Resources 
• Android Mediaplayer-> http://developer.android.com/guide/topics/media/mediaplayer.html 
• ExoPlayer -> https://github.com/google/ExoPlayer 
• Google Cast -> https://developers.google.com/cast 
• Chromecast App -> http://www.google.it/chrome/devices/chromecast/apps.html 
• Google Cast Downloads -> https://developers.google.com/cast/docs/downloads 
• Github -> https://github.com/googlecast 
• Android TV -> https://developer.android.com/tv 
• Nvidia Guideline -> https://developer.nvidia.com/android-tv-developer-guide 
• Github -> https://github.com/googlesamples/androidtv-Leanback.git 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
Contacts 
+MatteoBonifazi 
m.bonifazi[at]reply.it 
@mbonifazi 
+AlessandroMartellucci 
a.martellucci[at]reply.it 
@martellux 
http://www.reply.eu http://www.gaiareply.com 
Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci

More Related Content

PDF
Enlarge your screen: introducing the Google TV
PDF
The unconventional devices for the Android video streaming
PDF
The unconventional devices for the video streaming in Android
PDF
Video Streaming: from the native Android player to unconventional devices
PPTX
[Ultracode Munich Meetup #7] Building Apps for Nexus Player & Android TV
PDF
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
PDF
Droidcon2013 miracast final2
PDF
Deep Inside Android Hacks
Enlarge your screen: introducing the Google TV
The unconventional devices for the Android video streaming
The unconventional devices for the video streaming in Android
Video Streaming: from the native Android player to unconventional devices
[Ultracode Munich Meetup #7] Building Apps for Nexus Player & Android TV
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
Droidcon2013 miracast final2
Deep Inside Android Hacks

What's hot (20)

PDF
ExoPlayer for Application developers
ODP
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
PPT
Rubato Introduction
PDF
Using the Presentation API and external screens on Android
PDF
YouTube APIs presentation at Facultad de Ciencias, Universidad Nacional Autón...
KEY
Flash Builder and Flex Future - Multiscreen Development
PDF
Building Video Applications with YouTube APIs
PDF
Android App Development Intro at ESC SV 2012
PDF
YouTube APIs Workshop
PDF
Introduction of oesf education consortium
PPT
Android Application Development Basic
PDF
Getting Android Developers for Your Wearables
PPTX
Appcelerator Titanium Intro
DOCX
Lewis brady engine_terminology (edited version)
PPTX
Discovering the p2 API
PDF
Google teams up with ubuntu to bring linux desktop app support to flutter
PDF
Stefano Fornari - Come creare e far crescere un progetto ed una community ope...
PPTX
Android Application WebAPI Development Training
PDF
Cyworld AppStore Overview
PPT
Android Programming Basic
ExoPlayer for Application developers
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Rubato Introduction
Using the Presentation API and external screens on Android
YouTube APIs presentation at Facultad de Ciencias, Universidad Nacional Autón...
Flash Builder and Flex Future - Multiscreen Development
Building Video Applications with YouTube APIs
Android App Development Intro at ESC SV 2012
YouTube APIs Workshop
Introduction of oesf education consortium
Android Application Development Basic
Getting Android Developers for Your Wearables
Appcelerator Titanium Intro
Lewis brady engine_terminology (edited version)
Discovering the p2 API
Google teams up with ubuntu to bring linux desktop app support to flutter
Stefano Fornari - Come creare e far crescere un progetto ed una community ope...
Android Application WebAPI Development Training
Cyworld AppStore Overview
Android Programming Basic
Ad

Viewers also liked (17)

PDF
IT talk #18 Odessa: Alexey Rybakov "Android TV"
PPTX
Video service
PPTX
3D Video Programming for Android
PPTX
Android tv get started
PPTX
CMAF 101 by Cyril Concolato
PPTX
2016 Streaming Media West: Transitioning from Flash to HTML5
PDF
Embedded Android Real-Time Streaming Optimization
PPTX
2016 Streaming Media West: Choosing an HTML5 Player
PDF
Best Practices in Media Playback
PDF
Working with Android TV - English
PDF
Android's Multimedia Framework
PPTX
Android audio system(audioflinger)
PPTX
ABR Algorithms Explained (from Streaming Media East 2016)
PDF
用十分鐘學會 《微積分、工程數學》及其應用
PPTX
The next generation of protocols and APIs that could change streaming video
PDF
Developing Android Apps for TV in Minutes with Amazon Fire App Builder
PDF
Поговорим про Android TV, Алексей Рыбаков, Senior Mobile developer (DataArt)
IT talk #18 Odessa: Alexey Rybakov "Android TV"
Video service
3D Video Programming for Android
Android tv get started
CMAF 101 by Cyril Concolato
2016 Streaming Media West: Transitioning from Flash to HTML5
Embedded Android Real-Time Streaming Optimization
2016 Streaming Media West: Choosing an HTML5 Player
Best Practices in Media Playback
Working with Android TV - English
Android's Multimedia Framework
Android audio system(audioflinger)
ABR Algorithms Explained (from Streaming Media East 2016)
用十分鐘學會 《微積分、工程數學》及其應用
The next generation of protocols and APIs that could change streaming video
Developing Android Apps for TV in Minutes with Amazon Fire App Builder
Поговорим про Android TV, Алексей Рыбаков, Senior Mobile developer (DataArt)
Ad

Similar to Video Streaming: from the native Android player to uncoventional devices (20)

PDF
Cara Terbaik Membangun Aplikasi Android TV dalam Menyongsong Era TV Digital -...
PDF
Multi Streaming Player
PDF
Introduce Android TV and new features from Google I/O 2016
PPTX
Android – As a tool of innovation
PDF
Getting your app on Android TV
PPTX
Angelo Pettazzi - Where is television moving on? Italian experience
PPTX
Google IO 2014 overview
PDF
Creating Rich Multi-Screen Experiences on Android with Amazon Fling - Mario V...
PPT
Android cameraoverview
PDF
Android Evolution, AppForum 2014, Brussels, Friedger Müffke
PDF
JAM316 - Native API Deep Dive: Multimedia Playback & Streaming
PPTX
Android - Application Framework
PDF
Slides bootcamp21
PPTX
OTT for Mobile Devices
PPTX
Smart TV and APIs
PDF
forpress-droidconit2016
PDF
Report Droidcon Italy 2014
PPTX
Second Screen Apps - On Google TV
PPTX
Introduction to Android (before 2015)
PDF
Android : How Do I Code Thee?
Cara Terbaik Membangun Aplikasi Android TV dalam Menyongsong Era TV Digital -...
Multi Streaming Player
Introduce Android TV and new features from Google I/O 2016
Android – As a tool of innovation
Getting your app on Android TV
Angelo Pettazzi - Where is television moving on? Italian experience
Google IO 2014 overview
Creating Rich Multi-Screen Experiences on Android with Amazon Fling - Mario V...
Android cameraoverview
Android Evolution, AppForum 2014, Brussels, Friedger Müffke
JAM316 - Native API Deep Dive: Multimedia Playback & Streaming
Android - Application Framework
Slides bootcamp21
OTT for Mobile Devices
Smart TV and APIs
forpress-droidconit2016
Report Droidcon Italy 2014
Second Screen Apps - On Google TV
Introduction to Android (before 2015)
Android : How Do I Code Thee?

More from Matteo Bonifazi (16)

PDF
Invading the home screen
PDF
Engage user with actions
PDF
Kotlin killed Java stars
PDF
Android JET Navigation
PDF
Firebase-ized your mobile app
PDF
Backendless apps
PDF
Android - Saving data
PDF
Android Networking
PDF
Android - Displaying images
PDF
Android - Background operation
PDF
Android things intro
PDF
The Firebase tier for your mobile app - DevFest CH
PDF
Engage and retain users in the android world - Droidcon Italy 2016
PDF
UaMobitech - App Links and App Indexing API
PDF
Google IO - Five months later
PDF
Enlarge your screen
Invading the home screen
Engage user with actions
Kotlin killed Java stars
Android JET Navigation
Firebase-ized your mobile app
Backendless apps
Android - Saving data
Android Networking
Android - Displaying images
Android - Background operation
Android things intro
The Firebase tier for your mobile app - DevFest CH
Engage and retain users in the android world - Droidcon Italy 2016
UaMobitech - App Links and App Indexing API
Google IO - Five months later
Enlarge your screen

Recently uploaded (6)

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

Video Streaming: from the native Android player to uncoventional devices

  • 1. Video Streaming from the native Android player to uncoventional devices Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 2. Open Reply & Android Lab • Reply is today a leading IT Services Company • Operates in Italy, Germany, UK, Benelux, USA and Brasil. • Open Reply is the company of Reply Group focused on open source software, multichannel web solutions and mobile applications. • Based in Rome, Open Reply’s Android Lab is a young team of over 20 engineers 100% focused on Android development. • We are specialised in broadcasting, banking and Android OS Customisation. Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 3. Presentation Millestones • Playing a content on your handheld device. • Entertaiment tailored for the user with • Easiest way to enjoy online video and music on user TV on Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 4. Android multimedia framework • Android support for playing several media types from media file stored inside the application (raw resources, standalone files) or for OTT streaming. • Documentation of the media framework is enough just for simple test case. • Underneath MediaPlayer Framework documentation is kind of nightmare (lot of events and error are not documented at all). Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 5. Supported type HttpLiveStreaming Protocol 3 is supported by Android 4.0. Best implementation is in Kitkat. Google seems putting all his efforts to support new media type ( SmoothStreaming, Dynamic adaptive streaming) Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 6. Playing a video Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci VideoView Three different approaches Mediaplayer & SurfaceView ExoPlayer
  • 7. MediaPlayer code example android.widget.VideoView //1. Find the view from the layout VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview); //2. Setup video url myVideoView.setVideoURI(Uri.parse(SrcPath)); //3. Setup Video controller myVideoView.setMediaController(new MediaController(this)); //4. Start playing myVideoView.requestFocus(); myVideoView.start(); Programmer doesn’t directly handle the MediaPlayer Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 8. MediaPlayer code example android.media.Mediaplayer //0. Get SurfaceView and its holder mPreview = (SurfaceView)findViewById(R.id.surfaceView); holder = mPreview.getHolder(); //1. Create MediaPlayer object: mp = new MediaPlayer(); //2. Add SurfaceHolder callback - Aware when SurfaceView is created holder.addCallback(new SurfaceHolder.Callback(){ .... @Override public void surfaceCreated(SurfaceHolder holder) { android.view.SurfaceView //3. Attach the surface to the player mp.setDisplay(holder); try { mp.setDataSource(filepath); //4. Prepare the Mediaplayer in sync or async mode ( prepareAsync() ) mp.prepare(); } catch (Exception e) {// Catch the exception} //5. Start the player mp.start(); }... }); & Application creates SurfaceView and MediaPlayer. More control on MediaPlayer state Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 9. MediaPlayer code example // 1. Instantiate the player. player = ExoPlayer.Factory.newInstance(RENDERER_COUNT); // 2. Construct renderers. ExoPlayer MediaCodecVideoTrackRenderer videoRenderer = … MediaCodecAudioTrackRenderer audioRenderer = ... // 3. Inject the renderers through prepare. player.prepare(videoRenderer, audioRenderer); // 4. Pass the surface to the video renderer. player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface); // 5. Start playback. player.setPlayWhenReady(true); ... player.release(); // Release when everything is done! Pre-built player that can be extend. Implement features not currently supported in the normal mediaplayer. Droidcon London – 2014 – Matteo Bonifazi e Alessandro Martellucci
  • 10. What kind of Mediaplayer exist? Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci • Built-in players ü AwesomePlayer (default player selected) ü NuPlayer (Apple HLS) • Extra player factories can be registered • DIY mediaplayer ü Demuxing: android.media.mediaExtractor ü Decoding: android.media.MediaCodec ü Video rendering: android.media.MediaCodec ü Audio rendering: android.media.AudioTrack ü Implement the interface frameworks/av/include/media/MediaPlayerInterface.h
  • 11. Android TV Entertainment tailored for you Source:h)p://www.televisedrevolu4on.com/ Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 12. Nexus Player Source:h)p://www.televisedrevolu4on.com/ Asus device – 235 g 1.8GHz Quad Core, Intel® Atom™ Imagination PowerVR Series 6 Graphics 2D/3D Engine Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci 1GB RAM 8GB storage
  • 13. Android TV app features Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci • Android TV devices have Android Lollipop 5.0 on board. • Android TV has inside the same Android mul4media framework of normal devices. • Android TV app can be built on API 17 towards. • Based on Leanback Android Support library
  • 14. 10 feet experience Smartphone 5” 320 dp Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci TV Full HD 30” 320 dpi 10 feet 16 inches
  • 15. Manifest features Support landscape Portrait activity are forbidden Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 16. Manifest features No touch screen <uses-feature android:name="android.hardware.touchscreen" android:required="false"/> Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 17. Manifest features Limit sensor <uses-feature android:name="android.hardware.sensor.accelerometer” android:required="false" /> Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 18. Keep calm and lean back!! Provides built-in tailored for 10 feet experience Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 19. Leanback support library <uses-feature android:name="android.software.leanback" android:required="true" /> <application android:allowBackup="false” android:label="@string/app_name” android:theme="@style/Theme.Leanback" > <activity android:name="MainActivity” android:screenOrientation="landscape" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> </intent-filter> </activity> Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 20. Leanback support library Model View Presenter Model Presenter View Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 21. Leanback UI component BroswerFragment allows the developer “to create a primary layout for browsing categories and rows of media items [with a minimum of code]” Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 22. Leanback UI component DetailFragment Display information about the content that the user has selected Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 23. Chromecast a cast-ready device for multi-screen experience source: www.google.it Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 24. Chromecast hardware specifications source: www.pcworld.com Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 25. Chromecast components • Google Cast technology • Multi-Screen experiece • Google Cast SDK • Sender Application • Android app • iOS app • Chrome app • Receiver Application Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci • Default Media Receiver • Styled Media Receiver • Custom Media Receiver
  • 26. Android Client Application library dependencies • Minimum SDK version supported by Google Cast is 9 (Gingerbread) • MediaRouter API of android-support-v7 • Google Play Services • AppCompat API of android-support-v7 Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 27. Android Client Application typical sender application flow • Sender app starts MediaRouter device discovery: MediaRouter.addCallback • MediaRouter informs sender app of the route the user selected: MediaRouter.Callback.onRouteSelected • Sender app retrieves CastDevice instance: CastDevice.getFromBundle • Sender app creates and uses GoogleApiClient: GoogleApiClient.Builder source: developers.google.com • Sender app launches the receiver app: Cast.CastApi.launchApplication • Sender app creates a communication channel: Cast.CastApi.setMessageReceivedCallbacks • Sender sends a message to the receiver over the communication channel: Cast.CastApi.sendMessage Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 28. Cast-Ready Device Discovery capabilities Remote Playback Live Audio Live Video MediaRouteSelector.Builder mediaRouteSelectorBuilder = new MediaRouteSelector.Builder(); mediaRouteSelectorBuilder.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); mediaRouteSelectorBuilder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO); mediaRouteSelectorBuilder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO); MediaRouterSelector mediaRouterSelector = mediaRouterSelectorBuilder.build(); Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 29. Media Cast Button easy approach for discovering source: developers.google.com source: developers.google.com public boolean onCreateOptionsMenu(Menu menu) { MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item); MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem); mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector); …. } Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 30. Receiver Application what a mistery? Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci What is? HTML5 and Javascript application What does it do? Display the media content on TV Message handling Which type? Default Media Receiver Styled Media Receiver Custom Media Receiver
  • 31. Default Media Receiver simplest Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci • Off-the-shelf • No UI customization • No registration Source: developers.google.com
  • 32. Styled Media Receiver simple and customizable • Similar to Default Media Player • CSS UI customization Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci • Registration Source: developers.google.com
  • 33. Custom Media Receiver (1/3) whatever you want • Fully Web Applicaiton Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci • Debug(able) at 9222 • Registration Source: developers.google.com
  • 34. Custom Media Receiver (2/3) example <html> <head> <title>Example minimum receiver</title> <script src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script> </head> <body> <video id='media'/> <script> window.mediaElement = document.getElementById('media'); window.mediaManager = new cast.receiver.MediaManager(window.mediaElement); window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance(); window.castReceiverManager.start(); </script> </body> </html> Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 35. Custom Media Receiver (3/3) advanced features • Video Codification/Decodification • H.264 High Profile Level 4.1, 4.2 and 5 • VP8 • Adaptive Bitrate Streaming • HTTP Live Streaming (HLS) • Dynamic Adaptive Streaming over HTTP (MPEG-DASH) • Smooth Streaming • Digital Rights Management Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci • Play Ready DRM • Widevine DRM • Media Player Library
  • 36. Channel, Namespace and Protocol (1/2) communication • Protocol: a set of well-known messages • Namespace: a labeled protocol • Channel: the communication layer class CustomChannel implements Cast.MessageReceivedCallback { public String getNamespace() { return “urn:x-cast:com.channel.custom”; } @Override public void onMessageReceiver(CastDevice castDevice, String namespace, String message) { … } } … Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mCustomChannel.getNamespace(), mCustomChannel); … Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 37. Channel, Namespace and Protocol (2/2) communication • Media Namespace: urn:x-cast:com.google.media.cast • RemoteMediaPlayer • MediaManager RECEIVER MEDIA CHANNEL window.mediaManager = new cast.receiver.MediaManager(window.mediaElement); … CLIENT MEDIA CHANNEL Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mRemoteMediaPlayer.getNamespace(), mCustomChannel); Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci …
  • 38. Google Api Client and Media Route Provider manufacturing Source: developers.google.com CastDevice selectedCastDevice = CastDevice.getFromBundle(selectedRouteInfo.getExtras); Cast.CastOptions.Builder apiOptionsBuilder = new Cast.CastOptions.Builder(selectedCastDevice, …); googleApiClient = new GoogleApiClient.Builder().addApi(Cast.API, apiOptionsBuilder.build()).build(); googleApiClient.connect(); Cast.CastApi.launchApplication(googleApiClient, applicationId, launchOptions); Cast.CastApi.joinApplication(googleApiClient); Cast.CastApi.stopApplication(googleApiClient); Cast.CastApi.leaveApplication(googleApiClient); Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 39. RemoteMediaPlayer …finally MediaInfo mediaInfo = new MediaInfo.Builder("http://your.server.com/video.mp4") .setContentType("video/mp4") .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setMetadata(mediaMetadata) .build(); … mRemoteMediaPlayer = new RemoteMediaPlayer(); mRemoteMediaPlayer.load(mApiClient, mediaInfo, true); … Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 40. Enjoy the video Source: www.huffingtonpost.ca Thank you to all of you Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 41. Resources • Android Mediaplayer-> http://developer.android.com/guide/topics/media/mediaplayer.html • ExoPlayer -> https://github.com/google/ExoPlayer • Google Cast -> https://developers.google.com/cast • Chromecast App -> http://www.google.it/chrome/devices/chromecast/apps.html • Google Cast Downloads -> https://developers.google.com/cast/docs/downloads • Github -> https://github.com/googlecast • Android TV -> https://developer.android.com/tv • Nvidia Guideline -> https://developer.nvidia.com/android-tv-developer-guide • Github -> https://github.com/googlesamples/androidtv-Leanback.git Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci
  • 42. Contacts +MatteoBonifazi m.bonifazi[at]reply.it @mbonifazi +AlessandroMartellucci a.martellucci[at]reply.it @martellux http://www.reply.eu http://www.gaiareply.com Droidcon London – 2014 – Matteo Bonifazi & Alessandro Martellucci

Editor's Notes

  • #16: android:screenOrientation can’t be portrait, reversePortrait, sensorPortrait, userPortrait or reverseLandscape.
  • #17: No touchescreen– TV control comes with DPAD. TouchScreen must not to be required since Google Play won’t filter.
  • #18: Limit Sensor– Make optional every uses features which are for not crucial operation.
  • #27: Before starting to develop the Android client application is important to have in mind which are the basic requirements. First of all there are few library dependencies and constraints you’ll need to care about. Number one: the minimum SDK version supported by Goole Cast technology is the 9 that is Gingerbread Number two: the Goole Cast client APIs are packaged into the android.support.v7.media package of Android Support Library revision 19 o later Number three: you’ll need to setup the Google Play Services library revision 4.2 or later Number four: you must import the AppCompat which provides basic UI elements like the MediaButton, useful for establish a connection to the Chromecast device
  • #28: Now let me show you what is the typical sender application flow because it’s also important to understand which are the steps the client runs in order to start and control a receiver application. During the development phase you’ll have to interact with several Java objects. So first of all: the sender application uses the MediaRouter object to discover all the cast-device available inside the local WiFi network. through its callback, the MediaRouter informs the sender application which of the available. From the RouteInfo object the sender application extracts the instance of the CastDevice object: the most important object inside the development lifecycle. This is the object which represents the hardware specification of the cast-ready device Once the sender application knows the cast device the user selected it makes use of Google Play Services APIs in order to launch the receiver application and to establish a communication channel where several messages are exhanged Only at the end of these steps you’ll be able to play any kind of content using the RemoteMediaPlayer object
  • #29: Now I would like to give you more details about the discovery phase. It’s important because, inside the same local WiFi network, many cast-ready devices could be connected, everyone with different capabilities. So the sender app must make a choice in order to select the capailities it needs for. The Google Cast SDK provides three main categories that the Chromecast is able to manage: REMOTE PLAYBACK LIVE AUDIO LIVE VIDEO REMOTE PLAYBACK category idendifies all the routes which present a remote media by playing content from URI. These routes take the responsability for fetching and rendering content on their own. The application doesn’t display any content on the screen of the device. Different are the cases of the LIVE AUDIO and LIVE VIDEO where the routes support live audio and live video streaming respectively from device to the destination. Theses routes are the easiest to use because the application renders the content locally on the screen of the device and the system streams it automatically to the destination. A destination that could be a local display or wireless display with support for mirroring or Android presentation. Further, in this slide you can see how it’s easy to set the requested capabilities for the Android client application, using the MediaRouteSelector object.
  • #31: On the other side we have the receiver application. What a mistery? What a mistery just because I’ve experienced a lot of questions and curiosity from many collegues of mine. They couldn’t imagine what the receiver application is and how it works. I realized it was often confusing and frustrating for Android developers to find out that the receiver application is just an HTML5 and Javascript web application. Exactly. Inside the Chromecast device what’s running is a custom version of Chrome web browser. This decision is the reason why the Chromecast became a successful product. Having a widespread and consolidated technology like Chrome web browser playing the role of the media player allowed the many developers to solve most of the known problem about video streaming and to mantain client and server technology respectively decoupled. So what does it do? First of all it displays the media content on the TV and further it provides an handler for the management of the messages exchanged between the client application and the recevier device. As we’ll see later there is a strong presence of messages flow starting from the client towards the receiver and vice versa. If you’ll start develpoing a Chromecast application you would choose one of the three available media receiver: a default media receiver, a styled media receiver and finally a custom media receiver. The Chromecast Receiver API provides different solutions based on what are your needs. And now i’m showing you them.
  • #32: The default media receiver is the simplest and easy to use. It’s a prebuilt reciever application, hosted into the Google Cloud Factory, and it’s designed for the streaming of audio and video contents. It doesn’t provide any UI customization as Styled and Custom one permits and further it doesn’t require any kind of registration as Styled and Custom needs to.
  • #33: The Styled Media Receiver, instead, represents the right choice if you need a ready-made application receiver for media playing with the possibility to customise some little UI elements. By publishing a simple CSS file, with specific CSS class names, it’s possible change the logo image, the progress bar logo, the title style and so no. Differenty from the previous Media Receiver, the default one, the styled media receiver requires the user to register the receiver application by simply fullfil a web form. This registration calls for a name and a URL referring to host where the CSS file is remoted.