Skip to content

Commit

Permalink
Merge pull request #90 from learning-layers/integration
Browse files Browse the repository at this point in the history
Release v1.3.8
  • Loading branch information
melonmanchan committed Apr 28, 2016
2 parents 616f159 + 17628d9 commit a9d194b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies {
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.google.android.exoplayer:exoplayer:r1.3.3'

// Material design dialogs
compile('com.github.afollestad.material-dialogs:commons:0.8.5.4@aar') {
Expand Down
Binary file removed app/libs/exoplayer-r1.0.13.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.URLUtil;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import com.google.android.exoplayer.ExoPlaybackException;
import com.google.android.exoplayer.ExoPlayer;
import com.google.android.exoplayer.FrameworkSampleSource;
import com.google.android.exoplayer.extractor.Extractor;
import com.google.android.exoplayer.extractor.mp4.Mp4Extractor;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
import com.google.android.exoplayer.MediaCodecAudioTrackRenderer;
import com.google.android.exoplayer.MediaCodecTrackRenderer;
import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
import com.google.android.exoplayer.SampleSource;
import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.upstream.DefaultUriDataSource;
import com.google.android.exoplayer.upstream.FileDataSource;
import com.google.android.exoplayer.util.Util;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.rollbar.android.Rollbar;
Expand Down Expand Up @@ -63,6 +69,9 @@ public final class PlayerFragment extends Fragment implements ExoPlayer.Listener
// Number of framework renderers (currently video and audio)
private static final int DOWNSTREAM_RENDERER_COUNT = 2;

// The total buffer size for storing video stream data, in bytes
private static final int EXO_BUFFER_SIZE = 1024 * 1024 * 8;

private State state = State.UNPREPARED;

private FrameLayout videoContainer;
Expand All @@ -74,6 +83,9 @@ public final class PlayerFragment extends Fragment implements ExoPlayer.Listener

private LinearLayout subtitleContainer;

private DataSource dataSource;
private Extractor extractor;

private ExoPlayer exoPlayer;
private TrackRenderer videoRenderer;
private AnnotationRenderer annotationRenderer;
Expand Down Expand Up @@ -164,12 +176,17 @@ public void prepare(Video video, AnnotationEditor annotationEditor) {
orientationPatcher.updateOrientation(video);
orientationPatcher.setView(videoSurface);

SampleSource source = new FrameworkSampleSource(
getActivity(),
videoUri,
null,
DOWNSTREAM_RENDERER_COUNT
);
// Seems as if the DefaultUriDataSource cannot correctly guess a local file URI, so just do it manually
if (video.isLocal()) {
dataSource = new FileDataSource();
} else {
String userAgent = Util.getUserAgent(getActivity(), "ACHSO");
dataSource = new DefaultUriDataSource(getActivity(), userAgent);
}

extractor = new Mp4Extractor();

ExtractorSampleSource source = new ExtractorSampleSource(videoUri, dataSource, extractor, DOWNSTREAM_RENDERER_COUNT, EXO_BUFFER_SIZE);

// The video renderer runs on another thread: we need to supply a handler on the main
// thread in order to receive events.
Expand Down Expand Up @@ -395,6 +412,11 @@ public void onCryptoError(MediaCodec.CryptoException error) {
Rollbar.reportException(error);
}

@Override
public void onDecoderInitialized(String decoderName, long elapsedRealtimeMs, long initializationDurationMs) {

}

/**
* Invoked when a frame is rendered to a surface for the first time following that surface
* having been set as the target for the renderer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void run() {
* Invoked to make progress when the renderer is in the STATE_UNPREPARED state.
*/
@Override
protected int doPrepare() {
protected int doPrepare(long positionUs) {
// Prepared instantly
return STATE_PREPARED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public void onCryptoError(CryptoException exception) {
delegate.onCryptoError(exception);
}

@Override
public void onDecoderInitialized(String decoderName, long elapsedRealtimeMs, long initializationDurationMs) {

}

/**
* Rotates the video when the TextureView's layout bounds change.
* Video dimensions are preserved.
Expand All @@ -135,11 +140,6 @@ public void onCryptoError(CryptoException exception) {
public void onLayoutChange(View changedView, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {

// Not needed on API 21 and up
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
return;
}

if (rotationDegrees == -1 || view == null || changedView != view) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.webkit.URLUtil;

import com.google.common.io.Files;
import com.rollbar.android.Rollbar;
Expand Down Expand Up @@ -124,6 +125,29 @@ protected Video readVideoFromFile(File file) throws IOException {
video.setManifestUri(Uri.fromFile(file));
video.setLastModified(new Date(file.lastModified()));
video.setRepository(this);


// Sanity test to check if user deleted video file from gallery
// Missing thumb nail icon is fine, since you can still watch the local video
if (video.isLocal()) {
Uri videoUri = video.getVideoUri();
File sanityCheckFile = new File(videoUri.getPath());

if (!sanityCheckFile.exists()) {

// Also remove thumb file;
File thumbFile = new File(video.getThumbUri().getPath());
File videoFile = getLocalVideoFile(video.getId());

thumbFile.delete();
videoFile.delete();
allVideos.remove(video.getId());
bus.post(new VideoRepositoryUpdatedEvent(this));

throw new IOException("Local video file not found at " + videoUri);
}
}

return video;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,9 @@ private class GestureListener extends GestureDetector.SimpleOnGestureListener {
/**
* Called when the canvas is tapped once.
*/
@Override
public boolean onSingleTapUp(MotionEvent event) {
canvasTapped(event);
return true;
}

@Override
public boolean onDown(MotionEvent event) {
// Best practice to always return true here.
// http://developer.android.com/training/gestures/detector.html#detect
canvasTapped(event);
return true;
}

Expand Down

0 comments on commit a9d194b

Please sign in to comment.