|
@@ -5,45 +5,38 @@ import android.media.MediaPlayer;
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
import android.support.v4.app.Fragment;
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
-import android.view.KeyEvent;
|
|
|
|
|
|
|
+import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
-import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.kfzs.cfyl.media.BaseContainerActivity;
|
|
|
|
|
|
|
+import com.kfzs.cfyl.media.BaseListFgtActivity;
|
|
|
import com.kfzs.cfyl.media.R;
|
|
import com.kfzs.cfyl.media.R;
|
|
|
|
|
+import com.kfzs.cfyl.media.api.FgtCreater;
|
|
|
import com.kfzs.cfyl.media.api.IdChooser;
|
|
import com.kfzs.cfyl.media.api.IdChooser;
|
|
|
-import com.kfzs.cfyl.media.customview.VideoFramesView;
|
|
|
|
|
|
|
+import com.kfzs.cfyl.media.bean.EditVideoType;
|
|
|
import com.kfzs.cfyl.media.fragment.FgtDiscoveryTopic;
|
|
import com.kfzs.cfyl.media.fragment.FgtDiscoveryTopic;
|
|
|
|
|
+import com.kfzs.cfyl.media.fragment.FgtDoodle;
|
|
|
|
|
+import com.kfzs.cfyl.media.fragment.FgtEditVideoTypeList;
|
|
|
|
|
+import com.kfzs.cfyl.media.fragment.FgtVideoFrameList;
|
|
|
import com.kfzs.cfyl.media.util.G;
|
|
import com.kfzs.cfyl.media.util.G;
|
|
|
-import com.kfzs.cfyl.media.util.KeyEventUtil;
|
|
|
|
|
import com.kfzs.cfyl.media.util.ListUtil;
|
|
import com.kfzs.cfyl.media.util.ListUtil;
|
|
|
-import com.kfzs.cfyl.media.util.VideoUtil;
|
|
|
|
|
-import com.kfzs.cfyl.media.util.ViewUtil;
|
|
|
|
|
-import com.kfzs.cfyl.share_library.util.LogUtil;
|
|
|
|
|
import com.sheep.gamegroup.model.entity.Video;
|
|
import com.sheep.gamegroup.model.entity.Video;
|
|
|
|
|
|
|
|
import org.wysaid.common.Common;
|
|
import org.wysaid.common.Common;
|
|
|
import org.wysaid.view.VideoPlayerGLSurfaceView;
|
|
import org.wysaid.view.VideoPlayerGLSurfaceView;
|
|
|
|
|
|
|
|
-import java.text.DecimalFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
-
|
|
|
|
|
-import rx.functions.Action1;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by realicing on 2018/11/9.
|
|
* Created by realicing on 2018/11/9.
|
|
|
* realicing@sina.com
|
|
* realicing@sina.com
|
|
|
* 添加话题并剪切视频
|
|
* 添加话题并剪切视频
|
|
|
*/
|
|
*/
|
|
|
-public class ActCutVideo extends BaseContainerActivity implements IdChooser {
|
|
|
|
|
|
|
+public class ActCutVideo extends BaseListFgtActivity implements IdChooser {
|
|
|
|
|
|
|
|
VideoPlayerGLSurfaceView mPlayerView;
|
|
VideoPlayerGLSurfaceView mPlayerView;
|
|
|
- VideoFramesView videoFramesView;
|
|
|
|
|
- TextView edit_video_time_tv;
|
|
|
|
|
|
|
|
|
|
- TextView edit_video_topic_tv;
|
|
|
|
|
- TextView edit_video_sure_tv;
|
|
|
|
|
View frame_container;
|
|
View frame_container;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -51,34 +44,72 @@ public class ActCutVideo extends BaseContainerActivity implements IdChooser {
|
|
|
return R.layout.media_act_cut_video;
|
|
return R.layout.media_act_cut_video;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- public static final long MAX_VIDEO_DURATION = 15_000L;//视频最大时长,超过需要剪切
|
|
|
|
|
private Video data;
|
|
private Video data;
|
|
|
|
|
|
|
|
private ArrayList<String> arrayList;//主题列表
|
|
private ArrayList<String> arrayList;//主题列表
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void parseIntent(Intent intent) {
|
|
|
|
|
+ arrayList = intent.getStringArrayListExtra(ArrayList.class.getSimpleName());
|
|
|
|
|
+ data = JSONObject.parseObject(intent.getStringExtra(String.class.getSimpleName()), Video.class);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- protected Fragment initFragment() {
|
|
|
|
|
- return new FgtDiscoveryTopic();
|
|
|
|
|
|
|
+ protected List<FgtCreater> getFgtCreaterList() {
|
|
|
|
|
+ List<FgtCreater> fgtCreaterList = new ArrayList<>();
|
|
|
|
|
+ fgtCreaterList.add(new FgtCreater() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Fragment newInstance() {
|
|
|
|
|
+ return new FgtDiscoveryTopic();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ fgtCreaterList.add(new FgtCreater() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Fragment newInstance() {
|
|
|
|
|
+ return new FgtEditVideoTypeList();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ fgtCreaterList.add(new FgtCreater() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Fragment newInstance() {
|
|
|
|
|
+ return new FgtVideoFrameList();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return fgtCreaterList;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void initView() {
|
|
public void initView() {
|
|
|
super.initView();
|
|
super.initView();
|
|
|
-
|
|
|
|
|
- Intent intent = getIntent();
|
|
|
|
|
- arrayList = intent.getStringArrayListExtra(ArrayList.class.getSimpleName());
|
|
|
|
|
- if (arrayList != null && fragment instanceof FgtDiscoveryTopic)
|
|
|
|
|
- ((FgtDiscoveryTopic) fragment).loadData(arrayList);
|
|
|
|
|
- data = JSONObject.parseObject(intent.getStringExtra(String.class.getSimpleName()), Video.class);
|
|
|
|
|
-
|
|
|
|
|
mPlayerView = findViewById(R.id.videoGLSurfaceView);
|
|
mPlayerView = findViewById(R.id.videoGLSurfaceView);
|
|
|
- videoFramesView = findViewById(R.id.media_videoFramesView);
|
|
|
|
|
- edit_video_time_tv = findViewById(R.id.media_edit_video_time_tv);
|
|
|
|
|
- edit_video_topic_tv = findViewById(R.id.media_edit_video_topic_tv);
|
|
|
|
|
- edit_video_sure_tv = findViewById(R.id.media_edit_video_sure_tv);
|
|
|
|
|
frame_container = findViewById(R.id.media_frame_container);
|
|
frame_container = findViewById(R.id.media_frame_container);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onInitFragment(Fragment fragment, int position) {
|
|
|
|
|
+ super.onInitFragment(fragment, position);
|
|
|
|
|
+ if (fragment instanceof FgtDiscoveryTopic) {
|
|
|
|
|
+ if(arrayList != null)
|
|
|
|
|
+ ((FgtDiscoveryTopic) fragment).loadData(arrayList);
|
|
|
|
|
+ } else if (fragment instanceof FgtVideoFrameList) {
|
|
|
|
|
+ if(data != null)
|
|
|
|
|
+ ((FgtVideoFrameList) fragment).loadData(data);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onShowFragment(Fragment fragment, int position) {
|
|
|
|
|
+ super.onShowFragment(fragment, position);
|
|
|
|
|
+ if (fragment instanceof FgtVideoFrameList) {
|
|
|
|
|
+ if(data != null)
|
|
|
|
|
+ ((FgtVideoFrameList) fragment).tryCheckDuration();
|
|
|
|
|
+ } else if(fragment instanceof FgtDoodle){
|
|
|
|
|
+ if(data != null)
|
|
|
|
|
+ ((FgtDoodle) fragment).loadData(data);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initListener() {
|
|
|
//播放视频
|
|
//播放视频
|
|
|
mPlayerView.setZOrderOnTop(false);
|
|
mPlayerView.setZOrderOnTop(false);
|
|
|
mPlayerView.setZOrderMediaOverlay(true);
|
|
mPlayerView.setZOrderMediaOverlay(true);
|
|
@@ -107,44 +138,8 @@ public class ActCutVideo extends BaseContainerActivity implements IdChooser {
|
|
|
player.start();
|
|
player.start();
|
|
|
}
|
|
}
|
|
|
}, playCompletionCallback);
|
|
}, playCompletionCallback);
|
|
|
-
|
|
|
|
|
- //视频帧
|
|
|
|
|
- videoFramesView.initVideo(data).setMaxDuration(MAX_VIDEO_DURATION).showVideoList(this).setOnTimeChangeListener(new Action1<Float>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void call(Float duration) {
|
|
|
|
|
- if (duration == null)
|
|
|
|
|
- return;
|
|
|
|
|
- if (videoFramesView.getVisibility() == View.VISIBLE)
|
|
|
|
|
- checkDuration(duration.longValue());
|
|
|
|
|
- edit_video_time_tv.setText(getString(R.string.media_has_choose_x_second, new DecimalFormat("#.#").format(duration / 1000.0f)));
|
|
|
|
|
-// edit_video_time_tv.append("\t");
|
|
|
|
|
-// edit_video_time_tv.append(String.valueOf(duration));
|
|
|
|
|
-// edit_video_time_tv.append("\t");
|
|
|
|
|
-// edit_video_time_tv.append(String.valueOf(data.getDuration()));
|
|
|
|
|
-// edit_video_time_tv.append("\t");
|
|
|
|
|
-// edit_video_time_tv.append(String.format(Locale.CHINA, "%.1f秒-%.1f秒", videoFramesView.getStartPoint() / 1000.0f, videoFramesView.getEndPoint() / 1000.0f));
|
|
|
|
|
-// edit_video_time_tv.append("\t");
|
|
|
|
|
-// edit_video_time_tv.append(videoFramesView.getLineInfo());
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- //隐藏视频剪切相关view
|
|
|
|
|
- edit_video_time_tv.setVisibility(View.INVISIBLE);
|
|
|
|
|
- videoFramesView.setVisibility(View.INVISIBLE);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static final String TAG = ActCutVideo.class.getSimpleName();
|
|
|
|
|
-
|
|
|
|
|
- //检查有没有设置剪切视频的时长
|
|
|
|
|
- private void checkDuration(long duration) {
|
|
|
|
|
- LogUtil.println(TAG, data.getDuration(), duration);
|
|
|
|
|
- if ((data.getDuration() - duration) >= 500) {
|
|
|
|
|
- edit_video_sure_tv.setText(BTN_TEXT_CUT);
|
|
|
|
|
- } else {
|
|
|
|
|
- edit_video_sure_tv.setText(BTN_TEXT_FINISH);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onPause() {
|
|
public void onPause() {
|
|
|
super.onPause();
|
|
super.onPause();
|
|
@@ -159,13 +154,6 @@ public class ActCutVideo extends BaseContainerActivity implements IdChooser {
|
|
|
mPlayerView.onResume();
|
|
mPlayerView.onResume();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void onDestroy() {
|
|
|
|
|
- if (videoFramesView != null)
|
|
|
|
|
- videoFramesView.onDestroy();
|
|
|
|
|
- super.onDestroy();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private VideoPlayerGLSurfaceView.PlayCompletionCallback playCompletionCallback = new VideoPlayerGLSurfaceView.PlayCompletionCallback() {
|
|
private VideoPlayerGLSurfaceView.PlayCompletionCallback playCompletionCallback = new VideoPlayerGLSurfaceView.PlayCompletionCallback() {
|
|
|
@Override
|
|
@Override
|
|
|
public void playComplete(MediaPlayer player) {
|
|
public void playComplete(MediaPlayer player) {
|
|
@@ -180,89 +168,25 @@ public class ActCutVideo extends BaseContainerActivity implements IdChooser {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- //点击话题进行切换
|
|
|
|
|
- public void onClickTopic(View view) {
|
|
|
|
|
- ViewUtil.toggleVisibility(frame_container);
|
|
|
|
|
- ViewUtil.setText(edit_video_sure_tv, BTN_TEXT_NEXT);
|
|
|
|
|
- if (ViewUtil.isVisible(frame_container)) {
|
|
|
|
|
- ViewUtil.setVisibility2(edit_video_time_tv, false);
|
|
|
|
|
- ViewUtil.setVisibility2(videoFramesView, false);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //点击返回
|
|
|
|
|
- public void onClickBackImg(View view) {
|
|
|
|
|
- KeyEventUtil.sendKeyDownUp(KeyEvent.KEYCODE_BACK);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private static final String BTN_TEXT_NEXT = "下一步";
|
|
|
|
|
- private static final String BTN_TEXT_CUT = "剪切";
|
|
|
|
|
- private static final String BTN_TEXT_FINISH = "完成";
|
|
|
|
|
-
|
|
|
|
|
- //点击确定
|
|
|
|
|
- public void onClickSure(View view) {
|
|
|
|
|
- String btnText = ((TextView) view).getText().toString();
|
|
|
|
|
- switch (btnText) {
|
|
|
|
|
- case BTN_TEXT_NEXT:
|
|
|
|
|
- showCut();
|
|
|
|
|
- break;
|
|
|
|
|
- case BTN_TEXT_CUT:
|
|
|
|
|
- tryCut();
|
|
|
|
|
- break;
|
|
|
|
|
- case BTN_TEXT_FINISH:
|
|
|
|
|
- finishCut();
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onSelectId(int id) {
|
|
|
|
|
+ String item = ListUtil.getItem(arrayList, id);
|
|
|
|
|
+ if (item != null) {
|
|
|
|
|
+ data.setTopicIndex(id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void finishCut() {//完成剪切并返回数据
|
|
|
|
|
- Intent intent = new Intent();
|
|
|
|
|
- intent.putExtra(Video.class.getSimpleName(), data);
|
|
|
|
|
- setResult(RESULT_OK, intent);
|
|
|
|
|
- finish();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void tryCut() {//其次完成编辑
|
|
|
|
|
- showProgress().getTextView().setText("剪切视频中");
|
|
|
|
|
- VideoUtil.tryCutVideo(data.getFilePath(), videoFramesView.getStartPoint() * 1000, videoFramesView.getLineDuration() * 1000, new Action1<Object>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void call(final Object result) {
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- if (result instanceof Video) {
|
|
|
|
|
- Video video = (Video) result;
|
|
|
|
|
- data.setFilePath(video.getFilePath());
|
|
|
|
|
- data.setWidth(video.getWidth());
|
|
|
|
|
- data.setHeight(video.getHeight());
|
|
|
|
|
- data.setDuration(video.getDuration());
|
|
|
|
|
- sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + video.getFilePath())));
|
|
|
|
|
- hideProgress();
|
|
|
|
|
- G.showToast(getApplicationContext(), "剪切完成");
|
|
|
|
|
- finishCut();
|
|
|
|
|
- } else if (result instanceof Throwable) {
|
|
|
|
|
- hideProgress();
|
|
|
|
|
- G.showToast(getApplicationContext(), ((Throwable) result).getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private View curTouchView;
|
|
|
|
|
|
|
|
- private void showCut() {//首先隐藏话题列表
|
|
|
|
|
- ViewUtil.setVisibility(frame_container, false);
|
|
|
|
|
- ViewUtil.setVisibility2(edit_video_time_tv, true);
|
|
|
|
|
- ViewUtil.setVisibility2(videoFramesView, true);
|
|
|
|
|
- checkDuration(videoFramesView.getLineDuration());
|
|
|
|
|
|
|
+ public void setCurTouchView(View curTouchView) {
|
|
|
|
|
+ this.curTouchView = curTouchView;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void onSelectId(int id) {
|
|
|
|
|
- String item = ListUtil.getItem(arrayList, id);
|
|
|
|
|
- if (item != null) {
|
|
|
|
|
- data.setTopicIndex(id);
|
|
|
|
|
- ViewUtil.setText(edit_video_topic_tv, "#%s#", item);
|
|
|
|
|
|
|
+ public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
|
+ if(curTouchView != null){
|
|
|
|
|
+ return curTouchView.onTouchEvent(event);
|
|
|
}
|
|
}
|
|
|
|
|
+ return super.onTouchEvent(event);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|