|
@@ -4,10 +4,10 @@ import android.content.Intent;
|
|
|
import android.media.MediaPlayer;
|
|
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.view.KeyEvent;
|
|
import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
-import android.widget.VideoView;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.kfzs.cfyl.media.BaseContainerActivity;
|
|
import com.kfzs.cfyl.media.BaseContainerActivity;
|
|
@@ -23,9 +23,11 @@ import com.kfzs.cfyl.media.util.ViewUtil;
|
|
|
import com.kfzs.cfyl.share_library.util.LogUtil;
|
|
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.view.VideoPlayerGLSurfaceView;
|
|
|
|
|
+
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
import rx.functions.Action1;
|
|
import rx.functions.Action1;
|
|
|
|
|
|
|
@@ -34,10 +36,9 @@ import rx.functions.Action1;
|
|
|
* realicing@sina.com
|
|
* realicing@sina.com
|
|
|
* 添加话题并剪切视频
|
|
* 添加话题并剪切视频
|
|
|
*/
|
|
*/
|
|
|
-public class ActCutVideo extends BaseContainerActivity implements MediaPlayer.OnInfoListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener, IdChooser {
|
|
|
|
|
|
|
+public class ActCutVideo extends BaseContainerActivity implements IdChooser {
|
|
|
|
|
|
|
|
- VideoView videoView;
|
|
|
|
|
- View video_loading;
|
|
|
|
|
|
|
+ VideoPlayerGLSurfaceView mPlayerView;
|
|
|
VideoFramesView videoFramesView;
|
|
VideoFramesView videoFramesView;
|
|
|
TextView edit_video_time_tv;
|
|
TextView edit_video_time_tv;
|
|
|
|
|
|
|
@@ -70,22 +71,44 @@ public class ActCutVideo extends BaseContainerActivity implements MediaPlayer.On
|
|
|
if (arrayList != null && fragment instanceof FgtDiscoveryTopic)
|
|
if (arrayList != null && fragment instanceof FgtDiscoveryTopic)
|
|
|
((FgtDiscoveryTopic) fragment).loadData(arrayList);
|
|
((FgtDiscoveryTopic) fragment).loadData(arrayList);
|
|
|
data = JSONObject.parseObject(intent.getStringExtra(String.class.getSimpleName()), Video.class);
|
|
data = JSONObject.parseObject(intent.getStringExtra(String.class.getSimpleName()), Video.class);
|
|
|
- Uri uri = Uri.parse(data.getFilePath());
|
|
|
|
|
|
|
|
|
|
- videoView = findViewById(R.id.media_videoView);
|
|
|
|
|
- video_loading = findViewById(R.id.media_video_loading);
|
|
|
|
|
|
|
+ mPlayerView = findViewById(R.id.videoGLSurfaceView);
|
|
|
videoFramesView = findViewById(R.id.media_videoFramesView);
|
|
videoFramesView = findViewById(R.id.media_videoFramesView);
|
|
|
edit_video_time_tv = findViewById(R.id.media_edit_video_time_tv);
|
|
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_topic_tv = findViewById(R.id.media_edit_video_topic_tv);
|
|
|
edit_video_sure_tv = findViewById(R.id.media_edit_video_sure_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);
|
|
|
|
|
|
|
|
- videoView.setOnInfoListener(this);
|
|
|
|
|
- videoView.setOnPreparedListener(this);
|
|
|
|
|
- videoView.setOnErrorListener(this);
|
|
|
|
|
- videoView.setOnCompletionListener(this);
|
|
|
|
|
-// videoView.setMediaController(new MediaController(this));
|
|
|
|
|
- videoView.setVideoURI(uri);
|
|
|
|
|
|
|
+ //播放视频
|
|
|
|
|
+ mPlayerView.setZOrderOnTop(false);
|
|
|
|
|
+ mPlayerView.setZOrderMediaOverlay(true);
|
|
|
|
|
+// if(data.getOrientation() > 0)
|
|
|
|
|
+// mPlayerView.setRotation(360 - data.getOrientation());
|
|
|
|
|
+ mPlayerView.setPlayerInitializeCallback(new VideoPlayerGLSurfaceView.PlayerInitializeCallback() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initPlayer(final MediaPlayer player) {
|
|
|
|
|
+ //针对网络视频进行进度检查
|
|
|
|
|
+ player.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onBufferingUpdate(MediaPlayer mp, int percent) {
|
|
|
|
|
+ Log.i(Common.LOG_TAG, "Buffer update: " + percent);
|
|
|
|
|
+ if (percent == 100) {
|
|
|
|
|
+ Log.i(Common.LOG_TAG, "缓冲完毕!");
|
|
|
|
|
+ player.setOnBufferingUpdateListener(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ mPlayerView.setVideoUri(Uri.parse(data.getFilePath()), new VideoPlayerGLSurfaceView.PlayPreparedCallback() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void playPrepared(MediaPlayer player) {
|
|
|
|
|
+ Log.i(Common.LOG_TAG, "The video is prepared to play");
|
|
|
|
|
+ player.start();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, playCompletionCallback);
|
|
|
|
|
+
|
|
|
|
|
+ //视频帧
|
|
|
videoFramesView.initVideo(data).setMaxDuration(MAX_VIDEO_DURATION).showVideoList(this).setOnTimeChangeListener(new Action1<Float>() {
|
|
videoFramesView.initVideo(data).setMaxDuration(MAX_VIDEO_DURATION).showVideoList(this).setOnTimeChangeListener(new Action1<Float>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void call(Float duration) {
|
|
public void call(Float duration) {
|
|
@@ -122,106 +145,40 @@ public class ActCutVideo extends BaseContainerActivity implements MediaPlayer.On
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- //播放或者暂停
|
|
|
|
|
- private void playOrPause() {
|
|
|
|
|
- if (videoView.isPlaying()) {
|
|
|
|
|
- pause();
|
|
|
|
|
- } else {
|
|
|
|
|
- play();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //播放
|
|
|
|
|
- private void play() {
|
|
|
|
|
- if (videoView == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- videoView.start();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //暂停
|
|
|
|
|
- private void pause() {
|
|
|
|
|
- if (videoView == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- videoView.pause();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //销毁
|
|
|
|
|
- private void destroy() {
|
|
|
|
|
- if (videoView == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- videoView.stopPlayback();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- protected void onResume() {
|
|
|
|
|
- super.onResume();
|
|
|
|
|
- if (!isPauseByUser)
|
|
|
|
|
- play();
|
|
|
|
|
|
|
+ public void onPause() {
|
|
|
|
|
+ super.onPause();
|
|
|
|
|
+ Log.i(VideoPlayerGLSurfaceView.LOG_TAG, "activity onPause...");
|
|
|
|
|
+ mPlayerView.release();
|
|
|
|
|
+ mPlayerView.onPause();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //是否是用户手机暂停
|
|
|
|
|
- private boolean isPauseByUser;
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- protected void onPause() {
|
|
|
|
|
- super.onPause();
|
|
|
|
|
- if (videoView != null && videoView.isPlaying())
|
|
|
|
|
- isPauseByUser = false;
|
|
|
|
|
- if (video_loading != null)
|
|
|
|
|
- video_loading.setVisibility(View.VISIBLE);
|
|
|
|
|
- pause();
|
|
|
|
|
|
|
+ public void onResume() {
|
|
|
|
|
+ super.onResume();
|
|
|
|
|
+ mPlayerView.onResume();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
- destroy();
|
|
|
|
|
if (videoFramesView != null)
|
|
if (videoFramesView != null)
|
|
|
videoFramesView.onDestroy();
|
|
videoFramesView.onDestroy();
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
|
|
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo what = " + what + " extra = " + extra);
|
|
|
|
|
- if (!mediaPlayer.isLooping())
|
|
|
|
|
- mediaPlayer.setLooping(true);
|
|
|
|
|
- switch (what) {
|
|
|
|
|
- case MediaPlayer.MEDIA_INFO_BUFFERING_START:
|
|
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo", "正在缓冲");
|
|
|
|
|
- if (video_loading != null)
|
|
|
|
|
- video_loading.setVisibility(View.VISIBLE);
|
|
|
|
|
- break;
|
|
|
|
|
- case MediaPlayer.MEDIA_INFO_BUFFERING_END:
|
|
|
|
|
- case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
|
|
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo", "缓冲完成");
|
|
|
|
|
- //缓存完成,继续播放
|
|
|
|
|
- if (video_loading != null)
|
|
|
|
|
- video_loading.setVisibility(View.GONE);
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ private VideoPlayerGLSurfaceView.PlayCompletionCallback playCompletionCallback = new VideoPlayerGLSurfaceView.PlayCompletionCallback() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void playComplete(MediaPlayer player) {
|
|
|
|
|
+ Log.i(Common.LOG_TAG, "The video playing is over, restart...");
|
|
|
|
|
+ player.start();
|
|
|
}
|
|
}
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onPrepared(MediaPlayer mediaPlayer) {
|
|
|
|
|
- LogUtil.println("ActPlayVideo", "onPrepared");
|
|
|
|
|
- if (video_loading != null)
|
|
|
|
|
- video_loading.setVisibility(View.GONE);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
|
|
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo what = " + what + " extra = " + extra);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onCompletion(MediaPlayer mediaPlayer) {
|
|
|
|
|
- LogUtil.println("ActPlayVideo", "onCompletion");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean playFailed(MediaPlayer player, final int what, final int extra) {
|
|
|
|
|
+ G.showToast(getApplicationContext(), "播放出错,请稍候重试");
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
//点击话题进行切换
|
|
//点击话题进行切换
|
|
|
public void onClickTopic(View view) {
|
|
public void onClickTopic(View view) {
|