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;
|
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2017-08-29 00:38:37 +00:00
|
|
|
|
2017-09-04 17:23:56 +00:00
|
|
|
import io.reactivex.Single;
|
2017-08-29 00:38:37 +00:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
import io.reactivex.functions.Consumer;
|
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
2017-08-31 17:07:18 +00:00
|
|
|
public class PlayQueueItem {
|
2017-08-29 00:38:37 +00:00
|
|
|
|
2017-09-03 02:30:34 +00:00
|
|
|
final private String title;
|
|
|
|
final private String url;
|
|
|
|
final private int serviceId;
|
2017-09-04 17:23:56 +00:00
|
|
|
final private long duration;
|
2017-08-29 00:38:37 +00:00
|
|
|
|
|
|
|
private Throwable error;
|
2017-09-04 17:23:56 +00:00
|
|
|
private Single<StreamInfo> stream;
|
2017-08-29 00:38:37 +00:00
|
|
|
|
2017-09-03 02:30:34 +00:00
|
|
|
PlayQueueItem(final StreamInfoItem streamInfoItem) {
|
2017-09-04 17:23:56 +00:00
|
|
|
this.title = streamInfoItem.name;
|
|
|
|
this.url = streamInfoItem.url;
|
2017-08-29 00:38:37 +00:00
|
|
|
this.serviceId = streamInfoItem.service_id;
|
|
|
|
this.duration = streamInfoItem.duration;
|
|
|
|
|
|
|
|
this.stream = getInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public Throwable getError() {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2017-09-04 17:23:56 +00:00
|
|
|
public Single<StreamInfo> getStream() {
|
2017-08-29 00:38:37 +00:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2017-09-04 17:23:56 +00:00
|
|
|
private Single<StreamInfo> getInfo() {
|
2017-08-29 00:38:37 +00:00
|
|
|
final Consumer<Throwable> onError = new Consumer<Throwable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Throwable throwable) throws Exception {
|
|
|
|
error = throwable;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
2017-09-04 02:15:11 +00:00
|
|
|
.retry(3)
|
2017-09-04 17:23:56 +00:00
|
|
|
.doOnError(onError);
|
2017-09-03 02:30:34 +00:00
|
|
|
}
|
2017-08-29 00:38:37 +00:00
|
|
|
}
|