Skip to content

Instantly share code, notes, and snippets.

View ojw28's full-sized avatar

Oliver Woodman ojw28

View GitHub Profile
// Play a list of URIs as a playlist.
List<MediaItem> mediaItems = new ArrayList<>();
for (int i = 0; i < videoUris.length; i++) {
mediaItems.add(MediaItem.fromUri(videoUris[i]));
}
// Set the playlist, prepare and play.
player.setMediaItems(mediaItems);
player.prepare();
player.play()
class PlayerErrorListener extends Player.DefaultEventListener {
@Override
public void onPlayerError(ExoPlaybackException error) {
handlePlayerError(error);
}
}
class PlayerErrorListener implements Player.EventListener {
@Override
public void onPlayerError(ExoPlaybackException error) {
// We're interested!
handlePlayerError(error);
}
@Override
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
return new DashMediaSource.Factory(chunkSourceFactory, manifestDataSourceFactory)
.setManifestParser(new CustomManifestParser())
.createMediaSource(manifestUri, eventHandler, eventListener);
return new DashMediaSource(
manifestUri,
manifestDataSourceFactory,
new CustomManifestParser(),
chunkSourceFactory,
DashMediaSource.DEFAULT_MIN_LOADABLE_RETRY_COUNT,
DashMediaSource.DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS,
eventHandler,
eventListener);
// Enable tunneling if supported by the current media and device configuration.
trackSelector.setTunnelingAudioSessionId(C.generateAudioSessionIdV21(this));
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
for (int i = 0; i < trackGroups.length; i++) {
TrackGroup trackGroup = trackGroups.get(i);
for (int j = 0; j < trackGroup.length; j++) {
Metadata trackMetadata = trackGroup.getFormat(j).metadata;
if (trackMetadata != null) {
// We found metadata. Do something with it here!
}
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="@+id/player"
android:layout_width="match_parent"
- android:layout_height="match_parent"/>
+ android:layout_height="match_parent"
+ app:controller_layout_id="@layout/custom_controls"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton android:id="@id/exo_play"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="#CC000000"
style="@style/ExoMediaButton.Play"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="match_parent"
- app:resize_mode="fill"/>
+ app:resize_mode="fill"