Dave's Brain

Browse - Programming Tips - What is the minimal ExoPlayer use?

Date: 2014jul7
Updated: 2016jun9
OS: Android
Language: Java

Q.  What is the minimal ExoPlayer use?

A.  From the 2014 Google I/O lecture and the manual, this is it:

import com.google.android.exoplayer.*; import android.content.Context; import android.media.MediaCodec; import android.net.Uri; class ExampleExoplayer { ExoPlayer exoPlayer = null; void play(String strUri, Surface surface) { Uri uri = Uri.parse(strUri); final int numRenderers = 2; // Build the sample source SampleSource sampleSource = new FrameworkSampleSource(mContext, uri, /* headers */ null, numRenderers); // Build the track renderers TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Build the ExoPlayer and start playback exoPlayer = ExoPlayer.Factory.newInstance(numRenderers); exoPlayer.prepare(videoRenderer, audioRenderer); // Pass the surface to the video renderer. exoPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface); exoPlayer.setPlayWhenReady(true); } // Don't forget to release when done! void release() { if (exoPlayer != null) { exoPlayer.release(); } } }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.