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