|
@@ -8,6 +8,7 @@ import android.media.MediaPlayer;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
|
import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.Toast;
|
|
@@ -15,21 +16,29 @@ import android.widget.Toast;
|
|
|
import com.chivox.aiengine.EvalResult;
|
|
|
import com.edufound.reader.base.BaseActivity;
|
|
|
import com.edufound.reader.base.BasePresenter;
|
|
|
+import com.edufound.reader.bean.HttpResultBean;
|
|
|
import com.edufound.reader.bean.RecordResultBean;
|
|
|
+import com.edufound.reader.bean.UserRecordBean;
|
|
|
import com.edufound.reader.contract.RecordContract;
|
|
|
import com.edufound.reader.cusview.FullScreenVideoController;
|
|
|
import com.edufound.reader.cusview.RvListJzvdStd;
|
|
|
import com.edufound.reader.listener.PopupRecordStatusListener;
|
|
|
import com.edufound.reader.model.RecordModel;
|
|
|
import com.edufound.reader.popwindow.PopWindowUtil;
|
|
|
+import com.edufound.reader.receiver.BackPageReceiver;
|
|
|
import com.edufound.reader.services.RecordServices;
|
|
|
+import com.edufound.reader.util.GlideUtils;
|
|
|
import com.edufound.reader.videoutil.JZMediaIjk;
|
|
|
import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
+import com.okhttplib.HttpInfo;
|
|
|
+import com.okhttplib.callback.Callback;
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -41,7 +50,14 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
|
|
|
RecordServices mRecordServices;
|
|
|
RecordModel mModel;
|
|
|
- RvListJzvdStd mVideoView;
|
|
|
+ String mReadId = null;
|
|
|
+ String exampleUrl = "";
|
|
|
+ String recordUrl = "";
|
|
|
+ UserRecordBean.UserRead mRecordUserRead;
|
|
|
+ //READ是用户在读,example是厅官方
|
|
|
+ String playType = "EXAMPLE";
|
|
|
+
|
|
|
+ boolean isRecording = false;
|
|
|
|
|
|
public RecordPresenter() {
|
|
|
this.mModel = new RecordModel();
|
|
@@ -49,11 +65,9 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void createVideoPlayer(FrameLayout frame) {
|
|
|
+ public void createVideoPlayer() {
|
|
|
mView.showLoading();
|
|
|
- mVideoView = new RvListJzvdStd(mView.getActivity());
|
|
|
- mVideoView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
- mVideoView.setVideoCallBack(new RvListJzvdStd.VideoCallBack() {
|
|
|
+ mView.getJZVideoView().setVideoCallBack(new RvListJzvdStd.VideoCallBack() {
|
|
|
@Override
|
|
|
public void onComplete() {
|
|
|
onVideoCompletion();
|
|
@@ -69,24 +83,59 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
onVideoInfoListener(what, extra);
|
|
|
}
|
|
|
});
|
|
|
- frame.addView(mVideoView);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void initVideoPlayer(Intent intent) {
|
|
|
+ public void getReadInfo(Intent intent) {
|
|
|
Bundle params = intent.getBundleExtra("params_bundle");
|
|
|
- String index = params.getString("index");
|
|
|
- String play_url = params.getString("playUrl");
|
|
|
- //play_url没传
|
|
|
- play_url = "https://reader-wx.ai160.com/reader/resource/video/1610961140479648.mp4";
|
|
|
- Toast.makeText(mView.getActivity(), "index:" + index, Toast.LENGTH_SHORT).show();
|
|
|
- mVideoView.setUp(new JZDataSource(play_url), JzvdStd.SCREEN_FULLSCREEN, JZMediaIjk.class);
|
|
|
-// mVideoView.startVideoAfterPreloading();
|
|
|
+ mReadId = params.getString("exampleId");
|
|
|
+ mModel.getReadInfo(mView.getActivity(), mReadId, new Callback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(HttpInfo info) throws IOException {
|
|
|
+ HttpResultBean<UserRecordBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<UserRecordBean>>() {
|
|
|
+ }.getType());
|
|
|
+ mRecordUserRead = bean.getData().getUserRead();
|
|
|
+ exampleUrl = mRecordUserRead.getVideoPath();
|
|
|
+ recordUrl = mRecordUserRead.getOriginVideo();
|
|
|
+ GlideUtils.loadImageSizeKipMemoryCache(mView.getActivity(), mRecordUserRead.getCoverImg(), mView.getJZVideoView().posterImageView);
|
|
|
+ mView.getJZVideoView().setUp(new JZDataSource(exampleUrl), JzvdStd.SCREEN_FULLSCREEN, JZMediaIjk.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(HttpInfo info) throws IOException {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onVideoCompletion() {
|
|
|
+ public String getExampleUrl() {
|
|
|
+ return exampleUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getRecordUrl() {
|
|
|
+ return recordUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void clickExampleUI() {
|
|
|
+ playType = "EXAMPLE";
|
|
|
+ initVideoPlayer(exampleUrl);
|
|
|
+ mView.getJZVideoView().startVideoAfterPreloading();
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void initVideoPlayer(String url) {
|
|
|
+ Logger.e("url:" + url);
|
|
|
+ mView.getJZVideoView().setUp(new JZDataSource(url), JzvdStd.SCREEN_FULLSCREEN, JZMediaIjk.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onVideoCompletion() {
|
|
|
+ if (playType.equals("READ")) {
|
|
|
+ stopRecord();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -95,10 +144,12 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
case -10000:
|
|
|
// mVideoHandler.sendEmptyMessage(DISCONNECT_NETWORK);
|
|
|
Toast.makeText(mView.getActivity(), "网络出现异常", Toast.LENGTH_SHORT).show();
|
|
|
+ mView.getActivity().finish();
|
|
|
break;
|
|
|
default:
|
|
|
- mVideoView.pauseVideo();
|
|
|
- mVideoView.reset();
|
|
|
+ mView.getJZVideoView().pauseVideo();
|
|
|
+ mView.getJZVideoView().reset();
|
|
|
+ mView.getJZVideoView().onStatePreparingPlaying();
|
|
|
Toast.makeText(mView.getActivity(), "视频异常--what:" + what + "--extra:" + extra, Toast.LENGTH_SHORT).show();
|
|
|
mView.getActivity().finish();
|
|
|
break;
|
|
@@ -108,12 +159,16 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
|
|
|
@Override
|
|
|
public void onVideoInfoListener(int what, int extra) {
|
|
|
- switch (what) {
|
|
|
- case MediaPlayer.MEDIA_INFO_BUFFERING_START:
|
|
|
- mView.showLoading();
|
|
|
- break;
|
|
|
- case MediaPlayer.MEDIA_INFO_BUFFERING_END:
|
|
|
- mView.hideLoading();
|
|
|
+ Logger.e("状态:" + mView.getJZVideoView().state + "---+what:" + what);
|
|
|
+
|
|
|
+ switch (mView.getJZVideoView().state) {
|
|
|
+ case Jzvd.STATE_PLAYING:
|
|
|
+ //已经开始播放了
|
|
|
+ if (playType.equals("READ") && (mRecordServices.getIsRecording() == false)) {
|
|
|
+ Logger.e("准备完毕,可以播放");
|
|
|
+ mRecordServices.startRecord(mView.getActivity(), mRecordUserRead.getId(), mRecordUserRead.getLessonText());
|
|
|
+ mView.getJZVideoView().setCanPause(false);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -122,17 +177,26 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
public void addVideoController(FrameLayout frame) {
|
|
|
// mVideoController = (FrameLayout) LayoutInflater.from(mView.getActivity()).inflate(R.layout.player_controller, null);
|
|
|
// frame.addView(mVideoController);
|
|
|
- frame.addView(new FullScreenVideoController(mView.getActivity()).getController());
|
|
|
+// frame.addView(new FullScreenVideoController(mView.getActivity()).getController());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void startRecord(String name, String refText) {
|
|
|
- mRecordServices.startRecord(mView.getActivity(), name, refText);
|
|
|
+ public void startRecord() {
|
|
|
+ mView.hasShowOtherUI(View.INVISIBLE);
|
|
|
+ playType = "READ";
|
|
|
+ initVideoPlayer(recordUrl);
|
|
|
+ mView.getJZVideoView().startVideo();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void stopRecord() {
|
|
|
+ mView.hasShowOtherUI(View.VISIBLE);
|
|
|
+ mView.getJZVideoView().pauseVideo();
|
|
|
mRecordServices.stopRecord();
|
|
|
+// mView.getJZVideoView().setCanPause(true);
|
|
|
+// initVideoPlayer(recordUrl);
|
|
|
+ mView.getJZVideoView().posterImageView.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -143,9 +207,12 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
|
|
|
@Override
|
|
|
public void activityDestroy() {
|
|
|
- mVideoView.pauseVideo();
|
|
|
+ mView.getJZVideoView().pauseVideo();
|
|
|
+ mRecordServices.cancelRecord();
|
|
|
Jzvd.releaseAllVideos();
|
|
|
- mVideoView = null;
|
|
|
+// Intent intent = new Intent(BackPageReceiver.BACK_HOME_REF_VIDEO_ITEM);
|
|
|
+//// intent.putExtra("recordId", );
|
|
|
+// mView.getActivity().sendBroadcast(intent);
|
|
|
recordServicesConn = null;
|
|
|
mRecordServices = null;
|
|
|
}
|
|
@@ -161,8 +228,8 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void showRecordStatusWindow(RecordResultBean bean) {
|
|
|
- PopWindowUtil.showRecordStatusWindow(mView.getActivity(), mView.getRootView(), bean, new PopupRecordStatusListener() {
|
|
|
+ public void showRecordStatusWindow(RecordResultBean bean, UserRecordBean.UserRead userread) {
|
|
|
+ PopWindowUtil.showRecordStatusWindow(mView.getActivity(), mView.getRootView(), bean, userread, new PopupRecordStatusListener() {
|
|
|
@Override
|
|
|
public void clickReRecord() {
|
|
|
Toast.makeText(mView.getActivity(), "重新录制", Toast.LENGTH_SHORT).show();
|
|
@@ -199,7 +266,7 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
|
|
|
@Override
|
|
|
public void onRecordResult(String tokenId, EvalResult result) {
|
|
|
- Logger.e("录音停止");
|
|
|
+ Logger.e("录音完成");
|
|
|
Log.e("com.edufound.reader", "record-result:" + result);
|
|
|
Log.e("com.edufound.reader", "record-result.text:" + result.text());
|
|
|
try {
|
|
@@ -214,10 +281,10 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
int integrity = Integer.valueOf(jsonObject.getString("integrity"));
|
|
|
//正确率
|
|
|
int accuracy = Integer.valueOf(jsonObject.getString("accuracy"));
|
|
|
- mVideoView.post(new Runnable() {
|
|
|
+ mView.getJZVideoView().post(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- showRecordStatusWindow(new RecordResultBean(overall, speed, tone, integrity, accuracy));
|
|
|
+ showRecordStatusWindow(new RecordResultBean(overall, speed, tone, integrity, accuracy), mRecordUserRead);
|
|
|
}
|
|
|
});
|
|
|
} catch (JSONException e) {
|
|
@@ -236,6 +303,11 @@ public class RecordPresenter extends BasePresenter<RecordContract.View> implemen
|
|
|
public void onRecordError(String tokenId, EvalResult result) {
|
|
|
Toast.makeText(mView.getActivity(), "录音失败:" + result.text(), Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRecordStop() {
|
|
|
+ Logger.e("录音停止");
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|