use of com.google.android.exoplayer2.Player in project android by owncloud.
the class PreviewVideoActivity method preparePlayer.
// Video player internal methods
private void preparePlayer() {
// Create a default TrackSelector
AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = new SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).setLoadControl(new DefaultLoadControl()).build();
player.addListener(this);
exoPlayerView.setPlayer(player);
// Prepare video player asynchronously
new PrepareVideoPlayerAsyncTask(getApplicationContext(), this, getFile(), getAccount()).execute();
}
use of com.google.android.exoplayer2.Player in project android by owncloud.
the class PreviewVideoErrorAdapter method handlePlayerSourceError.
/**
* Handle video player source exceptions and create a PreviewVideoError with the appropriate info
*
* @param error Exoplayer source exception
* @param context
* @return preview video error after processing the Exoplayer source exception
*/
private static PreviewVideoError handlePlayerSourceError(ExoPlaybackException error, Context context) {
// PreviewVideoError previewVideoError;
final IOException sourceException = error.getSourceException();
final Throwable cause = sourceException.getCause();
if (cause != null) {
if (cause.getCause() instanceof CertificateException) {
return new PreviewVideoError(context.getString(R.string.streaming_certificate_error), true, false);
}
// Cannot connect with the server
if (sourceException.getCause() instanceof UnknownHostException) {
return new PreviewVideoError(context.getString(R.string.network_error_socket_exception), false, false);
}
// this case, the parent folder is refreshed and login view is shown
if (sourceException.getCause() != null && sourceException.getCause() instanceof EOFException) {
return new PreviewVideoError(context.getString(R.string.streaming_position_not_available), false, true);
}
}
// To handle this case, the parent folder is refreshed and login view is shown
if (sourceException instanceof UnrecognizedInputFormatException) {
return new PreviewVideoError(context.getString(R.string.streaming_unrecognized_input), true, true);
}
if (sourceException instanceof HttpDataSource.InvalidResponseCodeException) {
// Video file no longer exists in the server
if (((HttpDataSource.InvalidResponseCodeException) sourceException).responseCode == NOT_FOUND_ERROR) {
return new PreviewVideoError(context.getString(R.string.streaming_file_not_found_error), false, false);
}
// redirections are allowed, but crossed redirections not
if ((((HttpDataSource.InvalidResponseCodeException) sourceException).responseCode == TEMPORARY_REDIRECTION)) {
return new PreviewVideoError(context.getString(R.string.streaming_crossed_redirection), true, false);
}
}
// if error could not be detected properly
return new PreviewVideoError(context.getString(R.string.previewing_video_common_error), true, false);
}
use of com.google.android.exoplayer2.Player in project android by owncloud.
the class PreviewVideoFragment method preparePlayer.
// Video player internal methods
private void preparePlayer() {
AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// Video streaming is only supported at Jelly Bean or higher Android versions (>= API 16)
// Create the player
player = new SimpleExoPlayer.Builder(requireContext()).setTrackSelector(trackSelector).setLoadControl(new DefaultLoadControl()).build();
player.addListener(this);
// Bind the player to the view.
exoPlayerView.setPlayer(player);
// Prepare video player asynchronously
new PrepareVideoPlayerAsyncTask(getActivity(), this, getFile(), mAccount).execute();
}
use of com.google.android.exoplayer2.Player in project Douya by DreaminginCodeZH.
the class MediaQueueNavigator method onSkipToQueueItem.
@Override
public void onSkipToQueueItem(Player player, long id) {
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) {
return;
}
int windowIndex = (int) id;
if (windowIndex < 0 || windowIndex >= timeline.getWindowCount()) {
return;
}
player.seekToDefaultPosition(windowIndex);
player.setPlayWhenReady(true);
}
use of com.google.android.exoplayer2.Player in project ExoPlayer by google.
the class SessionPlayerConnectorTest method seekTo_skipsUnnecessarySeek.
@Test
@LargeTest
public void seekTo_skipsUnnecessarySeek() throws Exception {
CountDownLatch readAllowedLatch = new CountDownLatch(1);
playerTestRule.setDataSourceInstrumentation(dataSpec -> {
try {
assertThat(readAllowedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
} catch (Exception e) {
assertWithMessage("Unexpected exception %s", e).fail();
}
});
sessionPlayerConnector.setMediaItem(TestUtils.createMediaItem(R.raw.video_big_buck_bunny));
// prepare() will be pending until readAllowed is countDowned.
sessionPlayerConnector.prepare();
CopyOnWriteArrayList<Long> positionChanges = new CopyOnWriteArrayList<>();
long testIntermediateSeekToPosition1 = 3000;
long testIntermediateSeekToPosition2 = 2000;
long testFinalSeekToPosition = 1000;
CountDownLatch onSeekCompletedLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onSeekCompleted(SessionPlayer player, long position) {
// Do not assert here, because onSeekCompleted() can be called after the player is
// closed.
positionChanges.add(position);
if (position == testFinalSeekToPosition) {
onSeekCompletedLatch.countDown();
}
}
});
ListenableFuture<PlayerResult> seekFuture1 = sessionPlayerConnector.seekTo(testIntermediateSeekToPosition1);
ListenableFuture<PlayerResult> seekFuture2 = sessionPlayerConnector.seekTo(testIntermediateSeekToPosition2);
ListenableFuture<PlayerResult> seekFuture3 = sessionPlayerConnector.seekTo(testFinalSeekToPosition);
readAllowedLatch.countDown();
assertThat(seekFuture1.get().getResultCode()).isEqualTo(RESULT_INFO_SKIPPED);
assertThat(seekFuture2.get().getResultCode()).isEqualTo(RESULT_INFO_SKIPPED);
assertThat(seekFuture3.get().getResultCode()).isEqualTo(RESULT_SUCCESS);
assertThat(onSeekCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
assertThat(positionChanges).containsNoneOf(testIntermediateSeekToPosition1, testIntermediateSeekToPosition2);
assertThat(positionChanges).contains(testFinalSeekToPosition);
}
Aggregations