Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/brianwernick/ExoMedia
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwernick committed Sep 30, 2015
2 parents 810db28 + b1b3fd0 commit 06d63e6
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 191 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ back to the MediaPlayer.
This is useful for supporting Http Live Streaming (HLS) and full HD (1080p +) playback
since the Android VideoView struggles with those.

**NOTE:** HLS, DASH, and other streaming protocols are not supported on Android 4.0.* and below
due to constraints with the Android MediaPlayer and VideoView


Website And Documentation
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {
//For now we just picked an arbitrary item to play. More can be found at
//https://archive.org/details/more_animation
emVideoView.setVideoURI(Uri.parse("https://archive.org/download/Popeye_forPresident/Popeye_forPresident_512kb.mp4"));
// emVideoView.setVideoURI(Uri.parse("http://cdn-fms.rbs.com.br/vod/hls_sample1_manifest.m3u8"));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.0.1' // includes support-v4

// ExoPlayer
compile 'com.google.android.exoplayer:exoplayer:r1.4.2'
compile 'com.google.android.exoplayer:exoplayer:r1.5.0'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void stopProgressPoll() {
private RenderBuilder getRendererBuilder(AudioType renderType, Uri uri, MediaUtil.MediaType defaultMediaType) {
switch (renderType) {
case HLS:
return new HlsRenderBuilder(context, getUserAgent(), uri.toString(), audioCapabilities);
return new HlsRenderBuilder(context, getUserAgent(), uri.toString());
default:
return new RenderBuilder(context, getUserAgent(), uri.toString(), defaultMediaType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ public void onStateChanged(boolean playWhenReady, int playbackState) {
}

@Override
public void onVideoSizeChanged(int width, int height, float pixelWidthHeightRatio) {
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
muxNotifier.onVideoSizeChanged(width, height, pixelWidthHeightRatio);

for (ExoPlayerListener listener : exoPlayerListeners) {
listener.onVideoSizeChanged(width, height, pixelWidthHeightRatio);
listener.onVideoSizeChanged(width, height, unappliedRotationDegrees, pixelWidthHeightRatio);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private void setupVideoView() {
private RenderBuilder getRendererBuilder(VideoType renderType, Uri uri, MediaUtil.MediaType defaultMediaType) {
switch (renderType) {
case HLS:
return new HlsRenderBuilder(getContext(), getUserAgent(), uri.toString(), audioCapabilities);
return new HlsRenderBuilder(getContext(), getUserAgent(), uri.toString());
default:
return new RenderBuilder(getContext(), getUserAgent(), uri.toString(), defaultMediaType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
import android.os.Build;

import com.devbrackets.android.exomedia.exoplayer.EMExoPlayer;
import com.devbrackets.android.exomedia.listener.RendererBuilderCallback;
import com.google.android.exoplayer.DefaultLoadControl;
import com.google.android.exoplayer.LoadControl;
import com.google.android.exoplayer.MediaCodecAudioTrackRenderer;
import com.google.android.exoplayer.MediaCodecUtil;
import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.audio.AudioCapabilities;
import com.google.android.exoplayer.chunk.VideoFormatSelectorUtil;
import com.google.android.exoplayer.hls.HlsChunkSource;
import com.google.android.exoplayer.hls.HlsMasterPlaylist;
Expand All @@ -54,31 +52,27 @@
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class HlsRenderBuilder extends RenderBuilder implements ManifestCallback<HlsPlaylist> {
private final AudioCapabilities audioCapabilities;

private static final int BUFFER_SEGMENT_SIZE = 256 * 1024;
private static final int BUFFER_SEGMENTS = 64;

private EMExoPlayer player;
private RendererBuilderCallback callback;

public HlsRenderBuilder(Context context, String userAgent, String url, AudioCapabilities audioCapabilities) {
public HlsRenderBuilder(Context context, String userAgent, String url) {
super(context, userAgent, url);
this.audioCapabilities = audioCapabilities;
}

@Override
public void buildRenderers(EMExoPlayer player, RendererBuilderCallback callback) {
public void buildRenderers(EMExoPlayer player) {
this.player = player;
this.callback = callback;
HlsPlaylistParser parser = new HlsPlaylistParser();
ManifestFetcher<HlsPlaylist> playlistFetcher = new ManifestFetcher<>(uri, new DefaultUriDataSource(context, null, userAgent, true), parser);
playlistFetcher.singleLoad(player.getMainHandler().getLooper(), this);
}

@Override
public void onSingleManifestError(IOException e) {
callback.onRenderersError(e);
player.onRenderersError(e);
}

@Override
Expand All @@ -94,15 +88,15 @@ public void onSingleManifest(HlsPlaylist playlist) {
try {
variantIndices = VideoFormatSelectorUtil.selectVideoFormatsForDefaultDisplay(context, masterPlaylist.variants, null, false);
} catch (MediaCodecUtil.DecoderQueryException e) {
callback.onRenderersError(e);
player.onRenderersError(e);
return;
}
}

//Create the Sample Source to be used by the renders
DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent, true);
HlsChunkSource chunkSource = new HlsChunkSource(dataSource, uri, playlist, bandwidthMeter,
variantIndices, HlsChunkSource.ADAPTIVE_MODE_SPLICE, audioCapabilities);
variantIndices, HlsChunkSource.ADAPTIVE_MODE_SPLICE);

HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, player.getMainHandler(), player, EMExoPlayer.RENDER_VIDEO_INDEX);
Expand All @@ -122,7 +116,7 @@ public void onSingleManifest(HlsPlaylist playlist) {
renderers[EMExoPlayer.RENDER_VIDEO_INDEX] = videoRenderer;
renderers[EMExoPlayer.RENDER_AUDIO_INDEX] = audioRenderer;
renderers[EMExoPlayer.RENDER_TIMED_METADATA_INDEX] = id3Renderer;
callback.onRenderers(null, null, renderers, bandwidthMeter);
player.onRenderers(renderers, bandwidthMeter);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.util.Log;

import com.devbrackets.android.exomedia.exoplayer.EMExoPlayer;
import com.devbrackets.android.exomedia.listener.RendererBuilderCallback;
import com.devbrackets.android.exomedia.renderer.EMMediaCodecAudioTrackRenderer;
import com.devbrackets.android.exomedia.util.MediaUtil;
import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
Expand Down Expand Up @@ -72,7 +71,7 @@ public RenderBuilder(Context context, String userAgent, String uri, MediaUtil.Me
this.requestedDefaultType = defaultType;
}

public void buildRenderers(EMExoPlayer player, RendererBuilderCallback callback) {
public void buildRenderers(EMExoPlayer player) {
//Create the Sample Source to be used by the renderers
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(player.getMainHandler(), player);
Expand All @@ -92,7 +91,11 @@ public void buildRenderers(EMExoPlayer player, RendererBuilderCallback callback)
TrackRenderer[] renderers = new TrackRenderer[EMExoPlayer.RENDER_COUNT];
renderers[EMExoPlayer.RENDER_VIDEO_INDEX] = videoRenderer;
renderers[EMExoPlayer.RENDER_AUDIO_INDEX] = audioRenderer;
callback.onRenderers(null, null, renderers, bandwidthMeter);
player.onRenderers(renderers, bandwidthMeter);
}

public void cancel() {
//Purposefully left blank
}

/**
Expand Down Expand Up @@ -155,7 +158,7 @@ protected Extractor getExtractor(MediaUtil.MediaType mediaType, MediaUtil.MediaT
return new Mp3Extractor();

case TS:
return new TsExtractor(0, null);
return new TsExtractor();

case WEBM:
case MKV:
Expand Down
Loading

0 comments on commit 06d63e6

Please sign in to comment.