Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build a video streaming app

Build a video streaming app

Andrew Jack

October 26, 2015
Tweet

More Decks by Andrew Jack

Other Decks in Programming

Transcript

  1. 6 Streaming video content Progressive streaming • Download file from

    start to finish Streaming network protocols • RTSP - Real Time Streaming Protocol Adaptive Bitrate streaming over HTTP • Smooth Streaming • Adobe HTTP Dynamic Streaming • HLS - HTTP Live Streaming • DASH - Dynamic Adaptive Streaming over HTTP
  2. 11 Android’s support http://developer.android.com/guide/appendix/media-formats.html Streaming protocols • RTSP (RTP, SDP)

    • HTTP/HTTPS progressive streaming • HTTP/HTTPS live streamingdraft protocol: • MPEG-2 TS media files only • Protocol version 3 (Android 4.0 and above) • Protocol version 2 (Android 3.x) • Not supported before Android 3.0
  3. 12 Android’s support Video formats • H.263 • H.264/AVC •

    H.265/HEVC (5.0+) • MPEG-4 SP • VP8 (2.3.3+) • VP9 (4.4+) Audio formats • AAC LC • HE-AAC v1 • HE-AACv2 • AAC ELD (4.1+) • AMR-NB • AMR-WB • FLAC (3.1+) • MP3 • ….. http://developer.android.com/guide/appendix/media-formats.html
  4. 14 VideoView http://developer.android.com/reference/android/widget/VideoView.html android.widget.VideoView @Override protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_view); VideoView videoView = (VideoView) findViewById(R.id.view_video); // set media controller videoView.setMediaController(new MediaController(this)); // set video stream to play videoView.setVideoURI(Uri.parse(videoUri)); // start playback videoView.requestFocus(); videoView.start(); }
  5. 15 MediaPlayer & SurfaceView @Override protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState); setContentView(R.layout.activity_media_player); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view); SurfaceHolder holder = surfaceView.getHolder(); // create media player object final MediaPlayer mp = new MediaPlayer(); holder.addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { mp.setDisplay(holder); try { mp.setDataSource(videoUri); mp.prepare(); } catch (Exception e) { } mp.start(); } // ... ommitted methods for example }); } android.media.MediaPlayer android.view.SurfaceView http://developer.android.com/reference/android/media/MediaPlayer.html http://developer.android.com/reference/android/view/SurfaceView.html
  6. 20 ExoPlayer https://github.com/google/ExoPlayer Pros • Supports DASH, SmoothStreaming, and HLS

    • Customizable and extendable • Update the player with your app • Fewer device specific issues Cons • Relies on Android’s MediaCodec api, which is available on Android 4.1, (API level 16) • 4.3 for Widevine DRM