Przeglądaj źródła

修改滤镜顺序

zengjiebin 7 lat temu
rodzic
commit
07419a50ea

+ 56 - 99
media/app/src/main/java/com/kfzs/cfyl/media/activity/ActCutVideo.java

@@ -4,10 +4,10 @@ import android.content.Intent;
 import android.media.MediaPlayer;
 import android.net.Uri;
 import android.support.v4.app.Fragment;
+import android.util.Log;
 import android.view.KeyEvent;
 import android.view.View;
 import android.widget.TextView;
-import android.widget.VideoView;
 
 import com.alibaba.fastjson.JSONObject;
 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.sheep.gamegroup.model.entity.Video;
 
+import org.wysaid.common.Common;
+import org.wysaid.view.VideoPlayerGLSurfaceView;
+
 import java.text.DecimalFormat;
 import java.util.ArrayList;
-import java.util.Locale;
 
 import rx.functions.Action1;
 
@@ -34,10 +36,9 @@ import rx.functions.Action1;
  * 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;
     TextView edit_video_time_tv;
 
@@ -70,22 +71,44 @@ public class ActCutVideo extends BaseContainerActivity implements MediaPlayer.On
         if (arrayList != null && fragment instanceof FgtDiscoveryTopic)
             ((FgtDiscoveryTopic) fragment).loadData(arrayList);
         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);
         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);
 
-        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>() {
             @Override
             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
-    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
-    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
     protected void onDestroy() {
-        destroy();
         if (videoFramesView != null)
             videoFramesView.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) {

+ 1 - 1
media/app/src/main/java/com/kfzs/cfyl/media/fragment/FgtChooseFilterList.java

@@ -92,7 +92,6 @@ public class FgtChooseFilterList extends BaseFragment {
     private List<IFilter> filterList = new ArrayList<>();
     private void initData() {
         filterList.add(new Filter("原图"));
-        ColorBalanceFilter.addDefaultFilterList(filterList);
         filterList.add(new WaveFilter("波浪").setPercent(1).setType(null));
         filterList.add(new Filter("浮雕").setConfig("#unpack @style emboss 1 2 2"));
         filterList.add(new Filter("半色调").setConfig("@style halftone 1.2"));
@@ -104,6 +103,7 @@ public class FgtChooseFilterList extends BaseFragment {
             filterList.add(new Filter("滤镜" + i).setConfig(item));
             i++;
         }
+        ColorBalanceFilter.addDefaultFilterList(filterList);
         ViewUtil.notifyDataSetChanged(recyclerView);
     }
 

+ 9 - 16
media/app/src/main/res/layout/media_act_cut_video.xml

@@ -7,29 +7,22 @@
     android:background="#000000"
     tools:context=".activity.ActCutVideo">
 
-    <VideoView
-        android:id="@+id/media_videoView"
+    <FrameLayout
+        android:id="@+id/glviewFrameLayout"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:layout_height="match_parent">
+
+        <org.wysaid.view.VideoPlayerGLSurfaceView
+            android:id="@+id/videoGLSurfaceView"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent" />
+    </FrameLayout>
 
     <View
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="#99000000" />
 
-    <com.github.ybq.android.spinkit.SpinKitView
-        android:id="@+id/media_video_loading"
-        style="@style/SpinKitView.Large.ThreeBounce"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        app:SpinKit_Color="@color/media_colorAccent"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
-
     <ImageView
         android:id="@+id/media_video_back_iv"
         android:layout_width="?attr/actionBarSize"