2017-08-29 00:38:37 +00:00
|
|
|
package org.schabi.newpipe.playlist;
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
2017-09-04 17:23:56 +00:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2018-01-22 03:32:49 +00:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
2017-09-04 17:23:56 +00:00
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2017-08-29 00:38:37 +00:00
|
|
|
|
2017-09-05 19:27:12 +00:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
2017-09-04 17:23:56 +00:00
|
|
|
import io.reactivex.Single;
|
2017-08-29 00:38:37 +00:00
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
2017-09-05 19:27:12 +00:00
|
|
|
public class PlayQueueItem implements Serializable {
|
2018-03-17 23:04:02 +00:00
|
|
|
public final static long RECOVERY_UNSET = Long.MIN_VALUE;
|
|
|
|
private final static String EMPTY_STRING = "";
|
2017-09-05 19:27:12 +00:00
|
|
|
|
2018-03-17 23:04:02 +00:00
|
|
|
@NonNull final private String title;
|
|
|
|
@NonNull final private String url;
|
2017-09-03 02:30:34 +00:00
|
|
|
final private int serviceId;
|
2017-09-04 17:23:56 +00:00
|
|
|
final private long duration;
|
2018-03-17 23:04:02 +00:00
|
|
|
@NonNull final private String thumbnailUrl;
|
|
|
|
@NonNull final private String uploader;
|
|
|
|
@NonNull final private StreamType streamType;
|
2017-08-29 00:38:37 +00:00
|
|
|
|
2017-10-22 19:43:49 +00:00
|
|
|
private long recoveryPosition;
|
2017-08-29 00:38:37 +00:00
|
|
|
private Throwable error;
|
2017-09-05 19:27:12 +00:00
|
|
|
|
2017-09-06 00:48:48 +00:00
|
|
|
private transient Single<StreamInfo> stream;
|
|
|
|
|
2017-10-22 19:43:49 +00:00
|
|
|
PlayQueueItem(@NonNull final StreamInfo info) {
|
2018-01-22 03:32:49 +00:00
|
|
|
this(info.getName(), info.getUrl(), info.getServiceId(), info.getDuration(),
|
|
|
|
info.getThumbnailUrl(), info.getUploaderName(), info.getStreamType());
|
2017-10-22 19:43:49 +00:00
|
|
|
this.stream = Single.just(info);
|
|
|
|
}
|
2017-09-05 19:27:12 +00:00
|
|
|
|
2017-10-22 19:43:49 +00:00
|
|
|
PlayQueueItem(@NonNull final StreamInfoItem item) {
|
2018-01-22 03:32:49 +00:00
|
|
|
this(item.getName(), item.getUrl(), item.getServiceId(), item.getDuration(),
|
|
|
|
item.getThumbnailUrl(), item.getUploaderName(), item.getStreamType());
|
2017-09-05 19:27:12 +00:00
|
|
|
}
|
2017-08-29 00:38:37 +00:00
|
|
|
|
2018-03-17 23:04:02 +00:00
|
|
|
private PlayQueueItem(@Nullable final String name, @Nullable final String url,
|
|
|
|
final int serviceId, final long duration,
|
|
|
|
@Nullable final String thumbnailUrl, @Nullable final String uploader,
|
|
|
|
@NonNull final StreamType streamType) {
|
|
|
|
this.title = name != null ? name : EMPTY_STRING;
|
|
|
|
this.url = url != null ? url : EMPTY_STRING;
|
2017-10-22 19:43:49 +00:00
|
|
|
this.serviceId = serviceId;
|
|
|
|
this.duration = duration;
|
2018-03-17 23:04:02 +00:00
|
|
|
this.thumbnailUrl = thumbnailUrl != null ? thumbnailUrl : EMPTY_STRING;
|
|
|
|
this.uploader = uploader != null ? uploader : EMPTY_STRING;
|
2018-01-22 03:32:49 +00:00
|
|
|
this.streamType = streamType;
|
2017-10-22 19:43:49 +00:00
|
|
|
|
2017-10-23 01:58:01 +00:00
|
|
|
this.recoveryPosition = RECOVERY_UNSET;
|
2017-08-29 00:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getUrl() {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getServiceId() {
|
|
|
|
return serviceId;
|
|
|
|
}
|
|
|
|
|
2017-09-04 17:23:56 +00:00
|
|
|
public long getDuration() {
|
2017-08-29 00:38:37 +00:00
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:58:01 +00:00
|
|
|
@NonNull
|
2017-10-03 06:38:46 +00:00
|
|
|
public String getThumbnailUrl() {
|
|
|
|
return thumbnailUrl;
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:58:01 +00:00
|
|
|
@NonNull
|
2017-10-03 06:38:46 +00:00
|
|
|
public String getUploader() {
|
|
|
|
return uploader;
|
|
|
|
}
|
|
|
|
|
2018-03-17 23:04:02 +00:00
|
|
|
@NonNull
|
2018-01-22 03:32:49 +00:00
|
|
|
public StreamType getStreamType() {
|
|
|
|
return streamType;
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:58:01 +00:00
|
|
|
public long getRecoveryPosition() {
|
|
|
|
return recoveryPosition;
|
|
|
|
}
|
|
|
|
|
2017-08-29 00:38:37 +00:00
|
|
|
@Nullable
|
|
|
|
public Throwable getError() {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2017-09-04 17:23:56 +00:00
|
|
|
public Single<StreamInfo> getStream() {
|
2017-09-06 00:48:48 +00:00
|
|
|
return stream == null ? stream = getInfo() : stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
private Single<StreamInfo> getInfo() {
|
2017-09-04 17:23:56 +00:00
|
|
|
return ExtractorHelper.getStreamInfo(this.serviceId, this.url, false)
|
2017-08-29 00:38:37 +00:00
|
|
|
.subscribeOn(Schedulers.io())
|
2018-02-17 19:55:45 +00:00
|
|
|
.doOnError(throwable -> error = throwable);
|
2017-09-03 02:30:34 +00:00
|
|
|
}
|
2017-10-22 19:43:49 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2017-10-23 01:58:01 +00:00
|
|
|
// Item States, keep external access out
|
2017-10-22 19:43:49 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-23 01:58:01 +00:00
|
|
|
/*package-private*/ void setRecoveryPosition(final long recoveryPosition) {
|
2017-10-22 19:43:49 +00:00
|
|
|
this.recoveryPosition = recoveryPosition;
|
|
|
|
}
|
2017-08-29 00:38:37 +00:00
|
|
|
}
|