Posterior a de esta extensa búsqueda de datos dimos con la respuesta este enigma que presentan muchos los lectores. Te regalamos la solución y deseamos que te resulte de mucha apoyo.
Solución:
En Android 4.1+, puede usar esta biblioteca https://github.com/brianwernick/ExoMedia/. El ejemplo mencionado en la página Léame debería ser suficiente para comenzar. He reproducido ese fragmento de código con algunas adiciones / modificaciones.
private void setupVideoView()
EMVideoView emVideoView = (EMVideoView)findViewById(R.id.video_play_activity_video_view);
emVideoView.setOnPreparedListener(this);
//Enter your m3u8 URL below
emVideoView.setVideoURI(Uri.parse("http://SOMESERVER/playlist.m3u8"));
@Override
public void onPrepared(MediaPlayer mp)
//Starts the video playback as soon as it is ready
emVideoView.start();
@Override
public void onPause()
super.onPause();
//Pause Video Playback
emVideoView.pause();
He creado una aplicación de demostración para reproducir archivos multimedia m3u8
Primero agregue las dependencias de Gradle a su archivo
compile 'com.google.android.exoplayer:exoplayer:r2.4.0'
Cree un archivo de diseño simple con la ruta de almacenamiento master.m3u8 como entrada y la vista SimpleExoPlayerView para reproducir archivos descargados.
Cree una actividad sencilla de ExoPlayer para reproducir archivos.
public class ExoPlayer extends AppCompatActivity
Context mContext;
SimpleExoPlayerView playerView;
EditText editText;
private ComponentListener componentListener;
private DataSource.Factory mediaDataSourceFactory;
private Handler mainHandler;
private DefaultTrackSelector trackSelector;
SimpleExoPlayer player;
private static final DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exoplayer);
mContext =this;
editText = (EditText) findViewById(R.id.mediaPath);
Button btnPlay = (Button) findViewById(R.id.play);
playerView = (SimpleExoPlayerView)findViewById(R.id.video_view);
mediaDataSourceFactory = buildDataSourceFactory(true);
mainHandler = new Handler();
componentListener = new ComponentListener();
trackSelector = new DefaultTrackSelector();
btnPlay.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
if(editText.getText()!=null && editText.getText().length()>0)
initializePlayer(editText.getText().toString());
);
private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter)
return ((AnalyticsApplication) getApplication())
.buildDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
private void initializePlayer(String path)
player = ExoPlayerFactory.newSimpleInstance(mContext, trackSelector);
player.addListener(componentListener);
// String path = file:///storage/emulated/0/SugarBox/master.m3u8";
Uri uri = Uri.parse(path);
MediaSource mediaSource = buildMediaSource(uri);
player.prepare(mediaSource, true, false);
playerView.setPlayer(player);
private MediaSource buildMediaSource(Uri uri)
return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
private void releasePlayer()
if (player != null)
player.removeListener(componentListener);
player.release();
player = null;
@Override
public void onStart()
super.onStart();
if (Util.SDK_INT > 23)
if(editText.getText()!=null && editText.getText().length()>0)
initializePlayer(editText.getText().toString());
@Override
public void onResume() player == null))
if(editText.getText()!=null && editText.getText().length()>0)
initializePlayer(editText.getText().toString());
@Override
public void onPause()
super.onPause();
if (Util.SDK_INT <= 23)
releasePlayer();
@Override
public void onStop()
super.onStop();
if (Util.SDK_INT > 23)
releasePlayer();
private class ComponentListener implements com.google.android.exoplayer2.ExoPlayer.EventListener
@Override
public void onPlayerStateChanged(boolean playWhenReady,
int playbackState)
String stateString;
switch (playbackState)
case com.google.android.exoplayer2.ExoPlayer.STATE_IDLE:
stateString = "ExoPlayer.STATE_IDLE -";
break;
case com.google.android.exoplayer2.ExoPlayer.STATE_BUFFERING:
stateString = "ExoPlayer.STATE_BUFFERING -";
break;
case com.google.android.exoplayer2.ExoPlayer.STATE_READY:
stateString = "ExoPlayer.STATE_READY -";
break;
case com.google.android.exoplayer2.ExoPlayer.STATE_ENDED:
stateString = "ExoPlayer.STATE_ENDED -";
break;
default:
stateString = "UNKNOWN_STATE -";
break;
Log.d("ExopLayer", "changed state to " + stateString
+ " playWhenReady: " + playWhenReady);
@Override
public void onTimelineChanged(Timeline timeline, Object manifest)
@Override
public void onTracksChanged(TrackGroupArray trackGroups,
TrackSelectionArray trackSelections)
@Override
public void onLoadingChanged(boolean isLoading)
@Override
public void onPlayerError(ExoPlaybackException error)
@Override
public void onPositionDiscontinuity()
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters)
private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException
if (Util.SDK_INT < 18)
return null;
HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
buildHttpDataSourceFactory(false));
if (keyRequestPropertiesArray != null)
for (int i = 0; i < keyRequestPropertiesArray.length - 1; i += 2)
drmCallback.setKeyRequestProperty(keyRequestPropertiesArray[i],
keyRequestPropertiesArray[i + 1]);
return new DefaultDrmSessionManager<>(uuid,
FrameworkMediaDrm.newInstance(uuid), drmCallback, null, mainHandler, null);
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter)
return ((AnalyticsApplication) getApplication())
.buildHttpDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
Reseñas y valoraciones
Si conservas alguna desconfianza y disposición de aclararse nuestro ensayo te invitamos dejar una crónica y con gusto lo leeremos.