|
@@ -18,12 +18,14 @@ import android.widget.VideoView;
|
|
|
|
|
|
|
|
import com.kfzs.duanduan.utils.NumberFormatUtils;
|
|
import com.kfzs.duanduan.utils.NumberFormatUtils;
|
|
|
import com.kfzs.duanduan.utils.StatusBarUtils;
|
|
import com.kfzs.duanduan.utils.StatusBarUtils;
|
|
|
|
|
+import com.sheep.gamegroup.absBase.AbsObserver;
|
|
|
import com.sheep.gamegroup.absBase.BaseContainerActivity;
|
|
import com.sheep.gamegroup.absBase.BaseContainerActivity;
|
|
|
import com.sheep.gamegroup.model.entity.DiscoveryTopic;
|
|
import com.sheep.gamegroup.model.entity.DiscoveryTopic;
|
|
|
-import com.sheep.gamegroup.util.ActionUtil;
|
|
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.Video;
|
|
|
import com.sheep.gamegroup.util.DataUtil;
|
|
import com.sheep.gamegroup.util.DataUtil;
|
|
|
import com.sheep.gamegroup.util.KeyEventUtil;
|
|
import com.sheep.gamegroup.util.KeyEventUtil;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.MediaHandleUtil;
|
|
|
import com.sheep.gamegroup.util.TestUtil;
|
|
import com.sheep.gamegroup.util.TestUtil;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.gamegroup.view.customview.VideoFramesView;
|
|
import com.sheep.gamegroup.view.customview.VideoFramesView;
|
|
@@ -31,6 +33,11 @@ import com.sheep.gamegroup.view.fragment.FgtDiscoveryTopic;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Locale;
|
|
|
|
|
+
|
|
|
import butterknife.BindView;
|
|
import butterknife.BindView;
|
|
|
import rx.functions.Action1;
|
|
import rx.functions.Action1;
|
|
|
|
|
|
|
@@ -61,13 +68,15 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
return R.layout.act_edit_video;
|
|
return R.layout.act_edit_video;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static final long MAX_VIDEO_DURATION = 15_000L;//视频最大时长,超过需要剪切
|
|
|
|
|
+ private Video data;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void initView() {
|
|
public void initView() {
|
|
|
super.initView();
|
|
super.initView();
|
|
|
initVolume();
|
|
initVolume();
|
|
|
- String url = DataUtil.getObject(getIntent(), String.class);
|
|
|
|
|
- final long duration = DataUtil.getObject(getIntent(), Long.class);
|
|
|
|
|
- Uri uri = Uri.parse(url);
|
|
|
|
|
|
|
+ data = DataUtil.getObject(getIntent(), Video.class);
|
|
|
|
|
+ Uri uri = Uri.parse(data.getFilePath());
|
|
|
videoView.setOnInfoListener(this);
|
|
videoView.setOnInfoListener(this);
|
|
|
videoView.setOnPreparedListener(this);
|
|
videoView.setOnPreparedListener(this);
|
|
|
videoView.setOnErrorListener(this);
|
|
videoView.setOnErrorListener(this);
|
|
@@ -75,11 +84,13 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
videoView.addOnLayoutChangeListener(this);
|
|
videoView.addOnLayoutChangeListener(this);
|
|
|
// videoView.setMediaController(new MediaController(this));
|
|
// videoView.setMediaController(new MediaController(this));
|
|
|
videoView.setVideoURI(uri);
|
|
videoView.setVideoURI(uri);
|
|
|
- videoFramesView.initVideo(url, duration).showVideoList().setOnTimeChangeListener(new Action1<Float>() {
|
|
|
|
|
|
|
+ videoFramesView.initVideo(data).setMaxDuration(MAX_VIDEO_DURATION).showVideoList().setOnTimeChangeListener(new Action1<Float>() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void call(Float percent) {
|
|
|
|
|
- ViewUtil.setText(edit_video_time_tv, R.string.has_choose_x_second, NumberFormatUtils.retainMost1(duration * percent / 1000));
|
|
|
|
|
- if(TestUtil.isDev()) {
|
|
|
|
|
|
|
+ public void call(Float duration) {
|
|
|
|
|
+ ViewUtil.setText(edit_video_time_tv, R.string.has_choose_x_second, NumberFormatUtils.retainMost1(duration / 1000.0f));
|
|
|
|
|
+ if (TestUtil.isDev()) {
|
|
|
|
|
+ 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("\t");
|
|
|
edit_video_time_tv.append(videoFramesView.getLineInfo());
|
|
edit_video_time_tv.append(videoFramesView.getLineInfo());
|
|
|
}
|
|
}
|
|
@@ -104,33 +115,37 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
};
|
|
};
|
|
|
videoView.setOnTouchListener(listener);
|
|
videoView.setOnTouchListener(listener);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
private GestureDetector mGestureDetector;
|
|
private GestureDetector mGestureDetector;
|
|
|
|
|
|
|
|
//播放或者暂停
|
|
//播放或者暂停
|
|
|
private void playOrPause() {
|
|
private void playOrPause() {
|
|
|
- if(videoView.isPlaying()){
|
|
|
|
|
|
|
+ if (videoView.isPlaying()) {
|
|
|
pause();
|
|
pause();
|
|
|
} else {
|
|
} else {
|
|
|
play();
|
|
play();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//播放
|
|
//播放
|
|
|
- private void play(){
|
|
|
|
|
- if(videoView == null){
|
|
|
|
|
|
|
+ private void play() {
|
|
|
|
|
+ if (videoView == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
videoView.start();
|
|
videoView.start();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//暂停
|
|
//暂停
|
|
|
- private void pause(){
|
|
|
|
|
- if(videoView == null){
|
|
|
|
|
|
|
+ private void pause() {
|
|
|
|
|
+ if (videoView == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
videoView.pause();
|
|
videoView.pause();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//销毁
|
|
//销毁
|
|
|
- private void destroy(){
|
|
|
|
|
- if(videoView == null){
|
|
|
|
|
|
|
+ private void destroy() {
|
|
|
|
|
+ if (videoView == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
videoView.stopPlayback();
|
|
videoView.stopPlayback();
|
|
@@ -145,28 +160,33 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
@Override
|
|
@Override
|
|
|
protected void onResume() {
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
super.onResume();
|
|
|
- if(!isPauseByUser)
|
|
|
|
|
|
|
+ if (!isPauseByUser)
|
|
|
play();
|
|
play();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//是否是用户手机暂停
|
|
//是否是用户手机暂停
|
|
|
private boolean isPauseByUser;
|
|
private boolean isPauseByUser;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
protected void onPause() {
|
|
protected void onPause() {
|
|
|
super.onPause();
|
|
super.onPause();
|
|
|
- if(videoView != null && videoView.isPlaying())
|
|
|
|
|
|
|
+ if (videoView != null && videoView.isPlaying())
|
|
|
isPauseByUser = false;
|
|
isPauseByUser = false;
|
|
|
- if(video_loading != null)
|
|
|
|
|
|
|
+ if (video_loading != null)
|
|
|
video_loading.setVisibility(View.VISIBLE);
|
|
video_loading.setVisibility(View.VISIBLE);
|
|
|
pause();
|
|
pause();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
|
|
destroy();
|
|
destroy();
|
|
|
|
|
+ if (videoFramesView != null)
|
|
|
|
|
+ videoFramesView.onDestroy();
|
|
|
|
|
+ super.onDestroy();
|
|
|
|
|
+ mAudioManager = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// //滑动方向
|
|
|
|
|
|
|
+ // //滑动方向
|
|
|
// private int direction = 0;
|
|
// private int direction = 0;
|
|
|
// //左右滑动
|
|
// //左右滑动
|
|
|
// public static final int DIRECTION_LEFT_RIGHT = 1;
|
|
// public static final int DIRECTION_LEFT_RIGHT = 1;
|
|
@@ -194,6 +214,7 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
// playOrPause();
|
|
// playOrPause();
|
|
|
return super.onSingleTapConfirmed(e);
|
|
return super.onSingleTapConfirmed(e);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public boolean onScroll(MotionEvent e1, MotionEvent e2,
|
|
public boolean onScroll(MotionEvent e1, MotionEvent e2,
|
|
|
float distanceX, float distanceY) {
|
|
float distanceX, float distanceY) {
|
|
@@ -269,11 +290,13 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
private AudioManager mAudioManager;
|
|
private AudioManager mAudioManager;
|
|
|
private int mMaxVolume;//最大音量
|
|
private int mMaxVolume;//最大音量
|
|
|
private int mVolume;//当前音量
|
|
private int mVolume;//当前音量
|
|
|
- private void initVolume(){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private void initVolume() {
|
|
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
|
- if(mAudioManager != null)
|
|
|
|
|
|
|
+ if (mAudioManager != null)
|
|
|
mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
|
mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//滑动改变音量
|
|
//滑动改变音量
|
|
|
private void onVolumeSlide(float percent) {
|
|
private void onVolumeSlide(float percent) {
|
|
|
if (mVolume == -1) {
|
|
if (mVolume == -1) {
|
|
@@ -299,7 +322,9 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
// lp.width = findViewById(R.id.operation_full).getLayoutParams().width * index / mMaxVolume;
|
|
// lp.width = findViewById(R.id.operation_full).getLayoutParams().width * index / mMaxVolume;
|
|
|
// mOperationPercent.setLayoutParams(lp);
|
|
// mOperationPercent.setLayoutParams(lp);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
private float mBrightness = -1;
|
|
private float mBrightness = -1;
|
|
|
|
|
+
|
|
|
//滑动改变亮度
|
|
//滑动改变亮度
|
|
|
private void onBrightnessSlide(float percent) {
|
|
private void onBrightnessSlide(float percent) {
|
|
|
if (mBrightness < 0) {
|
|
if (mBrightness < 0) {
|
|
@@ -325,6 +350,7 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
// lp.width = (int) (findViewById(R.id.operation_full).getLayoutParams().width * lpa.screenBrightness);
|
|
// lp.width = (int) (findViewById(R.id.operation_full).getLayoutParams().width * lpa.screenBrightness);
|
|
|
// mOperationPercent.setLayoutParams(lp);
|
|
// mOperationPercent.setLayoutParams(lp);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
|
|
public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
|
|
|
LogUtil.println("ActPlayVideo", "onInfo what = " + what + " extra = " + extra);
|
|
LogUtil.println("ActPlayVideo", "onInfo what = " + what + " extra = " + extra);
|
|
@@ -333,23 +359,24 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
switch (what) {
|
|
switch (what) {
|
|
|
case MediaPlayer.MEDIA_INFO_BUFFERING_START:
|
|
case MediaPlayer.MEDIA_INFO_BUFFERING_START:
|
|
|
LogUtil.println("ActPlayVideo", "onInfo", "正在缓冲");
|
|
LogUtil.println("ActPlayVideo", "onInfo", "正在缓冲");
|
|
|
- if(video_loading != null)
|
|
|
|
|
|
|
+ if (video_loading != null)
|
|
|
video_loading.setVisibility(View.VISIBLE);
|
|
video_loading.setVisibility(View.VISIBLE);
|
|
|
break;
|
|
break;
|
|
|
case MediaPlayer.MEDIA_INFO_BUFFERING_END:
|
|
case MediaPlayer.MEDIA_INFO_BUFFERING_END:
|
|
|
case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
|
|
case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
|
|
|
LogUtil.println("ActPlayVideo", "onInfo", "缓冲完成");
|
|
LogUtil.println("ActPlayVideo", "onInfo", "缓冲完成");
|
|
|
//缓存完成,继续播放
|
|
//缓存完成,继续播放
|
|
|
- if(video_loading != null)
|
|
|
|
|
|
|
+ if (video_loading != null)
|
|
|
video_loading.setVisibility(View.GONE);
|
|
video_loading.setVisibility(View.GONE);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void onPrepared(MediaPlayer mediaPlayer) {
|
|
public void onPrepared(MediaPlayer mediaPlayer) {
|
|
|
LogUtil.println("ActPlayVideo", "onPrepared");
|
|
LogUtil.println("ActPlayVideo", "onPrepared");
|
|
|
- if(video_loading != null)
|
|
|
|
|
|
|
+ if (video_loading != null)
|
|
|
video_loading.setVisibility(View.GONE);
|
|
video_loading.setVisibility(View.GONE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -366,6 +393,7 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
|
|
|
|
|
private int windowWidth = G.WIDTH;
|
|
private int windowWidth = G.WIDTH;
|
|
|
private int windowHeight = G.HEIGHT;
|
|
private int windowHeight = G.HEIGHT;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
|
public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
|
|
LogUtil.println("ActPlayVideo", "onLayoutChange", left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom);
|
|
LogUtil.println("ActPlayVideo", "onLayoutChange", left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom);
|
|
@@ -381,17 +409,20 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
@BindView(R.id.frame_container)
|
|
@BindView(R.id.frame_container)
|
|
|
View frame_container;
|
|
View frame_container;
|
|
|
|
|
|
|
|
- //添加话题
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void doNextAction(Object action) {
|
|
|
|
|
- if(action instanceof DiscoveryTopic){
|
|
|
|
|
- ViewUtil.setText(edit_video_topic_tv, "#%s#", ((DiscoveryTopic) action).getTopic());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ protected boolean needRegisterEventBus() {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Subscribe
|
|
|
|
|
+ public void onEventMainThread(DiscoveryTopic result) {
|
|
|
|
|
+ ViewUtil.setText(edit_video_topic_tv, "#%s#", result.getTopic());
|
|
|
|
|
+ data.setTopicId(result.getId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//点击话题进行切换
|
|
//点击话题进行切换
|
|
|
public void onClickTopic(View view) {
|
|
public void onClickTopic(View view) {
|
|
|
- if(ViewUtil.isVisible(frame_container)){
|
|
|
|
|
|
|
+ if (ViewUtil.isVisible(frame_container)) {
|
|
|
ViewUtil.setText(edit_video_sure_tv, "完成");
|
|
ViewUtil.setText(edit_video_sure_tv, "完成");
|
|
|
} else {
|
|
} else {
|
|
|
ViewUtil.setText(edit_video_sure_tv, "下一步");
|
|
ViewUtil.setText(edit_video_sure_tv, "下一步");
|
|
@@ -402,16 +433,33 @@ public class ActEditVideo extends BaseContainerActivity implements MediaPlayer.O
|
|
|
//点击返回
|
|
//点击返回
|
|
|
public void onClickBackImg(View view) {
|
|
public void onClickBackImg(View view) {
|
|
|
KeyEventUtil.sendKeyDownUp(KeyEvent.KEYCODE_BACK);
|
|
KeyEventUtil.sendKeyDownUp(KeyEvent.KEYCODE_BACK);
|
|
|
- ActionUtil.getInstance().getAction(ActPublishArticle.class.getSimpleName());//清除掉选中的话题
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//点击确定
|
|
//点击确定
|
|
|
public void onClickSure(View view) {
|
|
public void onClickSure(View view) {
|
|
|
- if(ViewUtil.isVisible(frame_container)){//首先隐藏话题列表
|
|
|
|
|
|
|
+ if (ViewUtil.isVisible(frame_container)) {//首先隐藏话题列表
|
|
|
ViewUtil.setVisibility(frame_container, false);
|
|
ViewUtil.setVisibility(frame_container, false);
|
|
|
ViewUtil.setText(edit_video_sure_tv, "完成");
|
|
ViewUtil.setText(edit_video_sure_tv, "完成");
|
|
|
} else {//其次完成编辑
|
|
} else {//其次完成编辑
|
|
|
- G.showToast("完成操作");
|
|
|
|
|
|
|
+ G.showToast("开始剪切");
|
|
|
|
|
+ new MediaHandleUtil(data.getFilePath(), videoFramesView.getStartPoint() * 1000, videoFramesView.getLineDuration() * 1000)
|
|
|
|
|
+ .tryCutVideo(new AbsObserver<Video>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(Video video) {
|
|
|
|
|
+ data.setFilePath(video.getFilePath());
|
|
|
|
|
+ data.setWidth(video.getWidth());
|
|
|
|
|
+ data.setHeight(video.getHeight());
|
|
|
|
|
+ data.setDuration(video.getDuration());
|
|
|
|
|
+ EventBus.getDefault().post(data);
|
|
|
|
|
+ G.showToast("完成剪切");
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(Throwable e) {
|
|
|
|
|
+ G.showToast(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|