-Modified MediaSourceManager to immediately load on critical events.
-Fixed tag name for background service actcivity. -Removed unused track selector. -Removed unused database entities.
This commit is contained in:
parent
989b5c0900
commit
8b3a79ea0c
8 changed files with 34 additions and 350 deletions
|
|
@ -6,7 +6,7 @@ import org.schabi.newpipe.R;
|
|||
|
||||
public final class BackgroundPlayerActivity extends ServicePlayerActivity {
|
||||
|
||||
private static final String TAG = "BGPlayerActivity";
|
||||
private static final String TAG = "BackgroundPlayerActivity";
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
|
|
|
|||
|
|
@ -570,15 +570,16 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
|
|||
switch (error.type) {
|
||||
case ExoPlaybackException.TYPE_SOURCE:
|
||||
playQueue.error(isCurrentWindowValid());
|
||||
onStreamError(error);
|
||||
showStreamError(error);
|
||||
break;
|
||||
case ExoPlaybackException.TYPE_UNEXPECTED:
|
||||
onRecoverableError(error);
|
||||
showRecoverableError(error);
|
||||
setRecovery();
|
||||
reload();
|
||||
break;
|
||||
default:
|
||||
onUnrecoverableError(error);
|
||||
showUnrecoverableError(error);
|
||||
shutdown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -659,7 +660,7 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
|
|||
// General Player
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public void onStreamError(Exception exception) {
|
||||
public void showStreamError(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
if (errorToast == null) {
|
||||
|
|
@ -668,7 +669,7 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
|
|||
}
|
||||
}
|
||||
|
||||
public void onRecoverableError(Exception exception) {
|
||||
public void showRecoverableError(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
if (errorToast == null) {
|
||||
|
|
@ -677,7 +678,7 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
|
|||
}
|
||||
}
|
||||
|
||||
public void onUnrecoverableError(Exception exception) {
|
||||
public void showUnrecoverableError(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
if (errorToast != null) {
|
||||
|
|
@ -685,8 +686,6 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
|
|||
}
|
||||
errorToast = Toast.makeText(context, R.string.player_unrecoverable_failure, Toast.LENGTH_SHORT);
|
||||
errorToast.show();
|
||||
|
||||
shutdown();
|
||||
}
|
||||
|
||||
public void onPrepared(boolean playWhenReady) {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||
|
|
@ -77,8 +76,6 @@ public final class MainVideoPlayer extends Activity {
|
|||
private boolean activityPaused;
|
||||
private VideoPlayerImpl playerImpl;
|
||||
|
||||
private DefaultTrackSelector.Parameters parameters;
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Activity LifeCycle
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
|
@ -124,10 +121,6 @@ public final class MainVideoPlayer extends Activity {
|
|||
if (DEBUG) Log.d(TAG, "onStop() called");
|
||||
activityPaused = true;
|
||||
|
||||
if (playerImpl.trackSelector != null) {
|
||||
parameters = playerImpl.trackSelector.getParameters();
|
||||
}
|
||||
|
||||
if (playerImpl.getPlayer() != null) {
|
||||
playerImpl.wasPlaying = playerImpl.getPlayer().getPlayWhenReady();
|
||||
playerImpl.setRecovery();
|
||||
|
|
@ -146,10 +139,6 @@ public final class MainVideoPlayer extends Activity {
|
|||
playerImpl.getPlayer().setPlayWhenReady(playerImpl.wasPlaying);
|
||||
playerImpl.initPlayback(playerImpl.playQueue);
|
||||
|
||||
if (playerImpl.trackSelector != null && parameters != null) {
|
||||
playerImpl.trackSelector.setParameters(parameters);
|
||||
}
|
||||
|
||||
activityPaused = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -675,10 +664,11 @@ public final class MainVideoPlayer extends Activity {
|
|||
if (DEBUG) Log.d(TAG, "onDoubleTap() called with: e = [" + e + "]" + "rawXy = " + e.getRawX() + ", " + e.getRawY() + ", xy = " + e.getX() + ", " + e.getY());
|
||||
if (!playerImpl.isPlaying()) return false;
|
||||
|
||||
if (e.getX() > playerImpl.getRootView().getWidth() / 2)
|
||||
if (e.getX() > playerImpl.getRootView().getWidth() / 2) {
|
||||
playerImpl.onFastForward();
|
||||
else
|
||||
} else {
|
||||
playerImpl.onFastRewind();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,9 @@ public class MediaSourceManager {
|
|||
private final PlaybackListener playbackListener;
|
||||
private final PlayQueue playQueue;
|
||||
|
||||
// Process only the last load order when receiving a stream of load orders (lessens IO)
|
||||
// The lower it is, the faster the error processing during loading
|
||||
// The higher it is, the less loading occurs during rapid timeline changes
|
||||
// Not recommended to go below 50ms or above 500ms
|
||||
// Process only the last load order when receiving a stream of load orders (lessens I/O)
|
||||
// The higher it is, the less loading occurs during rapid noncritical timeline changes
|
||||
// Not recommended to go below 100ms
|
||||
private final long loadDebounceMillis;
|
||||
private final PublishSubject<Long> loadSignal;
|
||||
private final Disposable debouncedLoader;
|
||||
|
|
@ -53,7 +52,7 @@ public class MediaSourceManager {
|
|||
|
||||
public MediaSourceManager(@NonNull final PlaybackListener listener,
|
||||
@NonNull final PlayQueue playQueue) {
|
||||
this(listener, playQueue, 1, 200L);
|
||||
this(listener, playQueue, 1, 1000L);
|
||||
}
|
||||
|
||||
private MediaSourceManager(@NonNull final PlaybackListener listener,
|
||||
|
|
@ -131,11 +130,6 @@ public class MediaSourceManager {
|
|||
tryBlock();
|
||||
populateSources();
|
||||
}
|
||||
|
||||
public int getWindowSize() {
|
||||
return windowSize;
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Event Reactor
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
|
@ -195,13 +189,26 @@ public class MediaSourceManager {
|
|||
break;
|
||||
}
|
||||
|
||||
switch (event.type()) {
|
||||
case INIT:
|
||||
case REORDER:
|
||||
case ERROR:
|
||||
case APPEND:
|
||||
loadInternal(); // low frequency, critical events
|
||||
break;
|
||||
case REMOVE:
|
||||
case SELECT:
|
||||
case MOVE:
|
||||
case RECOVERY:
|
||||
default:
|
||||
load(); // high frequency or noncritical events
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isPlayQueueReady()) {
|
||||
tryBlock();
|
||||
playQueue.fetch();
|
||||
} else {
|
||||
load(); // All event warrants a load
|
||||
}
|
||||
|
||||
if (playQueueReactor != null) playQueueReactor.request(1);
|
||||
}
|
||||
|
||||
|
|
@ -320,6 +327,7 @@ public class MediaSourceManager {
|
|||
* If the play queue index already exists, then the insert is ignored.
|
||||
* */
|
||||
private void insert(final int queueIndex, final DeferredMediaSource source) {
|
||||
if (sources == null) return;
|
||||
if (queueIndex < 0 || queueIndex < sources.getSize()) return;
|
||||
|
||||
sources.addMediaSource(queueIndex, source);
|
||||
|
|
@ -331,12 +339,14 @@ public class MediaSourceManager {
|
|||
* If the play queue index does not exist, the removal is ignored.
|
||||
* */
|
||||
private void remove(final int queueIndex) {
|
||||
if (sources == null) return;
|
||||
if (queueIndex < 0 || queueIndex > sources.getSize()) return;
|
||||
|
||||
sources.removeMediaSource(queueIndex);
|
||||
}
|
||||
|
||||
private void move(final int source, final int target) {
|
||||
if (sources == null) return;
|
||||
if (source < 0 || target < 0) return;
|
||||
if (source >= sources.getSize() || target >= sources.getSize()) return;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue