use of com.google.android.exoplayer2.extractor.Extractor in project Camera-Roll-Android-App by kollerlukas.
the class VideoPlayerActivity method initPlayer.
private void initPlayer() {
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), null);
// Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null);
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);
// Create the player
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(null)), new DefaultLoadControl());
// Bind the player to the view.
SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView);
simpleExoPlayerView.setPlayer(player);
// Prepare the player with the source.
player.prepare(videoSource);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
player.setPlayWhenReady(true);
final ImageButton playPause = findViewById(R.id.play_pause);
player.addListener(new SimpleEventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
// update PlayPause-Button
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && showAnimations()) {
if (player.getPlayWhenReady()) {
playPause.setImageResource(R.drawable.play_to_pause_avd);
} else {
playPause.setImageResource(R.drawable.pause_to_play_avd);
}
Drawable d = playPause.getDrawable();
if (d instanceof Animatable) {
((Animatable) d).start();
}
} else {
if (player.getPlayWhenReady()) {
playPause.setImageResource(R.drawable.ic_pause_white);
} else {
playPause.setImageResource(R.drawable.ic_play_arrow_white);
}
}
}
});
}
use of com.google.android.exoplayer2.extractor.Extractor in project ExoPlayer by google.
the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekToZero.
@Test
public void seeking_seekTable_handlesSeekToZero() throws IOException {
String fileName = TEST_FILE_SEEK_TABLE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = 0;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.extractor.Extractor in project ExoPlayer by google.
the class FlacExtractorSeekTest method flacExtractorReads_binarySearch_returnSeekableSeekMap.
@Test
public void flacExtractorReads_binarySearch_returnSeekableSeekMap() throws IOException {
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_BINARY_SEARCH);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
assertThat(seekMap).isNotNull();
assertThat(seekMap.getDurationUs()).isEqualTo(DURATION_US);
assertThat(seekMap.isSeekable()).isTrue();
}
use of com.google.android.exoplayer2.extractor.Extractor in project ExoPlayer by google.
the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekingBackward.
@Test
public void seeking_seekTable_handlesSeekingBackward() throws IOException {
String fileName = TEST_FILE_SEEK_TABLE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 1_234_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 987_000;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.extractor.Extractor in project ExoPlayer by google.
the class FlacExtractorSeekTest method seeking_binarySearch_handlesSeekingBackward.
@Test
public void seeking_binarySearch_handlesSeekingBackward() throws IOException {
String fileName = TEST_FILE_BINARY_SEARCH;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 1_234_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 987_00;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekContainsTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Aggregations