mirror of
https://github.com/androidx/media.git
synced 2025-05-14 11:09:53 +08:00
Demo app bug fixes
- Restore position to start of period if period is not seekable, rather than not at all. - Get the correct window when saving position. - Disable position restore in onNewIntent. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130527704
This commit is contained in:
parent
cdb0ef13c8
commit
0d2dbb165d
@ -127,7 +127,7 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
|||||||
private boolean playerNeedsSource;
|
private boolean playerNeedsSource;
|
||||||
|
|
||||||
private boolean shouldRestorePosition;
|
private boolean shouldRestorePosition;
|
||||||
private int playerPeriodIndex;
|
private int playerPeriod;
|
||||||
private long playerPosition;
|
private long playerPosition;
|
||||||
|
|
||||||
// Activity lifecycle
|
// Activity lifecycle
|
||||||
@ -163,7 +163,7 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
|||||||
@Override
|
@Override
|
||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(Intent intent) {
|
||||||
releasePlayer();
|
releasePlayer();
|
||||||
playerPosition = 0;
|
shouldRestorePosition = false;
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +281,11 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
|||||||
player.setVideoListener(this);
|
player.setVideoListener(this);
|
||||||
player.setVideoSurfaceHolder(surfaceView.getHolder());
|
player.setVideoSurfaceHolder(surfaceView.getHolder());
|
||||||
if (shouldRestorePosition) {
|
if (shouldRestorePosition) {
|
||||||
player.seekInPeriod(playerPeriodIndex, playerPosition);
|
if (playerPosition == -1) {
|
||||||
|
player.seekToDefaultPositionForPeriod(playerPeriod);
|
||||||
|
} else {
|
||||||
|
player.seekInPeriod(playerPeriod, playerPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
mediaController.setMediaPlayer(new PlayerControl(player));
|
mediaController.setMediaPlayer(new PlayerControl(player));
|
||||||
@ -370,14 +374,14 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
|||||||
shutterView.setVisibility(View.VISIBLE);
|
shutterView.setVisibility(View.VISIBLE);
|
||||||
debugViewHelper.stop();
|
debugViewHelper.stop();
|
||||||
debugViewHelper = null;
|
debugViewHelper = null;
|
||||||
playerPeriodIndex = player.getCurrentPeriodIndex();
|
|
||||||
playerPosition = player.getCurrentPositionInPeriod();
|
|
||||||
shouldRestorePosition = false;
|
shouldRestorePosition = false;
|
||||||
Timeline playerTimeline = player.getCurrentTimeline();
|
Timeline playerTimeline = player.getCurrentTimeline();
|
||||||
if (playerTimeline != null) {
|
if (playerTimeline != null) {
|
||||||
Window window = playerTimeline.getWindow(playerPeriodIndex);
|
Window window = playerTimeline.getWindow(player.getCurrentWindowIndex());
|
||||||
if (window.isSeekable && !window.isDynamic) {
|
if (!window.isDynamic) {
|
||||||
shouldRestorePosition = true;
|
shouldRestorePosition = true;
|
||||||
|
playerPeriod = player.getCurrentPeriodIndex();
|
||||||
|
playerPosition = window.isSeekable ? player.getCurrentPositionInPeriod() : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.release();
|
player.release();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user