Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

Commit

Permalink
Update ExoPlayer sample's ExoPlayer version
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuya Matsuo committed May 9, 2017
1 parent 491fe67 commit 0884e56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
2 changes: 1 addition & 1 deletion sample-exoplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.google.android.exoplayer:exoplayer:r1.5.10'
compile 'com.google.android.exoplayer:exoplayer-core:r2.4.0'
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
package org.meganekkovr.sampleexoplayer;

import android.media.MediaCodec;
import android.net.Uri;

import com.google.android.exoplayer.ExoPlayer;
import com.google.android.exoplayer.MediaCodecAudioTrackRenderer;
import com.google.android.exoplayer.MediaCodecSelector;
import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
import com.google.android.exoplayer.upstream.Allocator;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.upstream.DefaultAllocator;
import com.google.android.exoplayer.upstream.DefaultUriDataSource;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;

import org.meganekkovr.Entity;
import org.meganekkovr.MeganekkoApp;
import org.meganekkovr.SurfaceRendererComponent;

public class App extends MeganekkoApp {

private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
private static final int BUFFER_SEGMENT_COUNT = 256;
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2763.0 Safari/537.36";

private ExoPlayer exoPlayer;
private SimpleExoPlayer exoPlayer;

@Override
public void init() {
Expand All @@ -50,17 +42,13 @@ public void init() {

// Load video
String videoUrl = getContext().getString(R.string.video_url);
DataSource dataSource = new DefaultUriDataSource(context, USER_AGENT);
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
ExtractorSampleSource sampleSource = new ExtractorSampleSource(Uri.parse(videoUrl), dataSource, allocator, BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT);

TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource, MediaCodecSelector.DEFAULT);

exoPlayer.prepare(videoRenderer, audioRenderer);
String userAgent = Util.getUserAgent(getContext(), "MeganekkoSample");
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), userAgent);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
exoPlayer.prepare(new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null));

// Connect ExoPlayer output to SurfaceRendererComponent
exoPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surfaceRenderer.getSurface());
exoPlayer.setVideoSurface(surfaceRenderer.getSurface());
exoPlayer.setPlayWhenReady(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import android.os.Bundle;

import com.google.android.exoplayer.ExoPlayer;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;

import org.meganekkovr.GearVRActivity;

public class MainActivity extends GearVRActivity {

private ExoPlayer exoPlayer;
private SimpleExoPlayer exoPlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// ExoPlayer.Factory.newInstance() must be called in UI thread
exoPlayer = ExoPlayer.Factory.newInstance(2);
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector());
}

@Override
Expand All @@ -24,7 +26,7 @@ protected void onDestroy() {
super.onDestroy();
}

public ExoPlayer getExoPlayer() {
public SimpleExoPlayer getExoPlayer() {
return exoPlayer;
}
}

0 comments on commit 0884e56

Please sign in to comment.