Commit 40ccbc2f authored by Geoffrey Métais's avatar Geoffrey Métais

Video Player: Ensure playback is always started

parent 0158723c
...@@ -299,7 +299,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS ...@@ -299,7 +299,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
mEnableCloneMode = mSettings.getBoolean("enable_clone_mode", false); mEnableCloneMode = mSettings.getBoolean("enable_clone_mode", false);
mDisplayManager = new DisplayManager(this, PlaybackService.Companion.getRenderer(), false, mEnableCloneMode, mIsBenchmark); mDisplayManager = new DisplayManager(this, PlaybackService.Companion.getRenderer(), false, mEnableCloneMode, mIsBenchmark);
setContentView(mDisplayManager.isPrimary() ? R.layout.player : R.layout.player_remote_control); setContentView(mDisplayManager.isPrimary() ? R.layout.player : R.layout.player_remote_control);
PlaybackService.Companion.getService().observe(this, this);
/** initialize Views an their Events */ /** initialize Views an their Events */
mActionBar = getSupportActionBar(); mActionBar = getSupportActionBar();
...@@ -488,14 +487,14 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS ...@@ -488,14 +487,14 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
if (mw == null || !AndroidDevices.pipAllowed) return; if (mw == null || !AndroidDevices.pipAllowed) return;
if (AndroidDevices.hasPiP) { if (AndroidDevices.hasPiP) {
if (AndroidUtil.isOOrLater) try { if (AndroidUtil.isOOrLater) try {
final SurfaceView videoSurface = mVideoLayout.findViewById(R.id.surface_video); final SurfaceView videoSurface = mVideoLayout.findViewById(R.id.surface_video);
final int height = videoSurface != null && videoSurface.getHeight() != 0 ? videoSurface.getHeight() : mw.getHeight(); final int height = videoSurface != null && videoSurface.getHeight() != 0 ? videoSurface.getHeight() : mw.getHeight();
final int width = Math.min(videoSurface != null && videoSurface.getWidth() != 0 ? videoSurface.getWidth() : mw.getWidth(), (int) (height*2.39f)); final int width = Math.min(videoSurface != null && videoSurface.getWidth() != 0 ? videoSurface.getWidth() : mw.getWidth(), (int) (height*2.39f));
enterPictureInPictureMode(new PictureInPictureParams.Builder().setAspectRatio(new Rational(width, height)).build()); enterPictureInPictureMode(new PictureInPictureParams.Builder().setAspectRatio(new Rational(width, height)).build());
} catch (IllegalArgumentException e) { // Fallback with default parameters } catch (IllegalArgumentException e) { // Fallback with default parameters
//noinspection deprecation //noinspection deprecation
enterPictureInPictureMode(); enterPictureInPictureMode();
} }
else { else {
//noinspection deprecation //noinspection deprecation
enterPictureInPictureMode(); enterPictureInPictureMode();
...@@ -569,6 +568,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS ...@@ -569,6 +568,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
PlaybackService.Companion.getService().observe(this, this);
restoreBrightness(); restoreBrightness();
final IntentFilter filter = new IntentFilter(Constants.PLAY_FROM_SERVICE); final IntentFilter filter = new IntentFilter(Constants.PLAY_FROM_SERVICE);
filter.addAction(Constants.EXIT_PLAYER); filter.addAction(Constants.EXIT_PLAYER);
...@@ -584,6 +584,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS ...@@ -584,6 +584,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
PlaybackService.Companion.getService().removeObservers(this);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mServiceReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mServiceReceiver);
unregisterReceiver(mBtReceiver); unregisterReceiver(mBtReceiver);
...@@ -2002,13 +2003,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS ...@@ -2002,13 +2003,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
public void onTrackSelected(final int trackID) { public void onTrackSelected(final int trackID) {
if (trackID < -1 || mService == null) return; if (trackID < -1 || mService == null) return;
mService.setAudioTrack(trackID); mService.setAudioTrack(trackID);
WorkersKt.runIO(new Runnable() { WorkersKt.runIO(new Runnable() {
@Override @Override
public void run() { public void run() {
final MediaWrapper mw = mMedialibrary.findMedia(mService.getCurrentMediaWrapper()); final MediaWrapper mw = mMedialibrary.findMedia(mService.getCurrentMediaWrapper());
if (mw != null && mw.getId() != 0L) mw.setLongMeta(MediaWrapper.META_AUDIOTRACK, trackID); if (mw != null && mw.getId() != 0L) mw.setLongMeta(MediaWrapper.META_AUDIOTRACK, trackID);
} }
}); });
} }
}); });
} }
...@@ -2904,8 +2905,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS ...@@ -2904,8 +2905,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
if (Permissions.checkReadStoragePermission(this, true) && !mSwitchingView) if (Permissions.checkReadStoragePermission(this, true) && !mSwitchingView)
mHandler.sendEmptyMessage(START_PLAYBACK); mHandler.sendEmptyMessage(START_PLAYBACK);
mSwitchingView = false; mSwitchingView = false;
if (mService.getVolume() > 100 && !audioBoostEnabled) if (mService.getVolume() > 100 && !audioBoostEnabled) mService.setVolume(100);
mService.setVolume(100);
} else { } else {
mService = null; mService = null;
mHandler.sendEmptyMessage(AUDIO_SERVICE_CONNECTION_FAILED); mHandler.sendEmptyMessage(AUDIO_SERVICE_CONNECTION_FAILED);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment