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-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-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-09-25 05:14:58 +02:00
|
|
|
PlayQueueItem(final StreamInfo streamInfo) {
|
2017-09-05 21:27:12 +02:00
|
|
|
this.title = streamInfo.name;
|
|
|
|
this.url = streamInfo.url;
|
|
|
|
this.serviceId = streamInfo.service_id;
|
|
|
|
this.duration = streamInfo.duration;
|
|
|
|
|
2017-09-18 05:14:02 +02:00
|
|
|
this.stream = Single.just(streamInfo);
|
2017-09-05 21:27:12 +02:00
|
|
|
}
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-03 04:30:34 +02:00
|
|
|
PlayQueueItem(final StreamInfoItem streamInfoItem) {
|
2017-09-04 19:23:56 +02:00
|
|
|
this.title = streamInfoItem.name;
|
|
|
|
this.url = streamInfoItem.url;
|
2017-08-29 02:38:37 +02:00
|
|
|
this.serviceId = streamInfoItem.service_id;
|
|
|
|
this.duration = streamInfoItem.duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-08-29 02:38:37 +02:00
|
|
|
}
|