Skip to content

Commit

Permalink
Fix exoplayer data sources for local videos also
Browse files Browse the repository at this point in the history
  • Loading branch information
melonmanchan committed Apr 25, 2016
1 parent 9af3449 commit f9c0d31
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,28 @@
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.extractor.Extractor;
import com.google.android.exoplayer.extractor.ExtractorInput;
import com.google.android.exoplayer.extractor.ExtractorOutput;
import com.google.android.exoplayer.extractor.PositionHolder;
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.TrackRenderer;
import com.google.android.exoplayer.upstream.Allocator;
import com.google.android.exoplayer.upstream.DefaultAllocator;
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;

import java.io.IOException;
import java.util.List;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -177,9 +173,16 @@ public void prepare(Video video, AnnotationEditor annotationEditor) {
orientationPatcher.updateOrientation(video);
orientationPatcher.setView(videoSurface);

String userAgent = Util.getUserAgent(getActivity(), "ACHSO");
System.out.println(URLUtil.isFileUrl(videoUri.toString()));

// Seems as if the DefaultUriDataSource cannot correctly guess a local file URI, so just do it manually
if (URLUtil.isFileUrl(videoUri.toString()) == true) {
dataSource = new FileDataSource();
} else {
String userAgent = Util.getUserAgent(getActivity(), "ACHSO");
dataSource = new DefaultUriDataSource(getActivity(), userAgent);
}

dataSource = new DefaultUriDataSource(getActivity(), userAgent);
extractor = new Mp4Extractor();

ExtractorSampleSource source = new ExtractorSampleSource(videoUri, dataSource, extractor, DOWNSTREAM_RENDERER_COUNT, 5 * 1024 * 1024);
Expand Down

0 comments on commit f9c0d31

Please sign in to comment.