Search in sources :

Example 1 with VideoException

use of com.dante.exception.VideoException in project 91Pop by DanteAndroid.

the class PlayVideoPresenter method loadVideoUrl.

@Override
public void loadVideoUrl(final UnLimit91PornItem unLimit91PornItem) {
    String viewKey = unLimit91PornItem.getViewKey();
    dataManager.loadPorn91VideoUrl(viewKey).map(new Function<VideoResult, VideoResult>() {

        @Override
        public VideoResult apply(VideoResult videoResult) throws VideoException {
            if (TextUtils.isEmpty(videoResult.getVideoUrl())) {
                if (VideoResult.OUT_OF_WATCH_TIMES.equals(videoResult.getId())) {
                    // 尝试强行重置,并上报异常
                    cookieManager.resetPorn91VideoWatchTiem(true);
                    Bugsnag.notify(new Throwable(TAG + ":ten videos each day "), Severity.WARNING);
                    throw new VideoException("观看次数达到上限了!");
                } else {
                    throw new VideoException("解析视频链接失败了");
                }
            }
            return videoResult;
        }
    }).retryWhen(new RetryWhenProcess(RetryWhenProcess.PROCESS_TIME)).compose(RxSchedulersHelper.<VideoResult>ioMainThread()).compose(provider.<VideoResult>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<VideoResult>() {

        @Override
        public void onBegin(Disposable d) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    view.showParsingDialog();
                }
            });
        }

        @Override
        public void onSuccess(final VideoResult videoResult) {
            cookieManager.resetPorn91VideoWatchTiem(false);
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    view.playVideo(saveVideoUrl(videoResult, unLimit91PornItem));
                }
            });
        }

        @Override
        public void onError(final String msg, int code) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    view.errorParseVideoUrl(msg);
                }
            });
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) VideoException(com.dante.exception.VideoException) VideoResult(com.dante.data.model.VideoResult) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 VideoResult (com.dante.data.model.VideoResult)1 VideoException (com.dante.exception.VideoException)1 RetryWhenProcess (com.dante.rxjava.RetryWhenProcess)1 Disposable (io.reactivex.disposables.Disposable)1