Skip to content

Commit

Permalink
Merge pull request #5 from brianwernick/exoplayer_1_4_1
Browse files Browse the repository at this point in the history
Updated ExoPlayer to 1.4.1
  • Loading branch information
brianwernick committed Jul 21, 2015
2 parents 95db684 + 96df113 commit ca61745
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 30 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The latest AAR (Android Archive) files can be downloaded from JCenter [ExoMedia]
Or included in your gradle dependencies

```groovy
compile 'com.devbrackets.android:exomedia:2.2.2'
compile 'com.devbrackets.android:exomedia:2.2.3'
```

Additionally, if you use ProGuard you will need to add the following rule
Expand All @@ -41,27 +41,29 @@ The EMVideoView (EM for ExoMedia) can be added in your layout files like any oth

```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.devbrackets.android.exomedia.EMVideoView
android:id="@+id/video_play_activity_video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
xmlns:EMVideoView="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.devbrackets.android.exomedia.EMVideoView
android:id="@+id/video_play_activity_video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
EMVideoView:defaultControlsEnabled="true"/>
</RelativeLayout>

```

While in your Activity or Fragment you treat it like a standard Android VideoView

```java
private void setupVideoView() {
EMVideoView emVideoView = (EMVideoView)findViewById(R.id.video_play_activity_video_view);
emVideoView.setDefaultControlsEnabled(true);
emVideoView.setOnPreparedListener(this);

//For now we just picked an arbitrary item to play. More can be found at
//https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java
emVideoView.setVideoURI(Uri.parse("https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"));
//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"));
}

@Override
Expand Down Expand Up @@ -101,4 +103,4 @@ under [Attribution 4.0 International][2]
[2]: http://creativecommons.org/licenses/by/4.0/
[3]: https://bintray.com/brianwernick/maven/ExoMedia/view#files
[4]: http://devbrackets.com/dev/libs/exomedia.html
[5]: http://devbrackets.com/dev/libs/docs/exomedia/2.2.2/index.html
[5]: http://devbrackets.com/dev/libs/docs/exomedia/2.2.3/index.html
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'bintray-release'

def versionMajor = 2
def versionMinor = 2
def versionPatch = 2
def versionPatch = 3

// Maven GAV
def libraryGroupId = 'com.devbrackets.android'
Expand All @@ -13,13 +13,13 @@ def libraryVersion = "${versionMajor}.${versionMinor}.${versionPatch}" // releas

dependencies {
// Android
compile 'com.android.support:appcompat-v7:22.2.0' // includes support-v4
compile 'com.android.support:appcompat-v7:22.2.1' // includes support-v4

// Event Bus
compile 'com.squareup:otto:1.3.7'
compile 'com.squareup:otto:1.3.8'

// ExoPlayer
compile 'com.google.android.exoplayer:exoplayer:r1.3.3'
compile 'com.google.android.exoplayer:exoplayer:r1.4.1'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import com.devbrackets.android.exomedia.util.MediaUtil;
import com.devbrackets.android.exomedia.util.Repeater;
import com.devbrackets.android.exomedia.util.StopWatch;
import com.google.android.exoplayer.VideoSurfaceView;
import com.devbrackets.android.exomedia.widget.VideoSurfaceView;
import com.google.android.exoplayer.audio.AudioCapabilities;
import com.google.android.exoplayer.audio.AudioCapabilitiesReceiver;
import com.squareup.otto.Bus;
Expand Down Expand Up @@ -1005,7 +1005,7 @@ public void onMediaPlaybackEnded() {
public void onVideoSizeChanged(int width, int height, float pixelWidthHeightRatio) {
//Makes sure we have the correct aspect ratio
float videoAspectRatio = height == 0 ? 1 : (width * pixelWidthHeightRatio) / height;
exoVideoSurfaceView.setVideoWidthHeightRatio(videoAspectRatio);
exoVideoSurfaceView.setAspectRatio(videoAspectRatio);

//Sets the horizontal shutter (top and bottom) sizes
int shutterHeight = calculateVerticalShutterSize(height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

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;
Expand All @@ -37,6 +39,7 @@
import com.google.android.exoplayer.metadata.Id3Parser;
import com.google.android.exoplayer.metadata.MetadataTrackRenderer;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.upstream.DefaultAllocator;
import com.google.android.exoplayer.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer.upstream.DefaultUriDataSource;
import com.google.android.exoplayer.util.ManifestFetcher;
Expand All @@ -51,8 +54,8 @@
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class HlsRenderBuilder extends RenderBuilder implements ManifestCallback<HlsPlaylist> {
private static final int DOWNSTREAM_RENDER_COUNT = 3;
private static final long REQUESTED_BUFFER_DURATION_MS = 40000;
private static final int BUFFER_SEGMENT_SIZE = 256 * 1024;
private static final int BUFFER_SEGMENTS = 64;

private final AudioCapabilities audioCapabilities;

Expand Down Expand Up @@ -80,6 +83,7 @@ public void onSingleManifestError(IOException e) {

@Override
public void onSingleManifest(HlsPlaylist playlist) {
LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

//Calculates the Chunk variant indices
Expand All @@ -100,9 +104,8 @@ public void onSingleManifest(HlsPlaylist playlist) {
HlsChunkSource chunkSource = new HlsChunkSource(dataSource, uri, playlist, bandwidthMeter,
variantIndices, HlsChunkSource.ADAPTIVE_MODE_SPLICE, audioCapabilities);

HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, true, DOWNSTREAM_RENDER_COUNT, REQUESTED_BUFFER_SIZE,
REQUESTED_BUFFER_DURATION_MS, player.getMainHandler(), player, EMExoPlayer.RENDER_VIDEO_INDEX);

HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, player.getMainHandler(), player, EMExoPlayer.RENDER_VIDEO_INDEX);

//Create the renderers
MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
import com.google.android.exoplayer.drm.StreamingDrmSessionManager;
import com.google.android.exoplayer.hls.HlsSampleSource;
import com.google.android.exoplayer.metadata.MetadataTrackRenderer;
import com.google.android.exoplayer.text.Cue;
import com.google.android.exoplayer.text.TextRenderer;
import com.google.android.exoplayer.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer.util.PlayerControl;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

Expand Down Expand Up @@ -464,11 +466,6 @@ public void onLoadError(int sourceId, IOException e) {
}
}

@Override
public void onText(String text) {
processText(text);
}

public MetadataTrackRenderer.MetadataRenderer<Map<String, Object>> getId3MetadataRenderer() {
return new MetadataTrackRenderer.MetadataRenderer<Map<String, Object>>() {
@Override
Expand Down Expand Up @@ -514,6 +511,11 @@ public void onUpstreamDiscarded(int sourceId, int mediaStartTimeMs, int mediaEnd
//Purposefully left blank
}

@Override
public void onCues(List<Cue> list) {
//Purposefully left blank
}

private void reportPlayerState() {
boolean playWhenReady = player.getPlayWhenReady();
int playbackState = getPlaybackState();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.devbrackets.android.exomedia.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceView;

/**
* A SurfaceView that resizes itself to match a specified aspect ratio.
*/
public class VideoSurfaceView extends SurfaceView {
/**
* The surface view will not resize itself if the fractional difference between its default
* aspect ratio and the aspect ratio of the video falls below this threshold.
* <p>
* This tolerance is useful for fullscreen playbacks, since it ensures that the surface will
* occupy the whole of the screen when playing content that has the same (or virtually the same)
* aspect ratio as the device. This typically reduces the number of view layers that need to be
* composited by the underlying system, which can help to reduce power consumption.
*/
private static final float MAX_ASPECT_RATIO_DEFORMATION_FRACTION = 0.01f;

private float videoAspectRatio;

public VideoSurfaceView(Context context) {
super(context);
}

public VideoSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
}

/**
* Set the aspect ratio that this {@link VideoSurfaceView} should satisfy.
*
* @param widthHeightRatio The width to height ratio.
*/
public void setAspectRatio(float widthHeightRatio) {
if (this.videoAspectRatio != widthHeightRatio) {
this.videoAspectRatio = widthHeightRatio;
requestLayout();
}
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (videoAspectRatio == 0) {
// Aspect ratio not set.
return;
}

int width = getMeasuredWidth();
int height = getMeasuredHeight();
float viewAspectRatio = (float) width / height;
float aspectDeformation = videoAspectRatio / viewAspectRatio - 1;
if (Math.abs(aspectDeformation) <= MAX_ASPECT_RATIO_DEFORMATION_FRACTION) {
// We're within the allowed tolerance.
return;
}

if (aspectDeformation > 0) {
height = (int) (width / videoAspectRatio);
} else {
width = (int) (height * videoAspectRatio);
}

super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
}
2 changes: 1 addition & 1 deletion library/src/main/res/layout/exomedia_exo_view_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:layout_alignParentLeft="true"
android:background="@android:color/black"/>

<com.google.android.exoplayer.VideoSurfaceView
<com.devbrackets.android.exomedia.widget.VideoSurfaceView
android:id="@+id/exomedia_exo_video_surface"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down

0 comments on commit ca61745

Please sign in to comment.