-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
b4fdbdeb1b
commit
68695bbf92
|
@ -1,17 +0,0 @@
|
|||
package org.schabi.newpipe.database;
|
||||
|
||||
import android.arch.persistence.room.TypeConverter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Converters {
|
||||
@TypeConverter
|
||||
public static Date fromTimestamp(Long value) {
|
||||
return value == null ? null : new Date(value);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static Long dateToTimestamp(Date date) {
|
||||
return date == null ? null : date.getTime();
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package org.schabi.newpipe.database.playlist;
|
||||
|
||||
import android.arch.persistence.room.ColumnInfo;
|
||||
import android.arch.persistence.room.Entity;
|
||||
import android.arch.persistence.room.Ignore;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
|
||||
import static org.schabi.newpipe.database.playlist.PlaylistEntity.PLAYLIST_TABLE;
|
||||
|
||||
@Entity(tableName = PLAYLIST_TABLE)
|
||||
public class PlaylistEntity {
|
||||
|
||||
final static String PLAYLIST_TABLE = "playlists";
|
||||
final static String PLAYLIST_URL = "url";
|
||||
final static String PLAYLIST_TITLE = "title";
|
||||
final static String PLAYLIST_THUMBNAIL_URL = "thumbnail_url";
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private long uid = 0;
|
||||
|
||||
@ColumnInfo(name = PLAYLIST_TITLE)
|
||||
private String title;
|
||||
|
||||
/* This is used as a reference to the source, should this playlist be dynamic */
|
||||
@ColumnInfo(name = PLAYLIST_URL)
|
||||
private String url;
|
||||
|
||||
@ColumnInfo(name = PLAYLIST_THUMBNAIL_URL)
|
||||
private String thumbnailUrl;
|
||||
|
||||
public long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
/* Keep this package-private since UID should always be auto generated by Room impl */
|
||||
void setUid(long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getThumbnailUrl() {
|
||||
return thumbnailUrl;
|
||||
}
|
||||
|
||||
public void setThumbnailUrl(String thumbnailUrl) {
|
||||
this.thumbnailUrl = thumbnailUrl;
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void setData(final String title,
|
||||
final String thumbnailUrl) {
|
||||
this.setTitle(title);
|
||||
this.setThumbnailUrl(thumbnailUrl);
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package org.schabi.newpipe.database.stream;
|
||||
|
||||
import android.arch.persistence.room.Dao;
|
||||
import android.arch.persistence.room.Query;
|
||||
|
||||
import org.schabi.newpipe.database.BasicDAO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Flowable;
|
||||
|
||||
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_SERVICE_ID;
|
||||
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_TABLE;
|
||||
|
||||
@Dao
|
||||
public interface StreamDAO extends BasicDAO<StreamEntity> {
|
||||
@Override
|
||||
@Query("SELECT * FROM " + STREAM_TABLE)
|
||||
Flowable<List<StreamEntity>> getAll();
|
||||
|
||||
@Override
|
||||
@Query("SELECT * FROM " + STREAM_TABLE + " WHERE " + STREAM_SERVICE_ID + " = :serviceId")
|
||||
Flowable<List<StreamEntity>> listByService(int serviceId);
|
||||
}
|
|
@ -1,204 +0,0 @@
|
|||
package org.schabi.newpipe.database.stream;
|
||||
|
||||
import android.arch.persistence.room.ColumnInfo;
|
||||
import android.arch.persistence.room.Entity;
|
||||
import android.arch.persistence.room.Ignore;
|
||||
import android.arch.persistence.room.Index;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_SERVICE_ID;
|
||||
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_TABLE;
|
||||
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_URL;
|
||||
|
||||
@Entity(tableName = STREAM_TABLE,
|
||||
indices = {@Index(value = {STREAM_SERVICE_ID, STREAM_URL}, unique = true)})
|
||||
public class StreamEntity {
|
||||
public final static String STREAM_UID = "uid";
|
||||
|
||||
final static String STREAM_TABLE = "streams";
|
||||
final static String STREAM_ID = "id";
|
||||
final static String STREAM_TYPE = "type";
|
||||
final static String STREAM_SERVICE_ID = "service_id";
|
||||
final static String STREAM_URL = "url";
|
||||
final static String STREAM_TITLE = "title";
|
||||
final static String STREAM_THUMBNAIL_URL = "thumbnail_url";
|
||||
final static String STREAM_VIEW_COUNT = "view_count";
|
||||
final static String STREAM_UPLOADER = "uploader";
|
||||
final static String STREAM_UPLOAD_DATE = "upload_date";
|
||||
final static String STREAM_DURATION = "duration";
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private long uid = 0;
|
||||
|
||||
@ColumnInfo(name = STREAM_SERVICE_ID)
|
||||
private int serviceId = -1;
|
||||
|
||||
@ColumnInfo(name = STREAM_ID)
|
||||
private String id;
|
||||
|
||||
@ColumnInfo(name = STREAM_TYPE)
|
||||
private String type;
|
||||
|
||||
@ColumnInfo(name = STREAM_URL)
|
||||
private String url;
|
||||
|
||||
@ColumnInfo(name = STREAM_TITLE)
|
||||
private String title;
|
||||
|
||||
@ColumnInfo(name = STREAM_THUMBNAIL_URL)
|
||||
private String thumbnailUrl;
|
||||
|
||||
@ColumnInfo(name = STREAM_VIEW_COUNT)
|
||||
private Long viewCount;
|
||||
|
||||
@ColumnInfo(name = STREAM_UPLOADER)
|
||||
private String uploader;
|
||||
|
||||
@ColumnInfo(name = STREAM_UPLOAD_DATE)
|
||||
private long uploadDate;
|
||||
|
||||
@ColumnInfo(name = STREAM_DURATION)
|
||||
private long duration;
|
||||
|
||||
@Ignore
|
||||
public StreamInfoItem toStreamInfoItem() {
|
||||
StreamInfoItem item = new StreamInfoItem();
|
||||
|
||||
item.stream_type = StreamType.valueOf( this.getType() );
|
||||
|
||||
item.service_id = this.getServiceId();
|
||||
item.url = this.getUrl();
|
||||
item.name = this.getTitle();
|
||||
item.thumbnail_url = this.getThumbnailUrl();
|
||||
item.view_count = this.getViewCount();
|
||||
item.uploader_name = this.getUploader();
|
||||
|
||||
// TODO: temporary until upload date parsing is fleshed out
|
||||
item.upload_date = "Unknown";
|
||||
item.duration = this.getDuration();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public StreamEntity(final StreamInfoItem item) {
|
||||
setData(item);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void setData(final StreamInfoItem item) {
|
||||
// Do not store ordinals into db since they may change in the future
|
||||
this.type = item.stream_type.name();
|
||||
|
||||
this.serviceId = item.service_id;
|
||||
this.url = item.url;
|
||||
this.title = item.name;
|
||||
this.thumbnailUrl = item.thumbnail_url;
|
||||
this.viewCount = item.view_count;
|
||||
this.uploader = item.uploader_name;
|
||||
|
||||
// TODO: temporary until upload date parsing is fleshed out
|
||||
this.uploadDate = new Date().getTime();
|
||||
this.duration = item.duration;
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public boolean is(final StreamInfoItem item) {
|
||||
return this.type.equals( item.stream_type.name() ) &&
|
||||
this.serviceId == item.service_id &&
|
||||
this.url.equals( item.url );
|
||||
}
|
||||
|
||||
public long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
void setUid(long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public int getServiceId() {
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
public void setServiceId(int serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getThumbnailUrl() {
|
||||
return thumbnailUrl;
|
||||
}
|
||||
|
||||
public void setThumbnailUrl(String thumbnailUrl) {
|
||||
this.thumbnailUrl = thumbnailUrl;
|
||||
}
|
||||
|
||||
public Long getViewCount() {
|
||||
return viewCount;
|
||||
}
|
||||
|
||||
public void setViewCount(Long viewCount) {
|
||||
this.viewCount = viewCount;
|
||||
}
|
||||
|
||||
public String getUploader() {
|
||||
return uploader;
|
||||
}
|
||||
|
||||
public void setUploader(String uploader) {
|
||||
this.uploader = uploader;
|
||||
}
|
||||
|
||||
public long getUploadDate() {
|
||||
return uploadDate;
|
||||
}
|
||||
|
||||
public void setUploadDate(long uploadDate) {
|
||||
this.uploadDate = uploadDate;
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
}
|
|
@ -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…
Reference in New Issue