Fix surface view not resizing video correctly
Also fix yet another random null pointer exception that could happen when adding the video player view
This commit is contained in:
parent
75917c7f61
commit
6805c75c9c
|
@ -1220,7 +1220,7 @@ public final class VideoDetailFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayQueue queue = setupPlayQueueForIntent(false);
|
final PlayQueue queue = setupPlayQueueForIntent(false);
|
||||||
addVideoPlayerView();
|
tryAddVideoPlayerView();
|
||||||
|
|
||||||
final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(),
|
final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(),
|
||||||
PlayerService.class, queue, true, autoPlayEnabled);
|
PlayerService.class, queue, true, autoPlayEnabled);
|
||||||
|
@ -1301,21 +1301,27 @@ public final class VideoDetailFragment
|
||||||
&& PlayerHelper.isAutoplayAllowedByUser(requireContext());
|
&& PlayerHelper.isAutoplayAllowedByUser(requireContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addVideoPlayerView() {
|
private void tryAddVideoPlayerView() {
|
||||||
|
// do all the null checks in the posted lambda, since the player, the binding and the view
|
||||||
|
// could be set or unset before the lambda gets executed on the next main thread cycle
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> {
|
||||||
if (!isPlayerAvailable() || getView() == null) {
|
if (!isPlayerAvailable() || getView() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setup the surface view height, so that it fits the video correctly
|
||||||
setHeightThumbnail();
|
setHeightThumbnail();
|
||||||
|
|
||||||
// Prevent from re-adding a view multiple times
|
|
||||||
new Handler(Looper.getMainLooper()).post(() ->
|
|
||||||
player.UIs().get(MainPlayerUi.class).ifPresent(playerUi -> {
|
player.UIs().get(MainPlayerUi.class).ifPresent(playerUi -> {
|
||||||
|
// sometimes binding would be null here, even though getView() != null above u.u
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
|
// prevent from re-adding a view multiple times
|
||||||
playerUi.removeViewFromParent();
|
playerUi.removeViewFromParent();
|
||||||
binding.playerPlaceholder.addView(playerUi.getBinding().getRoot());
|
binding.playerPlaceholder.addView(playerUi.getBinding().getRoot());
|
||||||
playerUi.setupVideoSurfaceIfNeeded();
|
playerUi.setupVideoSurfaceIfNeeded();
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeVideoPlayerView() {
|
private void removeVideoPlayerView() {
|
||||||
|
@ -1784,7 +1790,7 @@ public final class VideoDetailFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated() {
|
public void onViewCreated() {
|
||||||
addVideoPlayerView();
|
tryAddVideoPlayerView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1926,7 +1932,7 @@ public final class VideoDetailFragment
|
||||||
}
|
}
|
||||||
scrollToTop();
|
scrollToTop();
|
||||||
|
|
||||||
addVideoPlayerView();
|
tryAddVideoPlayerView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue