Procházet zdrojové kódy

修正拍摄的视频封面方向错误的问题(视频方向无法修改,需要使用其它播放方案解决)

zengjiebin před 7 roky
rodič
revize
b2cf652f43

+ 41 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/DiscoveryVideo.java

@@ -1,8 +1,13 @@
 package com.sheep.gamegroup.model.entity;
 
+import android.net.Uri;
 import android.support.annotation.Nullable;
 
+import com.kfzs.duanduan.utils.NumberFormatUtils;
+
 import java.io.Serializable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * Created by realicing on 2018/11/27.
@@ -230,6 +235,42 @@ public class DiscoveryVideo implements Serializable {
         return obj instanceof DiscoveryVideo && ((DiscoveryVideo) obj).getId() == id;
     }
 
+
+
+    private int width;
+    private int height;
+    private int orientation;
+
+    private void initVideoInfo(){
+        if(width == 0 || height == 0 || orientation == 0 && cover != null){
+            Uri uri = Uri.parse(cover);
+            width = (int) NumberFormatUtils.parseFloat(uri.getQueryParameter("w"));
+            height = (int) NumberFormatUtils.parseFloat(uri.getQueryParameter("h"));
+            Pattern p = Pattern.compile("/rotate/(.*?)\\&");
+            Matcher m = p.matcher(cover);
+            if(m.find()) {
+                String result = m.group(1);
+                orientation = (int) NumberFormatUtils.parseFloat(result);
+//                String result = m.group(0);
+//                orientation = (int) NumberFormatUtils.parseFloat(result.substring("/rotate/".length(), result.length() - 1));
+            }
+        }
+    }
+    public int getWidth() {
+        initVideoInfo();
+        return width;
+    }
+
+    public int getHeight() {
+        initVideoInfo();
+        return height;
+    }
+
+    public int getOrientation() {
+        initVideoInfo();
+        return orientation;
+    }
+
     //非通过状态
     public boolean isInAudit() {
         return status != 1;

+ 2 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/ActMain.java

@@ -139,7 +139,8 @@ public class ActMain extends BaseActYmPermissionCheck {
 //        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && G.checkDeviceHasNavigationBar(this)) {
 //            main_layout.setPadding(0, 0, 0, G.getHasVirtualKey(this) - G.getNoHasVirtualKey(this));
 //        }
-        CommonUtil.getInstance().initMiDong(this, DataUtil.getInstance().getUserId());
+        if(!TestUtil.isDev())
+            CommonUtil.getInstance().initMiDong(this, DataUtil.getInstance().getUserId());
     }
 
     @Override

+ 2 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/ActPublishArticle.java

@@ -209,7 +209,8 @@ public class ActPublishArticle extends BaseActivity {
                             b = video.getWidth();
                             break;
                     }
-                    jsonObject.put("cover", String.format(Locale.CHINA, "%s?vframe/jpg/offset/0&w=%d&h=%d", url, a, b));
+                    int rotate = 360 - Math.max(0, video.getOrientation());
+                    jsonObject.put("cover", String.format(Locale.CHINA, "%s?vframe/jpg/offset/0/rotate/%d&w=%d&h=%d", url, rotate, a, b));
                     publishArticle(dialogProgress);
                 } else {
                     ViewUtil.setText(dialogProgress.getTextView(), "上传失败");

+ 8 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActVideoDetail.java

@@ -94,6 +94,7 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
     private int video_id;
     private int user_id;
     private String video_url;
+    private int orientation = 0;
     private DiscoveryVideo newVideo;
     private ArrayList<DiscoveryVideo> videoList;
     private int position;
@@ -117,6 +118,7 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
         video_id = lastVideo.getId();
         user_id = lastVideo.getUser_id();
         video_url = lastVideo.getResource();
+        orientation = lastVideo.getOrientation();
         loadVideoData(lastVideo);
     }
 
@@ -144,6 +146,12 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
         videoView.setOnCompletionListener(this);
 //        videoView.setMediaController(new MediaController(this));
         videoView.setVideoURI(getUri());
+        resetVideoOrientation();
+    }
+    //重新设置视频的方向,videoView没法设置方向
+    private void resetVideoOrientation(){
+//        if(orientation > 0 && orientation < 360)
+//            videoView.setRotation(orientation);
     }
     //转化地址
     private Uri getUri(){