|
|
@@ -0,0 +1,146 @@
|
|
|
+package com.miekir.eden.ui.home.video;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.os.Bundle;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.miekir.common.utils.ToastTool;
|
|
|
+import com.miekir.eden.R;
|
|
|
+import com.miekir.eden.kawayi.API;
|
|
|
+import com.miekir.eden.kawayi.bean.BaseBean;
|
|
|
+import com.miekir.eden.manager.EdenManager;
|
|
|
+import com.miekir.eden.tool.StringTool;
|
|
|
+import com.scwang.smart.refresh.layout.SmartRefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.jzvd.JZDataSource;
|
|
|
+import cn.jzvd.Jzvd;
|
|
|
+import cn.jzvd.JzvdStd;
|
|
|
+import io.reactivex.Observable;
|
|
|
+import io.reactivex.ObservableEmitter;
|
|
|
+import io.reactivex.ObservableOnSubscribe;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.functions.Action;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Copyright (C), 2019-2020, Miekir
|
|
|
+ *
|
|
|
+ * @author Miekir
|
|
|
+ * @date 2020/8/25 11:28
|
|
|
+ * Description: 视频播放类,这是一个全屏的界面
|
|
|
+ */
|
|
|
+public class KwyVideoActivity extends Activity {
|
|
|
+ public static final String KEY_URL = "url";
|
|
|
+ public static final String KEY_TITLE = "title";
|
|
|
+ private String mTitle;
|
|
|
+
|
|
|
+ private JzvdStd js_video;
|
|
|
+ private SmartRefreshLayout srl_video;
|
|
|
+ private boolean mIsLoading;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_video_play);
|
|
|
+
|
|
|
+ String url = getIntent().getStringExtra(KEY_URL);
|
|
|
+ String title = getIntent().getStringExtra(KEY_TITLE);
|
|
|
+ mTitle = StringTool.getString(R.string.video_beauty);
|
|
|
+ js_video = findViewById(R.id.js_video);
|
|
|
+
|
|
|
+ Jzvd.WIFI_TIP_DIALOG_SHOWED = true;
|
|
|
+ // 直接播放视频
|
|
|
+ VideoPlayer.setVideoPlayListener(new VideoPlayer.VideoPlayListener() {
|
|
|
+ @Override
|
|
|
+ public void onPlayComplete() {
|
|
|
+ //finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ JzvdStd.setCurrentJzvd(VideoPlayer.CURRENT_JZVD);
|
|
|
+ js_video.setUp(EdenManager.getInstance().getVideoUrl(), mTitle);
|
|
|
+ js_video.startVideo();
|
|
|
+ srl_video = findViewById(R.id.srl_video);
|
|
|
+ srl_video.setEnableRefresh(false);
|
|
|
+ srl_video.setOnLoadMoreListener(new OnLoadMoreListener() {
|
|
|
+ @Override
|
|
|
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ if (!mIsLoading) {
|
|
|
+ mIsLoading = true;
|
|
|
+ playNextVideo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ Jzvd.backPress();
|
|
|
+ super.onBackPressed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ JzvdStd.goOnPlayOnResume();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ JzvdStd.goOnPlayOnPause();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ JzvdStd.releaseAllVideos();
|
|
|
+ VideoPlayer.setVideoPlayListener(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void playNextVideo() {
|
|
|
+ Observable<String> observable = Observable.create(new ObservableOnSubscribe<String>() {
|
|
|
+ @Override
|
|
|
+ //将事件发射出去,持有观察者的对象
|
|
|
+ public void subscribe(ObservableEmitter<String> e) throws Exception {
|
|
|
+ String videoResult = HttpUtil.get(API.VIDEO, 5000);
|
|
|
+ try {
|
|
|
+ BaseBean baseBean = JSON.parseObject(videoResult, BaseBean.class);
|
|
|
+ String videoUrl = baseBean.getJson();
|
|
|
+ e.onNext(videoUrl);
|
|
|
+ e.onComplete();
|
|
|
+ } catch (Exception videoException) {
|
|
|
+ videoException.printStackTrace();
|
|
|
+ e.onError(new Exception());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ observable.observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .doOnNext(result -> {
|
|
|
+ mIsLoading = false;
|
|
|
+ srl_video.finishLoadMore();
|
|
|
+ //JzvdStd.startFullscreenDirectly(this, VideoPlayer.class, result, mTitle);
|
|
|
+ JZDataSource dataSource = new JZDataSource(result, mTitle);
|
|
|
+ js_video.changeUrl(dataSource, 0);
|
|
|
+ })
|
|
|
+ .doOnError(err -> {
|
|
|
+ mIsLoading = false;
|
|
|
+ srl_video.finishLoadMore();
|
|
|
+ ToastTool.showShort(StringTool.getString(R.string.video_get_failed));
|
|
|
+ err.printStackTrace();
|
|
|
+ })
|
|
|
+ .doOnComplete(new Action() {
|
|
|
+ @Override
|
|
|
+ public void run() throws Exception {
|
|
|
+ }
|
|
|
+ }).subscribe();
|
|
|
+ }
|
|
|
+}
|