Changes for review

This commit is contained in:
Avently 2020-06-27 06:25:50 +03:00
parent 398cbe9284
commit a7fbe05a73
22 changed files with 182 additions and 350 deletions

View File

@ -38,9 +38,6 @@
<service
android:name=".player.BackgroundPlayer"
android:exported="false">
<!--<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>-->
</service>
<service

View File

@ -456,7 +456,10 @@ public class MainActivity extends AppCompatActivity {
FrameLayout bottomSheetLayout = findViewById(R.id.fragment_player_holder);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout);
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN || bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
final int sheetState = bottomSheetBehavior.getState();
// In case bottomSheet is not visible on the screen or collapsed we can assume that the user interacts with a fragment
// inside fragment_holder so all back presses should be handled by it
if (sheetState == BottomSheetBehavior.STATE_HIDDEN || sheetState == BottomSheetBehavior.STATE_COLLAPSED) {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press) delegate the back press to it
if (fragment instanceof BackPressable) {
@ -540,10 +543,6 @@ public class MainActivity extends AppCompatActivity {
super.onCreateOptionsMenu(menu);
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
if (!(fragment instanceof VideoDetailFragment)) {
findViewById(R.id.toolbar).findViewById(R.id.toolbar_spinner).setVisibility(View.GONE);
}
if (!(fragment instanceof SearchFragment)) {
findViewById(R.id.toolbar).findViewById(R.id.toolbar_search_container).setVisibility(View.GONE);

View File

@ -606,13 +606,8 @@ public class RouterActivity extends AppCompatActivity {
}
private void openMainPlayer(PlayQueue playQueue, Choice choice) {
Intent intent = NavigationHelper.getPlayerIntent(this, MainActivity.class, playQueue, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Constants.KEY_LINK_TYPE, choice.linkType);
intent.putExtra(Constants.KEY_URL, choice.url);
intent.putExtra(Constants.KEY_TITLE, "");
intent.putExtra(VideoDetailFragment.AUTO_PLAY, true);
this.startActivity(intent);
NavigationHelper.playOnMainPlayer(this, playQueue, choice.linkType,
choice.url, "", true, true);
}
@Override

View File

@ -5,7 +5,6 @@ import android.app.Activity;
import android.content.*;
import android.content.pm.ActivityInfo;
import android.database.ContentObserver;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -102,11 +101,8 @@ public class VideoDetailFragment
PlayerServiceEventListener {
public static final String AUTO_PLAY = "auto_play";
private int updateFlags = 0;
private static final int RELATED_STREAMS_UPDATE_FLAG = 0x1;
private static final int RESOLUTIONS_MENU_UPDATE_FLAG = 0x2;
private static final int TOOLBAR_ITEMS_UPDATE_FLAG = 0x4;
private static final int COMMENTS_UPDATE_FLAG = 0x8;
private static final int COMMENTS_UPDATE_FLAG = 0x2;
private static final float MAX_OVERLAY_ALPHA = 0.9f;
private static final float MAX_PLAYER_HEIGHT = 0.7f;
@ -115,10 +111,16 @@ public class VideoDetailFragment
public static final String ACTION_VIDEO_FRAGMENT_RESUMED = "org.schabi.newpipe.VideoDetailFragment.ACTION_VIDEO_FRAGMENT_RESUMED";
public static final String ACTION_VIDEO_FRAGMENT_STOPPED = "org.schabi.newpipe.VideoDetailFragment.ACTION_VIDEO_FRAGMENT_STOPPED";
private static final String COMMENTS_TAB_TAG = "COMMENTS";
private static final String RELATED_TAB_TAG = "NEXT VIDEO";
private static final String EMPTY_TAB_TAG = "EMPTY TAB";
private boolean showRelatedStreams;
private boolean showComments;
private String selectedTabTag;
private int updateFlags = 0;
@State
protected int serviceId = Constants.NO_SERVICE_ID;
@State
@ -148,10 +150,6 @@ public class VideoDetailFragment
// Views
//////////////////////////////////////////////////////////////////////////*/
private Menu menu;
private Spinner spinnerToolbar;
private LinearLayout contentRootLayoutHiding;
private View thumbnailBackgroundButton;
@ -195,10 +193,6 @@ public class VideoDetailFragment
private ImageButton overlayPlayPauseButton;
private ImageButton overlayCloseButton;
private static final String COMMENTS_TAB_TAG = "COMMENTS";
private static final String RELATED_TAB_TAG = "NEXT VIDEO";
private static final String EMPTY_TAB_TAG = "EMPTY TAB";
private AppBarLayout appBarLayout;
private ViewPager viewPager;
private TabAdaptor pageAdapter;
@ -207,7 +201,7 @@ public class VideoDetailFragment
private ContentObserver settingsContentObserver;
private ServiceConnection serviceConnection;
private boolean bounded;
private boolean bound;
private MainPlayer playerService;
private VideoPlayerImpl player;
@ -242,12 +236,18 @@ public class VideoDetailFragment
if (playerIsNotStopped() && player.videoPlayerSelected()) addVideoPlayerView();
// If the video is playing but orientation changed let's make the video in fullscreen again
if (isLandscape()) checkLandscape();
else if (player.isInFullscreen()) player.toggleFullscreen();
if (isLandscape()) {
// If the video is playing but orientation changed let's make the video in fullscreen again
checkLandscape();
} else if (player.isFullscreen()) {
// Device is in portrait orientation after rotation but UI is in fullscreen.
// Return back to non-fullscreen state
player.toggleFullscreen();
}
if (currentInfo != null && isAutoplayEnabled() && player.getParentActivity() == null || playAfterConnect)
if (playAfterConnect || (currentInfo != null && isAutoplayEnabled() && player.getParentActivity() == null)) {
openVideoPlayer();
}
}
};
}
@ -259,15 +259,15 @@ public class VideoDetailFragment
final boolean success = getContext().bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
if (!success) getContext().unbindService(serviceConnection);
bounded = success;
bound = success;
}
private void unbind() {
if (DEBUG) Log.d(TAG, "unbind() called");
if (bounded) {
if (bound) {
getContext().unbindService(serviceConnection);
bounded = false;
bound = false;
stopPlayerListener();
playerService = null;
player = null;
@ -313,9 +313,6 @@ public class VideoDetailFragment
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
showRelatedStreams = PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(getString(R.string.show_next_video_key), true);
@ -371,15 +368,9 @@ public class VideoDetailFragment
if (updateFlags != 0) {
if (!isLoading.get() && currentInfo != null) {
if ((updateFlags & RELATED_STREAMS_UPDATE_FLAG) != 0) startLoading(false);
if ((updateFlags & RESOLUTIONS_MENU_UPDATE_FLAG) != 0) setupActionBar(currentInfo);
if ((updateFlags & COMMENTS_UPDATE_FLAG) != 0) startLoading(false);
}
if ((updateFlags & TOOLBAR_ITEMS_UPDATE_FLAG) != 0
&& menu != null) {
updateMenuItemVisibility();
}
updateFlags = 0;
}
@ -418,14 +409,6 @@ public class VideoDetailFragment
bottomSheetBehavior.setBottomSheetCallback(null);
}
@Override
public void onDestroyView() {
if (DEBUG) Log.d(TAG, "onDestroyView() called");
spinnerToolbar.setOnItemSelectedListener(null);
spinnerToolbar.setAdapter(null);
super.onDestroyView();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@ -446,13 +429,6 @@ public class VideoDetailFragment
if (key.equals(getString(R.string.show_next_video_key))) {
showRelatedStreams = sharedPreferences.getBoolean(key, true);
updateFlags |= RELATED_STREAMS_UPDATE_FLAG;
} else if (key.equals(getString(R.string.default_video_format_key))
|| key.equals(getString(R.string.default_resolution_key))
|| key.equals(getString(R.string.show_higher_resolutions_key))
|| key.equals(getString(R.string.use_external_video_player_key))) {
updateFlags |= RESOLUTIONS_MENU_UPDATE_FLAG;
} else if (key.equals(getString(R.string.show_play_with_kodi_key))) {
updateFlags |= TOOLBAR_ITEMS_UPDATE_FLAG;
} else if (key.equals(getString(R.string.show_comments_key))) {
showComments = sharedPreferences.getBoolean(key, true);
updateFlags |= COMMENTS_UPDATE_FLAG;
@ -600,8 +576,6 @@ public class VideoDetailFragment
@Override
protected void initViews(View rootView, Bundle savedInstanceState) {
super.initViews(rootView, savedInstanceState);
spinnerToolbar = activity.findViewById(R.id.toolbar).findViewById(R.id.toolbar_spinner);
thumbnailBackgroundButton = rootView.findViewById(R.id.detail_thumbnail_root_layout);
thumbnailImageView = rootView.findViewById(R.id.detail_thumbnail_image_view);
thumbnailPlayButton = rootView.findViewById(R.id.detail_thumbnail_play_button);
@ -730,116 +704,6 @@ public class VideoDetailFragment
}
}
/*//////////////////////////////////////////////////////////////////////////
// Menu
//////////////////////////////////////////////////////////////////////////*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
this.menu = menu;
// CAUTION set item properties programmatically otherwise it would not be accepted by
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);
/*inflater.inflate(R.menu.video_detail_menu, menu);
updateMenuItemVisibility();
ActionBar supportActionBar = activity.getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setDisplayHomeAsUpEnabled(true);
supportActionBar.setDisplayShowTitleEnabled(false);
}*/
}
private void updateMenuItemVisibility() {
/*// show kodi if set in settings
menu.findItem(R.id.action_play_with_kodi).setVisible(
PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(
activity.getString(R.string.show_play_with_kodi_key), false));*/
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (isLoading.get()) {
// if is still loading block menu
return true;
}
int id = item.getItemId();
switch (id) {
case R.id.menu_item_share: {
if (currentInfo != null) {
ShareUtils.shareUrl(this.getContext(), currentInfo.getName(), currentInfo.getOriginalUrl());
}
return true;
}
case R.id.menu_item_openInBrowser: {
if (currentInfo != null) {
ShareUtils.openUrlInBrowser(this.getContext(), currentInfo.getOriginalUrl());
}
return true;
}
case R.id.action_play_with_kodi:
/*try {
NavigationHelper.playWithKore(activity, Uri.parse(
url.replace("https", "http")));
} catch (Exception e) {
if (DEBUG) Log.i(TAG, "Failed to start kore", e);
showInstallKoreDialog(activity);
}*/
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/*private static void showInstallKoreDialog(final Context context) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(R.string.kore_not_found)
.setPositiveButton(R.string.install, (DialogInterface dialog, int which) ->
NavigationHelper.installKore(context))
.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> {
});
builder.create().show();
}
private void setupActionBarOnError(final String url) {
if (DEBUG) Log.d(TAG, "setupActionBarHandlerOnError() called with: url = [" + url + "]");
Log.e("-----", "missing code");
}*/
private void setupActionBar(final StreamInfo info) {
if (DEBUG) Log.d(TAG, "setupActionBarHandler() called with: info = [" + info + "]");
boolean isExternalPlayerEnabled = PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(activity.getString(R.string.use_external_video_player_key), false);
sortedVideoStreams = ListHelper.getSortedStreamVideosList(
activity,
info.getVideoStreams(),
info.getVideoOnlyStreams(),
false);
selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(activity, sortedVideoStreams);
/*final StreamItemAdapter<VideoStream, Stream> streamsAdapter =
new StreamItemAdapter<>(activity,
new StreamSizeWrapper<>(sortedVideoStreams, activity), isExternalPlayerEnabled);
spinnerToolbar.setAdapter(streamsAdapter);
spinnerToolbar.setSelection(selectedVideoStreamIndex);
spinnerToolbar.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedVideoStreamIndex = position;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});*/
}
/*//////////////////////////////////////////////////////////////////////////
// OwnStack
//////////////////////////////////////////////////////////////////////////*/
@ -866,7 +730,7 @@ public class VideoDetailFragment
if (DEBUG) Log.d(TAG, "onBackPressed() called");
// If we are in fullscreen mode just exit from it via first back press
if (player != null && player.isInFullscreen()) {
if (player != null && player.isFullscreen()) {
if (!PlayerHelper.isTablet(activity)) player.onPause();
restoreDefaultOrientation();
setAutoplay(false);
@ -874,11 +738,10 @@ public class VideoDetailFragment
}
// If we have something in history of played items we replay it here
boolean isPreviousCanBePlayed = player != null
if (player != null
&& player.getPlayQueue() != null
&& player.videoPlayerSelected()
&& player.getPlayQueue().previous();
if (isPreviousCanBePlayed) {
&& player.getPlayQueue().previous()) {
return true;
}
// That means that we are on the start of the stack,
@ -930,9 +793,8 @@ public class VideoDetailFragment
}
public void selectAndLoadVideo(int serviceId, String videoUrl, String name, PlayQueue playQueue) {
boolean streamIsTheSame = this.playQueue != null && this.playQueue.equals(playQueue);
// Situation when user switches from players to main player. All needed data is here, we can start watching
if (streamIsTheSame) {
if (this.playQueue != null && this.playQueue.equals(playQueue)) {
openVideoPlayer();
return;
}
@ -1056,7 +918,7 @@ public class VideoDetailFragment
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
// If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode
if (player != null && player.isInFullscreen()) player.toggleFullscreen();
if (player != null && player.isFullscreen()) player.toggleFullscreen();
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
openNormalBackgroundPlayer(append);
@ -1072,18 +934,16 @@ public class VideoDetailFragment
}
// See UI changes while remote playQueue changes
if (!bounded) startService(false);
if (!bound) startService(false);
// If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode
if (player != null && player.isInFullscreen()) player.toggleFullscreen();
if (player != null && player.isFullscreen()) player.toggleFullscreen();
PlayQueue queue = setupPlayQueueForIntent(append);
if (append) {
NavigationHelper.enqueueOnPopupPlayer(activity, queue, false);
} else {
Runnable onAllow = () -> NavigationHelper.playOnPopupPlayer(activity, queue, true);
if (shouldAskBeforeClearingQueue()) showClearingQueueConfirmation(onAllow);
else onAllow.run();
replaceQueueIfUserConfirms(() -> NavigationHelper.playOnPopupPlayer(activity, queue, true));
}
}
@ -1093,27 +953,23 @@ public class VideoDetailFragment
VideoStream selectedVideoStream = getSelectedVideoStream();
startOnExternalPlayer(activity, currentInfo, selectedVideoStream);
} else {
Runnable onAllow = this::openNormalPlayer;
if (shouldAskBeforeClearingQueue()) showClearingQueueConfirmation(onAllow);
else onAllow.run();
replaceQueueIfUserConfirms(this::openMainPlayer);
}
}
private void openNormalBackgroundPlayer(final boolean append) {
// See UI changes while remote playQueue changes
if (!bounded) startService(false);
if (!bound) startService(false);
PlayQueue queue = setupPlayQueueForIntent(append);
if (append) {
NavigationHelper.enqueueOnBackgroundPlayer(activity, queue, false);
} else {
Runnable onAllow = () -> NavigationHelper.playOnBackgroundPlayer(activity, queue, true);
if (shouldAskBeforeClearingQueue()) showClearingQueueConfirmation(onAllow);
else onAllow.run();
replaceQueueIfUserConfirms(() -> NavigationHelper.playOnBackgroundPlayer(activity, queue, true));
}
}
private void openNormalPlayer() {
private void openMainPlayer() {
if (playerService == null) {
startService(true);
return;
@ -1144,7 +1000,7 @@ public class VideoDetailFragment
PlayQueue queue = playQueue;
// Size can be 0 because queue removes bad stream automatically when error occurs
if (playQueue == null || playQueue.size() == 0)
if (queue == null || queue.size() == 0)
queue = new SinglePlayQueue(currentInfo);
return queue;
@ -1284,18 +1140,18 @@ public class VideoDetailFragment
boolean isPortrait = metrics.heightPixels > metrics.widthPixels;
int height;
if (player != null && player.isInFullscreen())
if (player != null && player.isFullscreen())
height = isInMultiWindow() ? getView().getHeight() : activity.getWindow().getDecorView().getHeight();
else
height = isPortrait
? (int) (metrics.widthPixels / (16.0f / 9.0f))
: (int) (metrics.heightPixels / 2f);
: (int) (metrics.heightPixels / 2.0f);
thumbnailImageView.setLayoutParams(new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height));
thumbnailImageView.setMinimumHeight(height);
if (player != null) {
int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT);
player.getSurfaceView().setHeights(height, player.isInFullscreen() ? height : maxHeight);
player.getSurfaceView().setHeights(height, player.isFullscreen() ? height : maxHeight);
}
}
@ -1353,7 +1209,7 @@ public class VideoDetailFragment
private void restoreDefaultOrientation() {
if (player == null || !player.videoPlayerSelected() || activity == null) return;
if (player != null && player.isInFullscreen()) player.toggleFullscreen();
if (player != null && player.isFullscreen()) player.toggleFullscreen();
// This will show systemUI and pause the player.
// User can tap on Play button and video will be in fullscreen mode again
// Note for tablet: trying to avoid orientation changes since it's not easy to physically rotate the tablet every time
@ -1375,7 +1231,6 @@ public class VideoDetailFragment
contentRootLayoutHiding.setVisibility(View.INVISIBLE);
}
//animateView(spinnerToolbar, false, 200);
animateView(thumbnailPlayButton, false, 50);
animateView(detailDurationView, false, 100);
animateView(detailPositionView, false, 100);
@ -1392,7 +1247,7 @@ public class VideoDetailFragment
if(relatedStreamsLayout != null){
if(showRelatedStreams){
relatedStreamsLayout.setVisibility(player != null && player.isInFullscreen() ? View.GONE : View.INVISIBLE);
relatedStreamsLayout.setVisibility(player != null && player.isFullscreen() ? View.GONE : View.INVISIBLE);
}else{
relatedStreamsLayout.setVisibility(View.GONE);
}
@ -1419,7 +1274,7 @@ public class VideoDetailFragment
getChildFragmentManager().beginTransaction()
.replace(R.id.relatedStreamsLayout, RelatedVideosFragment.getInstance(info))
.commitNow();
relatedStreamsLayout.setVisibility(player != null && player.isInFullscreen() ? View.GONE : View.VISIBLE);
relatedStreamsLayout.setVisibility(player != null && player.isFullscreen() ? View.GONE : View.VISIBLE);
}
}
@ -1506,9 +1361,6 @@ public class VideoDetailFragment
prepareDescription(info.getDescription());
updateProgressInfo(info);
//animateView(spinnerToolbar, true, 500);
setupActionBar(info);
initThumbnailViews(info);
if (player == null || player.isPlayerStopped())
@ -1527,7 +1379,6 @@ public class VideoDetailFragment
case LIVE_STREAM:
case AUDIO_LIVE_STREAM:
detailControlsDownload.setVisibility(View.GONE);
spinnerToolbar.setVisibility(View.GONE);
break;
default:
if(info.getAudioStreams().isEmpty()) detailControlsBackground.setVisibility(View.GONE);
@ -1535,7 +1386,6 @@ public class VideoDetailFragment
|| !info.getVideoOnlyStreams().isEmpty()) break;
detailControlsPopup.setVisibility(View.GONE);
spinnerToolbar.setVisibility(View.GONE);
thumbnailPlayButton.setImageResource(R.drawable.ic_headset_white_24dp);
break;
}
@ -1629,8 +1479,8 @@ public class VideoDetailFragment
}, e -> {
if (DEBUG) e.printStackTrace();
}, () -> {
animateView(positionView, false, 0);
animateView(detailPositionView, false, 0);
positionView.setVisibility(View.GONE);
detailPositionView.setVisibility(View.GONE);
});
}
@ -1653,15 +1503,16 @@ public class VideoDetailFragment
@Override
public void onQueueUpdate(PlayQueue queue) {
playQueue = queue;
StackItem stackWithQueue;
// This should be the only place where we push data to stack. It will allow to have live instance of PlayQueue with actual
// information about deleted/added items inside Channel/Playlist queue and makes possible to have a history of played items
if (stack.isEmpty() || !stack.peek().getPlayQueue().equals(queue)) {
stack.push(new StackItem(serviceId, url, name, playQueue));
} else if (findQueueInStack(queue) != null) {
} else if ((stackWithQueue = findQueueInStack(queue)) != null) {
// On every MainPlayer service's destroy() playQueue gets disposed and no longer able to track progress.
// That's why we update our cached disposed queue with the new one that is active and have the same history
// Without that the cached playQueue will have an old recovery position
findQueueInStack(queue).setPlayQueue(queue);
stackWithQueue.setPlayQueue(queue);
}
if (DEBUG) {
@ -1679,7 +1530,7 @@ public class VideoDetailFragment
restoreDefaultOrientation();
break;
case BasePlayer.STATE_PLAYING:
if (positionView.getAlpha() != 1f
if (positionView.getAlpha() != 1.0f
&& player.getPlayQueue() != null
&& player.getPlayQueue().getItem() != null
&& player.getPlayQueue().getItem().getUrl().equals(url)) {
@ -1725,7 +1576,7 @@ public class VideoDetailFragment
public void onPlayerError(ExoPlaybackException error) {
if (error.type == ExoPlaybackException.TYPE_SOURCE || error.type == ExoPlaybackException.TYPE_UNEXPECTED) {
hideMainPlayer();
if (playerService != null && player.isInFullscreen())
if (playerService != null && player.isFullscreen())
player.toggleFullscreen();
}
}
@ -1824,7 +1675,7 @@ public class VideoDetailFragment
// Listener implementation
public void hideSystemUiIfNeeded() {
if (player != null && player.isInFullscreen() && bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
if (player != null && player.isFullscreen() && bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
hideSystemUi();
}
@ -1897,11 +1748,19 @@ public class VideoDetailFragment
return item;
}
private boolean shouldAskBeforeClearingQueue() {
PlayQueue activeQueue = player != null ? player.getPlayQueue() : null;
private void replaceQueueIfUserConfirms(final Runnable onAllow) {
@Nullable final PlayQueue activeQueue = player == null ? null : player.getPlayQueue();
// Player will have STATE_IDLE when a user pressed back button
return isClearingQueueConfirmationRequired(activity) && playerIsNotStopped()
&& activeQueue != null && !activeQueue.equals(playQueue) && activeQueue.getStreams().size() > 1;
if (isClearingQueueConfirmationRequired(activity)
&& playerIsNotStopped()
&& activeQueue != null
&& !activeQueue.equals(playQueue)
&& activeQueue.getStreams().size() > 1) {
showClearingQueueConfirmation(onAllow);
} else {
onAllow.run();
}
}
private void showClearingQueueConfirmation(Runnable onAllow) {
@ -1964,13 +1823,13 @@ public class VideoDetailFragment
// Disable click because overlay buttons located on top of buttons from the player
setOverlayElementsClickable(false);
hideSystemUiIfNeeded();
boolean needToExpand = isLandscape()
// Conditions when the player should be expanded to fullscreen
if (isLandscape()
&& player != null
&& player.isPlaying()
&& !player.isInFullscreen()
&& !player.isFullscreen()
&& !PlayerHelper.isTablet(activity)
&& player.videoPlayerSelected();
if (needToExpand) player.toggleFullscreen();
&& player.videoPlayerSelected()) player.toggleFullscreen();
break;
case BottomSheetBehavior.STATE_COLLAPSED:
// Re-enable clicks
@ -1979,7 +1838,7 @@ public class VideoDetailFragment
break;
case BottomSheetBehavior.STATE_DRAGGING:
case BottomSheetBehavior.STATE_SETTLING:
if (player != null && player.isInFullscreen()) showSystemUi();
if (player != null && player.isFullscreen()) showSystemUi();
if (player != null && player.isControlsVisible()) player.hideControls(0, 0);
break;
}
@ -1997,8 +1856,8 @@ public class VideoDetailFragment
}
private void updateOverlayData(@Nullable String title, @Nullable String uploader, @Nullable String thumbnailUrl) {
overlayTitleTextView.setText(!TextUtils.isEmpty(title) ? title : "");
overlayChannelTextView.setText(!TextUtils.isEmpty(uploader) ? uploader : "");
overlayTitleTextView.setText(TextUtils.isEmpty(title) ? "" : title);
overlayChannelTextView.setText(TextUtils.isEmpty(uploader) ? "" : uploader);
overlayThumbnailImageView.setImageResource(R.drawable.dummy_thumbnail_dark);
if (!TextUtils.isEmpty(thumbnailUrl))
imageLoader.displayImage(thumbnailUrl, overlayThumbnailImageView,
@ -2006,8 +1865,7 @@ public class VideoDetailFragment
}
private void setOverlayPlayPauseImage() {
boolean playing = player != null && player.getPlayer().getPlayWhenReady();
int attr = playing ? R.attr.pause : R.attr.play;
int attr = player != null && player.getPlayer().getPlayWhenReady() ? R.attr.pause : R.attr.play;
overlayPlayPauseButton.setImageResource(ThemeHelper.resolveResourceIdFromAttr(activity, attr));
}

View File

@ -436,16 +436,16 @@ public class SearchFragment
if (TextUtils.isEmpty(searchString) || TextUtils.isEmpty(searchEditText.getText())) {
searchToolbarContainer.setTranslationX(100);
searchToolbarContainer.setAlpha(0f);
searchToolbarContainer.setAlpha(0.0f);
searchToolbarContainer.setVisibility(View.VISIBLE);
searchToolbarContainer.animate()
.translationX(0)
.alpha(1f)
.alpha(1.0f)
.setDuration(200)
.setInterpolator(new DecelerateInterpolator()).start();
} else {
searchToolbarContainer.setTranslationX(0);
searchToolbarContainer.setAlpha(1f);
searchToolbarContainer.setAlpha(1.0f);
searchToolbarContainer.setVisibility(View.VISIBLE);
}
}

View File

@ -337,7 +337,7 @@ public final class BackgroundPlayer extends Service {
@Override
public void onPrepared(boolean playWhenReady) {
super.onPrepared(playWhenReady);
simpleExoPlayer.setVolume(1f);
simpleExoPlayer.setVolume(1.0f);
}
@Override

View File

@ -158,7 +158,7 @@ public abstract class BasePlayer implements
// Playback
//////////////////////////////////////////////////////////////////////////*/
protected static final float[] PLAYBACK_SPEEDS = {0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f};
protected static final float[] PLAYBACK_SPEEDS = {0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f};
protected PlayQueue playQueue;
protected PlayQueueAdapter playQueueAdapter;
@ -227,7 +227,7 @@ public abstract class BasePlayer implements
public void setup() {
if (simpleExoPlayer == null) {
initPlayer(/*playOnInit=*/true);
initPlayer(true);
}
initListeners();
}
@ -274,7 +274,7 @@ public abstract class BasePlayer implements
return;
}
boolean same = playQueue != null && playQueue.equals(queue);
boolean samePlayQueue = playQueue != null && playQueue.equals(queue);
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
final float playbackSpeed = intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed());
@ -282,6 +282,14 @@ public abstract class BasePlayer implements
final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE,
getPlaybackSkipSilence());
/*
* There are 3 situations when playback shouldn't be started from scratch (zero timestamp):
* 1. User pressed on a timestamp link and the same video should be rewound to that timestamp
* 2. User changed a player from, for example. main to popup, or from audio to main, etc
* 3. User chose to resume a video based on a saved timestamp from history of played videos
* In those cases time will be saved because re-init of the play queue is a not an instant task
* and requires network calls
* */
// seek to timestamp if stream is already playing
if (simpleExoPlayer != null
&& queue.size() == 1
@ -289,21 +297,20 @@ public abstract class BasePlayer implements
&& playQueue.size() == 1
&& playQueue.getItem() != null
&& queue.getItem().getUrl().equals(playQueue.getItem().getUrl())
&& queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET
&& simpleExoPlayer.getPlaybackState() != Player.STATE_IDLE) {
&& queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET) {
// Player can have state = IDLE when playback is stopped or failed and we should retry() in this case
if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) simpleExoPlayer.retry();
simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition());
return;
} else if (same && !playQueue.isDisposed() && simpleExoPlayer != null) {
} else if (samePlayQueue && !playQueue.isDisposed() && simpleExoPlayer != null) {
// Do not re-init the same PlayQueue. Save time
// Player can have state = IDLE when playback is stopped or failed and we should retry() in this case
if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) simpleExoPlayer.retry();
return;
} else if (intent.getBooleanExtra(RESUME_PLAYBACK, false)
&& isPlaybackResumeEnabled()
&& !same) {
&& !samePlayQueue) {
final PlayQueueItem item = queue.getItem();
if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET) {
stateLoader = recordManager.loadStreamState(item)
@ -313,19 +320,16 @@ public abstract class BasePlayer implements
.subscribe(
state -> {
queue.setRecovery(queue.getIndex(), state.getProgressTime());
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true);
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true);
},
error -> {
if (DEBUG) error.printStackTrace();
// In case any error we can start playback without history
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true);
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true);
},
() -> {
// Completed but not found in history
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true);
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true);
}
);
databaseUpdateReactor.add(stateLoader);
@ -334,8 +338,7 @@ public abstract class BasePlayer implements
}
// Good to go...
// In a case of equal PlayQueues we can re-init old one but only when it is disposed
initPlayback(same ? playQueue : queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true);
initPlayback(samePlayQueue ? playQueue : queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true);
}
protected void initPlayback(@NonNull final PlayQueue queue,

View File

@ -184,8 +184,6 @@ public final class MainPlayer extends Service {
playerImpl.destroy();
}
if (notificationManager != null) notificationManager.cancel(NOTIFICATION_ID);
playerImpl = null;
lockManager = null;
stopForeground(true);
stopSelf();
@ -197,7 +195,7 @@ public final class MainPlayer extends Service {
boolean isLandscape() {
// DisplayMetrics from activity context knows about MultiWindow feature while DisplayMetrics from app context doesn't
final DisplayMetrics metrics = playerImpl != null && playerImpl.getParentActivity() != null ?
final DisplayMetrics metrics = (playerImpl != null && playerImpl.getParentActivity() != null) ?
playerImpl.getParentActivity().getResources().getDisplayMetrics()
: getResources().getDisplayMetrics();
return metrics.heightPixels < metrics.widthPixels;

View File

@ -797,9 +797,9 @@ public abstract class VideoPlayer extends BasePlayer
if (drawableId == -1) {
if (controlAnimationView.getVisibility() == View.VISIBLE) {
controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView,
PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f),
PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1f),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1f)
PropertyValuesHolder.ofFloat(View.ALPHA, 1.0f, 0.0f),
PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1.0f),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1.0f)
).setDuration(DEFAULT_CONTROLS_DURATION);
controlViewAnimator.addListener(new AnimatorListenerAdapter() {
@Override
@ -812,8 +812,8 @@ public abstract class VideoPlayer extends BasePlayer
return;
}
float scaleFrom = goneOnEnd ? 1f : 1f, scaleTo = goneOnEnd ? 1.8f : 1.4f;
float alphaFrom = goneOnEnd ? 1f : 0f, alphaTo = goneOnEnd ? 0f : 1f;
float scaleFrom = goneOnEnd ? 1.0f : 1.0f, scaleTo = goneOnEnd ? 1.8f : 1.4f;
float alphaFrom = goneOnEnd ? 1.0f : 0.0f, alphaTo = goneOnEnd ? 0.0f : 1.0f;
controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView,

View File

@ -270,14 +270,14 @@ public class VideoPlayerImpl extends VideoPlayer
final float captionScale,
@NonNull final CaptionStyleCompat captionStyle) {
if (popupPlayerSelected()) {
float captionRatio = (captionScale - 1f) / 5f + 1f;
float captionRatio = (captionScale - 1.0f) / 5.0f + 1.0f;
view.setFractionalTextSize(SubtitleView.DEFAULT_TEXT_SIZE_FRACTION * captionRatio);
view.setApplyEmbeddedStyles(captionStyle.equals(CaptionStyleCompat.DEFAULT));
view.setStyle(captionStyle);
} else {
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels);
final float captionRatioInverse = 20f + 4f * (1f - captionScale);
final float captionRatioInverse = 20f + 4f * (1.0f - captionScale);
view.setFixedTextSize(TypedValue.COMPLEX_UNIT_PX,
(float) minimumLength / captionRatioInverse);
view.setApplyEmbeddedStyles(captionStyle.equals(CaptionStyleCompat.DEFAULT));
@ -300,7 +300,7 @@ public class VideoPlayerImpl extends VideoPlayer
moreOptionsButton.setVisibility(View.GONE);
getTopControlsRoot().setOrientation(LinearLayout.HORIZONTAL);
primaryControls.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
secondaryControls.setAlpha(1f);
secondaryControls.setAlpha(1.0f);
secondaryControls.setVisibility(View.VISIBLE);
secondaryControls.setTranslationY(0);
shareButton.setVisibility(View.GONE);
@ -333,7 +333,7 @@ public class VideoPlayerImpl extends VideoPlayer
getTopControlsRoot().setClickable(true);
getTopControlsRoot().setFocusable(true);
}
if (!isInFullscreen()) {
if (!isFullscreen()) {
titleTextView.setVisibility(View.GONE);
channelTextView.setVisibility(View.GONE);
} else {
@ -602,10 +602,10 @@ public class VideoPlayerImpl extends VideoPlayer
isFullscreen = !isFullscreen;
setControlsSize();
fragmentListener.onFullscreenStateChanged(isInFullscreen());
fragmentListener.onFullscreenStateChanged(isFullscreen());
}
if (!isInFullscreen()) {
if (!isFullscreen()) {
titleTextView.setVisibility(View.GONE);
channelTextView.setVisibility(View.GONE);
playerCloseButton.setVisibility(videoPlayerSelected() ? View.VISIBLE : View.GONE);
@ -674,7 +674,7 @@ public class VideoPlayerImpl extends VideoPlayer
@Override
public boolean onLongClick(View v) {
if (v.getId() == moreOptionsButton.getId() && isInFullscreen()) {
if (v.getId() == moreOptionsButton.getId() && isFullscreen()) {
fragmentListener.onMoreOptionsLongClicked();
hideControls(0, 0);
hideSystemUIIfNeeded();
@ -690,7 +690,7 @@ public class VideoPlayerImpl extends VideoPlayer
updatePlaybackButtons();
getControlsRoot().setVisibility(View.INVISIBLE);
animateView(queueLayout, SLIDE_AND_ALPHA, /*visible=*/true,
animateView(queueLayout, SLIDE_AND_ALPHA,true,
DEFAULT_CONTROLS_DURATION);
itemsList.scrollToPosition(playQueue.getIndex());
@ -699,7 +699,7 @@ public class VideoPlayerImpl extends VideoPlayer
public void onQueueClosed() {
if (!queueVisible) return;
animateView(queueLayout, SLIDE_AND_ALPHA, /*visible=*/false,
animateView(queueLayout, SLIDE_AND_ALPHA,false,
DEFAULT_CONTROLS_DURATION, 0, () -> {
// Even when queueLayout is GONE it receives touch events and ruins normal behavior of the app. This line fixes it
queueLayout.setTranslationY(-queueLayout.getHeight() * 5);
@ -765,12 +765,12 @@ public class VideoPlayerImpl extends VideoPlayer
boolean showButton = videoPlayerSelected() && (orientationLocked || isVerticalVideo || tabletInLandscape);
screenRotationButton.setVisibility(showButton ? View.VISIBLE : View.GONE);
screenRotationButton.setImageDrawable(service.getResources().getDrawable(
isInFullscreen() ? R.drawable.ic_fullscreen_exit_white : R.drawable.ic_fullscreen_white));
isFullscreen() ? R.drawable.ic_fullscreen_exit_white : R.drawable.ic_fullscreen_white));
}
private void prepareOrientation() {
boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service);
if (orientationLocked && isInFullscreen() && service.isLandscape() == isVerticalVideo && fragmentListener != null)
if (orientationLocked && isFullscreen() && service.isLandscape() == isVerticalVideo && fragmentListener != null)
fragmentListener.onScreenRotationButtonClicked();
}
@ -893,7 +893,7 @@ public class VideoPlayerImpl extends VideoPlayer
@Override
public void onBlocked() {
super.onBlocked();
playPauseButton.setImageResource(R.drawable.ic_pause_white);
playPauseButton.setImageResource(R.drawable.ic_play_arrow_white);
animatePlayButtons(false, 100);
getRootView().setKeepScreenOn(false);
@ -1185,7 +1185,7 @@ public class VideoPlayerImpl extends VideoPlayer
return distanceFromCloseButton(popupMotionEvent) <= getClosingRadius();
}
public boolean isInFullscreen() {
public boolean isFullscreen() {
return isFullscreen;
}
@ -1216,8 +1216,7 @@ public class VideoPlayerImpl extends VideoPlayer
getControlsVisibilityHandler().removeCallbacksAndMessages(null);
getControlsVisibilityHandler().postDelayed(() ->
animateView(getControlsRoot(), false, duration, 0,
this::hideSystemUIIfNeeded),
/*delayMillis=*/delay
this::hideSystemUIIfNeeded), delay
);
}
@ -1225,24 +1224,13 @@ public class VideoPlayerImpl extends VideoPlayer
if (playQueue == null)
return;
if (playQueue.getIndex() == 0)
playPreviousButton.setVisibility(View.INVISIBLE);
else
playPreviousButton.setVisibility(View.VISIBLE);
if (playQueue.getIndex() + 1 == playQueue.getStreams().size())
playNextButton.setVisibility(View.INVISIBLE);
else
playNextButton.setVisibility(View.VISIBLE);
if (playQueue.getStreams().size() <= 1 || popupPlayerSelected())
queueButton.setVisibility(View.GONE);
else
queueButton.setVisibility(View.VISIBLE);
playPreviousButton.setVisibility(playQueue.getIndex() == 0 ? View.INVISIBLE : View.VISIBLE);
playNextButton.setVisibility(playQueue.getIndex() + 1 == playQueue.getStreams().size() ? View.INVISIBLE : View.VISIBLE);
queueButton.setVisibility(playQueue.getStreams().size() <= 1 || popupPlayerSelected() ? View.GONE : View.VISIBLE);
}
private void showSystemUIPartially() {
if (isInFullscreen() && getParentActivity() != null) {
if (isFullscreen() && getParentActivity() != null) {
int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
getParentActivity().getWindow().getDecorView().setSystemUiVisibility(visibility);
}
@ -1330,7 +1318,7 @@ public class VideoPlayerImpl extends VideoPlayer
public void checkLandscape() {
AppCompatActivity parent = getParentActivity();
boolean videoInLandscapeButNotInFullscreen = service.isLandscape() && !isInFullscreen() && videoPlayerSelected() && !audioOnly;
boolean videoInLandscapeButNotInFullscreen = service.isLandscape() && !isFullscreen() && videoPlayerSelected() && !audioOnly;
boolean playingState = getCurrentState() != STATE_COMPLETED && getCurrentState() != STATE_PAUSED;
if (parent != null && videoInLandscapeButNotInFullscreen && playingState && !PlayerHelper.isTablet(service))
toggleFullscreen();
@ -1421,7 +1409,7 @@ public class VideoPlayerImpl extends VideoPlayer
if (DEBUG) Log.d(TAG, "initPopup() called");
// Popup is already added to windowManager
if (isPopupHasParent()) return;
if (popupHasParent()) return;
updateScreenSize();
@ -1430,13 +1418,10 @@ public class VideoPlayerImpl extends VideoPlayer
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(service);
popupWidth = popupRememberSizeAndPos ? sharedPreferences.getFloat(POPUP_SAVED_WIDTH, defaultSize) : defaultSize;
popupHeight = getMinimumVideoHeight(popupWidth);
final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ?
WindowManager.LayoutParams.TYPE_PHONE :
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
popupLayoutParams = new WindowManager.LayoutParams(
(int) popupWidth, (int) popupHeight,
layoutParamType,
popupLayoutParamType(),
IDLE_WINDOW_FLAGS,
PixelFormat.TRANSLUCENT);
popupLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
@ -1470,15 +1455,12 @@ public class VideoPlayerImpl extends VideoPlayer
closeOverlayView = View.inflate(service, R.layout.player_popup_close_overlay, null);
closeOverlayButton = closeOverlayView.findViewById(R.id.closeButton);
final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ?
WindowManager.LayoutParams.TYPE_PHONE :
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
final int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
WindowManager.LayoutParams closeOverlayLayoutParams = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
layoutParamType,
popupLayoutParamType(),
flags,
PixelFormat.TRANSLUCENT);
closeOverlayLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
@ -1600,6 +1582,12 @@ public class VideoPlayerImpl extends VideoPlayer
windowManager.updateViewLayout(getRootView(), popupLayoutParams);
}
private int popupLayoutParamType() {
return Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ?
WindowManager.LayoutParams.TYPE_PHONE :
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
/*//////////////////////////////////////////////////////////////////////////
// Misc
//////////////////////////////////////////////////////////////////////////*/
@ -1617,7 +1605,7 @@ public class VideoPlayerImpl extends VideoPlayer
public void removePopupFromView() {
boolean isCloseOverlayHasParent = closeOverlayView != null && closeOverlayView.getParent() != null;
if (isPopupHasParent())
if (popupHasParent())
windowManager.removeView(getRootView());
if (isCloseOverlayHasParent)
windowManager.removeView(closeOverlayView);
@ -1651,7 +1639,7 @@ public class VideoPlayerImpl extends VideoPlayer
}).start();
}
private boolean isPopupHasParent() {
private boolean popupHasParent() {
View root = getRootView();
return root != null && root.getLayoutParams() instanceof WindowManager.LayoutParams && root.getParent() != null;
}

View File

@ -160,10 +160,7 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen
isMovingInMain = true;
boolean acceptVolumeArea = initialEvent.getX() > playerImpl.getRootView().getWidth() / 2.0;
boolean acceptBrightnessArea = initialEvent.getX() <= playerImpl.getRootView().getWidth() / 2.0;
if (isVolumeGestureEnabled && acceptVolumeArea) {
if (isVolumeGestureEnabled && initialEvent.getX() > playerImpl.getRootView().getWidth() / 2.0) {
playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY);
float currentProgressPercent =
(float) playerImpl.getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength();
@ -172,14 +169,11 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen
if (DEBUG) Log.d(TAG, "onScroll().volumeControl, currentVolume = " + currentVolume);
final int resId =
currentProgressPercent <= 0 ? R.drawable.ic_volume_off_white_72dp
playerImpl.getVolumeImageView().setImageDrawable(
AppCompatResources.getDrawable(service, currentProgressPercent <= 0 ? R.drawable.ic_volume_off_white_72dp
: currentProgressPercent < 0.25 ? R.drawable.ic_volume_mute_white_72dp
: currentProgressPercent < 0.75 ? R.drawable.ic_volume_down_white_72dp
: R.drawable.ic_volume_up_white_72dp;
playerImpl.getVolumeImageView().setImageDrawable(
AppCompatResources.getDrawable(service, resId)
: R.drawable.ic_volume_up_white_72dp)
);
if (playerImpl.getVolumeRelativeLayout().getVisibility() != View.VISIBLE) {
@ -188,7 +182,7 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen
if (playerImpl.getBrightnessRelativeLayout().getVisibility() == View.VISIBLE) {
playerImpl.getBrightnessRelativeLayout().setVisibility(View.GONE);
}
} else if (isBrightnessGestureEnabled && acceptBrightnessArea) {
} else if (isBrightnessGestureEnabled && initialEvent.getX() <= playerImpl.getRootView().getWidth() / 2.0) {
Activity parent = playerImpl.getParentActivity();
if (parent == null) return true;
@ -203,13 +197,11 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen
if (DEBUG) Log.d(TAG, "onScroll().brightnessControl, currentBrightness = " + currentProgressPercent);
final int resId =
currentProgressPercent < 0.25 ? R.drawable.ic_brightness_low_white_72dp
: currentProgressPercent < 0.75 ? R.drawable.ic_brightness_medium_white_72dp
: R.drawable.ic_brightness_high_white_72dp;
playerImpl.getBrightnessImageView().setImageDrawable(
AppCompatResources.getDrawable(service, resId)
AppCompatResources.getDrawable(service,
currentProgressPercent < 0.25 ? R.drawable.ic_brightness_low_white_72dp
: currentProgressPercent < 0.75 ? R.drawable.ic_brightness_medium_white_72dp
: R.drawable.ic_brightness_high_white_72dp)
);
if (playerImpl.getBrightnessRelativeLayout().getVisibility() != View.VISIBLE) {
@ -247,7 +239,7 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
v.getParent().requestDisallowInterceptTouchEvent(playerImpl.isInFullscreen());
v.getParent().requestDisallowInterceptTouchEvent(playerImpl.isFullscreen());
return true;
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);

View File

@ -114,7 +114,7 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener,
private void onAudioFocusGain() {
Log.d(TAG, "onAudioFocusGain() called");
player.setVolume(DUCK_AUDIO_TO);
animateAudio(DUCK_AUDIO_TO, 1f);
animateAudio(DUCK_AUDIO_TO, 1.0f);
if (PlayerHelper.isResumeAfterAudioFocusGain(context)) {
player.setPlayWhenReady(true);

View File

@ -222,14 +222,10 @@ public class PlayerHelper {
@AutoplayType
public static int getAutoplayType(@NonNull final Context context) {
final String defaultType = context.getString(R.string.autoplay_wifi_key);
final String always = context.getString(R.string.autoplay_always_key);
final String never = context.getString(R.string.autoplay_never_key);
final String type = getAutoplayType(context, defaultType);
if (type.equals(always)) {
final String type = getAutoplayType(context, context.getString(R.string.autoplay_wifi_key));
if (type.equals(context.getString(R.string.autoplay_always_key))) {
return AUTOPLAY_TYPE_ALWAYS;
} else if (type.equals(never)) {
} else if (type.equals(context.getString(R.string.autoplay_never_key))) {
return AUTOPLAY_TYPE_NEVER;
} else {
return AUTOPLAY_TYPE_WIFI;
@ -307,12 +303,12 @@ public class PlayerHelper {
* Very small - 0.25f, Small - 0.5f, Normal - 1.0f, Large - 1.5f, Very Large - 2.0f
* */
public static float getCaptionScale(@NonNull final Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return 1f;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return 1.0f;
final CaptioningManager captioningManager = (CaptioningManager)
context.getSystemService(Context.CAPTIONING_SERVICE);
if (captioningManager == null || !captioningManager.isEnabled()) {
return 1f;
return 1.0f;
}
return captioningManager.getFontScale();
@ -330,8 +326,8 @@ public class PlayerHelper {
public static boolean globalScreenOrientationLocked(Context context) {
// 1: Screen orientation changes using accelerometer
// 0: Screen orientation is locked
return !(android.provider.Settings.System.getInt(
context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1);
return android.provider.Settings.System.getInt(
context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 0;
}
public static boolean isTablet(@NonNull final Context context) {

View File

@ -158,7 +158,7 @@ public class OggFromWebMWriter implements Closeable {
switch (webm_track.kind) {
case Audio:
resolution = getSampleFrequencyFromTrack(webm_track.bMetadata);
if (resolution == 0f) {
if (resolution == 0.0f) {
throw new RuntimeException("cannot get the audio sample rate");
}
break;
@ -167,7 +167,7 @@ public class OggFromWebMWriter implements Closeable {
if (webm_track.defaultDuration == 0) {
throw new RuntimeException("missing default frame time");
}
resolution = 1000f / ((float) webm_track.defaultDuration / webm_segment.info.timecodeScale);
resolution = 1000.0f / ((float) webm_track.defaultDuration / webm_segment.info.timecodeScale);
break;
default:
throw new RuntimeException("not implemented");
@ -358,7 +358,7 @@ public class OggFromWebMWriter implements Closeable {
}
}
return 0f;
return 0.0f;
}
private void clearSegmentTable() {

View File

@ -292,7 +292,7 @@ public class SubtitleConverter {
time += Integer.parseInt(units[0]) * 3600000;// hours
time += Integer.parseInt(units[1]) * 60000;//minutes
time += Float.parseFloat(units[2]) * 1000f;// seconds and milliseconds (if present)
time += Float.parseFloat(units[2]) * 1000.0f;// seconds and milliseconds (if present)
// frames and sub-frames are ignored (not implemented)
// time += units[3] * fps;

View File

@ -612,7 +612,7 @@ public class WebMWriter implements Closeable {
int offset = withLength ? 1 : 0;
byte[] buffer = new byte[offset + length];
long marker = (long) Math.floor((length - 1f) / 8f);
long marker = (long) Math.floor((length - 1.0f) / 8.0f);
float mul = 1;
for (int i = length - 1; i >= 0; i--, mul *= 0x100) {

View File

@ -73,9 +73,7 @@ public class NavigationHelper {
if (cacheKey != null) intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey);
if (quality != null) intent.putExtra(VideoPlayer.PLAYBACK_QUALITY, quality);
intent.putExtra(VideoPlayer.RESUME_PLAYBACK, resumePlayback);
int playerType = intent.getIntExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO);
intent.putExtra(VideoPlayer.PLAYER_TYPE, playerType);
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO);
return intent;
}
@ -122,7 +120,24 @@ public class NavigationHelper {
public static void playOnMainPlayer(final FragmentManager fragmentManager, final PlayQueue queue, boolean autoPlay) {
PlayQueueItem currentStream = queue.getItem();
NavigationHelper.openVideoDetailFragment(fragmentManager, currentStream.getServiceId(), currentStream.getUrl(), currentStream.getTitle(), autoPlay, queue);
openVideoDetailFragment(fragmentManager, currentStream.getServiceId(), currentStream.getUrl(), currentStream.getTitle(), autoPlay, queue);
}
public static void playOnMainPlayer(@NonNull final Context context,
@NonNull final PlayQueue queue,
@NonNull final StreamingService.LinkType linkType,
@NonNull final String url,
@NonNull final String title,
final boolean autoPlay,
final boolean resumePlayback) {
Intent intent = getPlayerIntent(context, MainActivity.class, queue, resumePlayback);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Constants.KEY_LINK_TYPE, linkType);
intent.putExtra(Constants.KEY_URL, url);
intent.putExtra(Constants.KEY_TITLE, title);
intent.putExtra(VideoDetailFragment.AUTO_PLAY, autoPlay);
context.startActivity(intent);
}
public static void playOnPopupPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {

View File

@ -11,7 +11,7 @@ public class ExpandableSurfaceView extends SurfaceView {
private int resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT;
private int baseHeight = 0;
private int maxHeight = 0;
private float videoAspectRatio = 0f;
private float videoAspectRatio = 0.0f;
private float scaleX = 1.0f;
private float scaleY = 1.0f;
@ -22,7 +22,7 @@ public class ExpandableSurfaceView extends SurfaceView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (videoAspectRatio == 0f) return;
if (videoAspectRatio == 0.0f) return;
int width = MeasureSpec.getSize(widthMeasureSpec);
boolean verticalVideo = videoAspectRatio < 1;

View File

@ -89,7 +89,7 @@ public abstract class Postprocessing implements Serializable {
}
public void setTemporalDir(@NonNull File directory) {
long rnd = (int) (Math.random() * 100000f);
long rnd = (int) (Math.random() * 100000.0f);
tempFile = new File(directory, rnd + "_" + System.nanoTime() + ".tmp");
}

View File

@ -198,7 +198,7 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
} else {
h.progress.setMarquee(false);
h.status.setText("100%");
h.progress.setProgress(1f);
h.progress.setProgress(1.0f);
h.size.setText(Utility.formatBytes(item.mission.length));
}
}
@ -231,7 +231,7 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
double progress;
if (mission.unknownLength) {
progress = Double.NaN;
h.progress.setProgress(0f);
h.progress.setProgress(0.0f);
} else {
progress = done / length;
}
@ -298,7 +298,7 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
for (int i = 0; i < h.lastSpeed.length; i++) {
averageSpeed += h.lastSpeed[i];
}
averageSpeed /= h.lastSpeed.length + 1f;
averageSpeed /= h.lastSpeed.length + 1.0f;
}
String speedStr = Utility.formatSpeed(averageSpeed);

View File

@ -26,7 +26,7 @@ public class ProgressDrawable extends Drawable {
public ProgressDrawable() {
mMarqueeLine = null;// marquee disabled
mMarqueeProgress = 0f;
mMarqueeProgress = 0.0f;
mMarqueeSize = 0;
mMarqueeNext = 0;
}
@ -122,7 +122,7 @@ public class ProgressDrawable extends Drawable {
}
private void setupMarquee(int width, int height) {
mMarqueeSize = (int) ((width * 10f) / 100f);// the size is 10% of the width
mMarqueeSize = (int) ((width * 10.0f) / 100.0f);// the size is 10% of the width
mMarqueeLine.rewind();
mMarqueeLine.moveTo(-mMarqueeSize, -mMarqueeSize);

View File

@ -19,15 +19,6 @@
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar"
app:titleTextAppearance="@style/Toolbar.Title">
<Spinner
android:id="@+id/toolbar_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:visibility="gone"
tools:ignore="RtlHardcoded"
tools:visibility="visible"/>
<include
android:id="@+id/toolbar_search_container"
layout="@layout/toolbar_search_layout"