2017-08-29 02:38:37 +02:00
|
|
|
package org.schabi.newpipe.playlist;
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
import io.reactivex.Single;
|
2017-08-29 02:38:37 +02:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
import io.reactivex.functions.Consumer;
|
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
public class PlayQueueItem implements Serializable {
|
2017-10-22 21:43:49 +02:00
|
|
|
final public static int DEFAULT_QUALITY = Integer.MIN_VALUE;
|
|
|
|
final public static long RECOVERY_UNSET = Long.MIN_VALUE;
|
2017-09-05 21:27:12 +02:00
|
|
|
|
2017-09-03 04:30:34 +02:00
|
|
|
final private String title;
|
|
|
|
final private String url;
|
|
|
|
final private int serviceId;
|
2017-09-04 19:23:56 +02:00
|
|
|
final private long duration;
|
2017-10-03 08:38:46 +02:00
|
|
|
final private String thumbnailUrl;
|
|
|
|
final private String uploader;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
private int qualityIndex;
|
|
|
|
private long recoveryPosition;
|
2017-08-29 02:38:37 +02:00
|
|
|
private Throwable error;
|
2017-09-05 21:27:12 +02:00
|
|
|
|
2017-09-06 02:48:48 +02:00
|
|
|
private transient Single<StreamInfo> stream;
|
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
PlayQueueItem(@NonNull final StreamInfo info) {
|
|
|
|
this(info.name, info.url, info.service_id, info.duration, info.thumbnail_url, info.uploader_name);
|
|
|
|
this.stream = Single.just(info);
|
|
|
|
}
|
2017-09-05 21:27:12 +02:00
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
PlayQueueItem(@NonNull final StreamInfoItem item) {
|
|
|
|
this(item.name, item.url, item.service_id, item.duration, item.thumbnail_url, item.uploader_name);
|
2017-09-05 21:27:12 +02:00
|
|
|
}
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
private PlayQueueItem(final String name, final String url, final int serviceId,
|
|
|
|
final long duration, final String thumbnailUrl, final String uploader) {
|
|
|
|
this.title = name;
|
|
|
|
this.url = url;
|
|
|
|
this.serviceId = serviceId;
|
|
|
|
this.duration = duration;
|
|
|
|
this.thumbnailUrl = thumbnailUrl;
|
|
|
|
this.uploader = uploader;
|
|
|
|
|
|
|
|
resetQualityIndex();
|
|
|
|
resetRecoveryPosition();
|
2017-08-29 02:38:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getUrl() {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getServiceId() {
|
|
|
|
return serviceId;
|
|
|
|
}
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
public long getDuration() {
|
2017-08-29 02:38:37 +02:00
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2017-10-03 08:38:46 +02:00
|
|
|
public String getThumbnailUrl() {
|
|
|
|
return thumbnailUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUploader() {
|
|
|
|
return uploader;
|
|
|
|
}
|
|
|
|
|
2017-08-29 02:38:37 +02:00
|
|
|
@Nullable
|
|
|
|
public Throwable getError() {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2017-09-04 19:23:56 +02:00
|
|
|
public Single<StreamInfo> getStream() {
|
2017-09-06 02:48:48 +02:00
|
|
|
return stream == null ? stream = getInfo() : stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
private Single<StreamInfo> getInfo() {
|
2017-08-29 02:38:37 +02:00
|
|
|
final Consumer<Throwable> onError = new Consumer<Throwable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Throwable throwable) throws Exception {
|
|
|
|
error = throwable;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
return ExtractorHelper.getStreamInfo(this.serviceId, this.url, false)
|
2017-08-29 02:38:37 +02:00
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
2017-09-04 19:23:56 +02:00
|
|
|
.doOnError(onError);
|
2017-09-03 04:30:34 +02:00
|
|
|
}
|
2017-10-22 21:43:49 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Item States
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public int getQualityIndex() {
|
|
|
|
return qualityIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getRecoveryPosition() {
|
|
|
|
return recoveryPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setQualityIndex(int qualityIndex) {
|
|
|
|
this.qualityIndex = qualityIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRecoveryPosition(long recoveryPosition) {
|
|
|
|
this.recoveryPosition = recoveryPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetQualityIndex() {
|
|
|
|
this.qualityIndex = DEFAULT_QUALITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetRecoveryPosition() {
|
|
|
|
this.recoveryPosition = RECOVERY_UNSET;
|
|
|
|
}
|
2017-08-29 02:38:37 +02:00
|
|
|
}
|