avoid stopping playback after skipping (and changing media type)
This commit is contained in:
parent
8bf33732a9
commit
0f32e2953c
|
@ -176,7 +176,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -497,7 +497,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -575,7 +575,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -655,7 +655,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -738,7 +738,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -796,7 +796,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -874,7 +874,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -989,7 +989,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -1081,7 +1081,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -1185,7 +1185,7 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -211,11 +211,11 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if(controller != null) {
|
||||
controller.reinitServiceIfPaused();
|
||||
controller.pause();
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,12 +257,12 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.d(TAG, "onStop()");
|
||||
if (controller != null) {
|
||||
controller.release();
|
||||
controller = null; // prevent leak
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
|
|
|
@ -41,6 +41,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
|||
*/
|
||||
private boolean videoControlsShowing = true;
|
||||
private boolean videoSurfaceCreated = false;
|
||||
private boolean destroyingDueToReload = false;
|
||||
|
||||
private VideoControlsHider videoControlsHider = new VideoControlsHider(this);
|
||||
|
||||
|
@ -86,6 +87,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
|||
} else if (PlaybackService.isCasting()) {
|
||||
Intent intent = PlaybackService.getPlayerActivityIntent(this);
|
||||
if (!intent.getComponent().getClassName().equals(VideoplayerActivity.class.getName())) {
|
||||
destroyingDueToReload = true;
|
||||
finish();
|
||||
startActivity(intent);
|
||||
}
|
||||
|
@ -94,18 +96,18 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
|||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
videoControlsHider.stop();
|
||||
if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) {
|
||||
controller.pause();
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
videoControlsHider.stop();
|
||||
videoControlsHider = null;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,7 +244,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
|||
if (controller.serviceAvailable()) {
|
||||
controller.setVideoSurface(holder);
|
||||
} else {
|
||||
Log.e(TAG, "Could'nt attach surface to mediaplayer - reference to service was null");
|
||||
Log.e(TAG, "Couldn't attach surface to mediaplayer - reference to service was null");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +254,9 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
|||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
Log.d(TAG, "Videosurface was destroyed");
|
||||
videoSurfaceCreated = false;
|
||||
controller.notifyVideoSurfaceAbandoned();
|
||||
if (!destroyingDueToReload) {
|
||||
controller.notifyVideoSurfaceAbandoned();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -261,10 +265,12 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
|||
protected void onReloadNotification(int notificationCode) {
|
||||
if (notificationCode == PlaybackService.EXTRA_CODE_AUDIO) {
|
||||
Log.d(TAG, "ReloadNotification received, switching to Audioplayer now");
|
||||
destroyingDueToReload = true;
|
||||
finish();
|
||||
startActivity(new Intent(this, AudioplayerActivity.class));
|
||||
} else if (notificationCode == PlaybackService.EXTRA_CODE_CAST) {
|
||||
Log.d(TAG, "ReloadNotification received, switching to Castplayer now");
|
||||
destroyingDueToReload = true;
|
||||
finish();
|
||||
startActivity(new Intent(this, CastplayerActivity.class));
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
||||
try {
|
||||
media.loadMetadata();
|
||||
callback.reloadUI();
|
||||
callback.reloadUI(true);
|
||||
if (stream) {
|
||||
mediaPlayer.setDataSource(media.getStreamUrl());
|
||||
} else {
|
||||
|
@ -337,6 +337,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
public void reinit() {
|
||||
executor.submit(() -> {
|
||||
playerLock.lock();
|
||||
Log.d(TAG, "reinit()");
|
||||
releaseWifiLockIfNecessary();
|
||||
if (media != null) {
|
||||
playMediaObject(media, true, stream, startWhenPrepared.get(), false);
|
||||
|
@ -629,9 +630,13 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
public void resetVideoSurface() {
|
||||
executor.submit(() -> {
|
||||
playerLock.lock();
|
||||
Log.d(TAG, "Resetting video surface");
|
||||
mediaPlayer.setDisplay(null);
|
||||
reinit();
|
||||
if (mediaType == MediaType.VIDEO) {
|
||||
Log.d(TAG, "Resetting video surface");
|
||||
mediaPlayer.setDisplay(null);
|
||||
reinit();
|
||||
} else {
|
||||
Log.e(TAG, "Resetting video surface for media of Audio type");
|
||||
}
|
||||
playerLock.unlock();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -499,7 +499,7 @@ public class PlaybackService extends Service {
|
|||
}
|
||||
|
||||
public void notifyVideoSurfaceAbandoned() {
|
||||
stopForeground(true);
|
||||
stopForeground(!UserPreferences.isPersistNotify());
|
||||
mediaPlayer.resetVideoSurface();
|
||||
}
|
||||
|
||||
|
@ -640,9 +640,11 @@ public class PlaybackService extends Service {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reloadUI() {
|
||||
public void reloadUI(boolean onlyMediaSession) {
|
||||
Log.d(TAG, "reloadUI callback reached");
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
|
||||
if (!onlyMediaSession) {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
|
||||
}
|
||||
PlaybackService.this.updateMediaSessionMetadata(getPlayable());
|
||||
}
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ public abstract class PlaybackServiceMediaPlayer {
|
|||
|
||||
void onBufferingUpdate(int percent);
|
||||
|
||||
void reloadUI();
|
||||
void reloadUI(boolean onlyMediaSession);
|
||||
|
||||
boolean onMediaPlayerInfo(int code, @StringRes int resourceId);
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer {
|
|||
setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
|
||||
}
|
||||
if (updateUI) {
|
||||
callback.reloadUI();
|
||||
callback.reloadUI(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer {
|
|||
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
||||
try {
|
||||
media.loadMetadata();
|
||||
callback.reloadUI();
|
||||
callback.reloadUI(false);
|
||||
setPlayerStatus(PlayerStatus.INITIALIZED, media);
|
||||
if (prepareImmediately) {
|
||||
prepare();
|
||||
|
|
Loading…
Reference in New Issue