use of com.google.android.exoplayer2.ui.PlayerView in project odysee-android by OdyseeTeam.
the class FileViewFragment method onExitPIPMode.
public void onExitPIPMode() {
View root = getView();
if (root != null) {
PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
playerView.setVisibility(View.VISIBLE);
}
}
use of com.google.android.exoplayer2.ui.PlayerView in project odysee-android by OdyseeTeam.
the class MainActivity method setPlayerForMiniPlayerView.
private void setPlayerForMiniPlayerView() {
PlayerView view = findViewById(R.id.global_now_playing_player_view);
if (view != null) {
view.setVisibility(View.VISIBLE);
view.setPlayer(null);
view.setPlayer(MainActivity.appPlayer);
}
}
use of com.google.android.exoplayer2.ui.PlayerView in project odysee-android by OdyseeTeam.
the class MainActivity method renderFullMode.
private void renderFullMode() {
if (!inFullscreenMode) {
showActionBar();
} else {
View v = findViewById(R.id.appbar);
if (v != null) {
v.setFitsSystemWindows(false);
}
}
Fragment fragment = getCurrentFragment();
boolean inMainView = currentDisplayFragment == null;
boolean inFileView = fragment instanceof FileViewFragment;
boolean inChannelView = fragment instanceof ChannelFragment;
boolean inSearchView = fragment instanceof SearchFragment;
findViewById(R.id.main_activity_other_fragment).setVisibility(!inMainView ? View.VISIBLE : View.GONE);
findViewById(R.id.content_main).setVisibility(View.VISIBLE);
findViewById(R.id.fragment_container_main_activity).setVisibility(inMainView ? View.VISIBLE : View.GONE);
if (inMainView) {
showBottomNavigation();
}
findViewById(R.id.appbar).setVisibility(inMainView || inSearchView ? View.VISIBLE : View.GONE);
if (!inFileView && !inFullscreenMode && nowPlayingClaim != null) {
findViewById(R.id.miniplayer).setVisibility(View.VISIBLE);
setPlayerForMiniPlayerView();
}
View pipPlayerContainer = findViewById(R.id.pip_player_container);
PlayerView pipPlayer = findViewById(R.id.pip_player);
pipPlayer.setPlayer(null);
pipPlayerContainer.setVisibility(View.GONE);
playerReassigned = true;
}
use of com.google.android.exoplayer2.ui.PlayerView in project odysee-android by OdyseeTeam.
the class FileViewFragment method playMedia.
private void playMedia() {
boolean newPlayerCreated = false;
Context context = getContext();
if (MainActivity.appPlayer == null && context != null) {
AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).setContentType(C.CONTENT_TYPE_MOVIE).build();
MainActivity.appPlayer = new ExoPlayer.Builder(context).build();
MainActivity.appPlayer.setWakeMode(C.WAKE_MODE_NETWORK);
MainActivity.appPlayer.setAudioAttributes(audioAttributes, true);
MainActivity.playerCache = new SimpleCache(context.getCacheDir(), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 256), new ExoDatabaseProvider(context));
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.initMediaSession();
activity.initPlaybackNotification();
}
newPlayerCreated = true;
}
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.initPlaybackNotification();
}
Claim claimToPlay = collectionClaimItem != null ? collectionClaimItem : fileClaim;
View root = getView();
if (root != null) {
PlayerView view = root.findViewById(R.id.file_view_exoplayer_view);
view.setShutterBackgroundColor(Color.TRANSPARENT);
view.setPlayer(MainActivity.appPlayer);
view.getPlayer().addListener(new Player.Listener() {
@Override
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
isPlaying = playWhenReady;
Player.Listener.super.onPlayWhenReadyChanged(playWhenReady, reason);
}
});
view.setUseController(true);
if (context instanceof MainActivity) {
((MainActivity) context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
if (MainActivity.nowPlayingClaim != null && MainActivity.nowPlayingClaim.getClaimId().equalsIgnoreCase(claimToPlay.getClaimId()) && !newPlayerCreated) {
// if the claim is already playing, we don't need to reload the media source
if (MainActivity.appPlayer != null) {
MainActivity.appPlayer.setPlayWhenReady(true);
playbackStarted = true;
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.displayCurrentlyPlayingVideo();
}
// reconnect the app player
if (fileViewPlayerListener != null) {
MainActivity.appPlayer.addListener(fileViewPlayerListener);
}
setPlayerForPlayerView();
loadAndScheduleDurations();
}
return;
}
if (MainActivity.appPlayer != null) {
showBuffering();
if (fileViewPlayerListener != null) {
MainActivity.appPlayer.addListener(fileViewPlayerListener);
}
if (context instanceof MainActivity) {
((MainActivity) context).setNowPlayingClaim(claimToPlay, currentUrl);
}
MainActivity.appPlayer.setPlayWhenReady(Objects.requireNonNull((MainActivity) (getActivity())).isMediaAutoplayEnabled());
if (claimToPlay.hasSource()) {
getStreamingUrlAndInitializePlayer(claimToPlay);
} else {
String mediaSourceUrl = getLivestreamUrl();
DefaultHttpDataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();
if (context != null) {
dataSourceFactory.setUserAgent(Util.getUserAgent(context, getString(R.string.app_name)));
}
MediaSource mediaSource = null;
if (mediaSourceUrl != null) {
if (!mediaSourceUrl.equals("notlive")) {
Map<String, String> defaultRequestProperties = new HashMap<>(1);
defaultRequestProperties.put("Referer", "https://bitwave.tv");
dataSourceFactory.setDefaultRequestProperties(defaultRequestProperties);
mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mediaSourceUrl));
} else {
if (claimToPlay.getThumbnailUrl() != null && context != null) {
ImageView thumbnailView = root.findViewById(R.id.file_view_livestream_thumbnail);
Glide.with(context.getApplicationContext()).asBitmap().load(claimToPlay.getThumbnailUrl()).apply(RequestOptions.circleCropTransform()).into(thumbnailView);
}
root.findViewById(R.id.file_view_livestream_not_live).setVisibility(View.VISIBLE);
TextView userNotStreaming = root.findViewById(R.id.user_not_streaming);
userNotStreaming.setText(getString(R.string.user_not_live_yet, claimToPlay.getPublisherName()));
userNotStreaming.setVisibility(View.VISIBLE);
}
}
if (mediaSource != null) {
MainActivity.appPlayer.setMediaSource(mediaSource, true);
MainActivity.appPlayer.prepare();
}
}
}
}
}
use of com.google.android.exoplayer2.ui.PlayerView in project odysee-android by OdyseeTeam.
the class FileViewFragment method onEnterPIPMode.
public void onEnterPIPMode() {
View root = getView();
if (root != null) {
PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
playerView.setVisibility(View.GONE);
}
}
Aggregations