Commit 9fcf692dda990aec94feaebfc5b70e9971d1821e
1 parent
23b004d9
优化 加载速度
1:处理空文件夹问题
Showing
9 changed files
with
110 additions
and
77 deletions
app/src/main/AndroidManifest.xml
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | + xmlns:tools="http://schemas.android.com/tools" | |
| 3 | 4 | package="com.cnlive.strike.debug"> |
| 5 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
| 6 | + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |
| 7 | + <uses-permission android:name="android.permission.RECORD_AUDIO" /> | |
| 8 | + <uses-permission android:name="android.permission.CAMERA" /> | |
| 9 | + <uses-permission android:name="android.permission.FLASHLIGHT" /> | |
| 10 | + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
| 11 | + <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" /> | |
| 12 | + <uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" /> | |
| 13 | + <uses-permission android:name="com.sec.android.provider.badge.permission.READ" /> | |
| 14 | + <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" /> | |
| 4 | 15 | |
| 5 | 16 | <application |
| 6 | 17 | |
| ... | ... | @@ -20,6 +31,17 @@ |
| 20 | 31 | <category android:name="android.intent.category.LAUNCHER" /> |
| 21 | 32 | </intent-filter> |
| 22 | 33 | </activity> |
| 34 | + <provider | |
| 35 | + android:name="androidx.core.content.FileProvider" | |
| 36 | + android:authorities="${applicationId}.fileprovider" | |
| 37 | + android:exported="false" | |
| 38 | + android:grantUriPermissions="true" | |
| 39 | + tools:replace="android:authorities"> | |
| 40 | + <meta-data | |
| 41 | + android:name="android.support.FILE_PROVIDER_PATHS" | |
| 42 | + android:resource="@xml/app_files" | |
| 43 | + tools:replace="android:resource" /> | |
| 44 | + </provider> | |
| 23 | 45 | </application> |
| 24 | 46 | |
| 25 | 47 | </manifest> |
| 26 | 48 | \ No newline at end of file | ... | ... |
app/src/main/java/com/cnlive/strike/debug/MainActivity.java
| ... | ... | @@ -73,7 +73,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 73 | 73 | .isReturnUri(AndroidQUtil.isAndroidQ()) |
| 74 | 74 | .selectMode(PickerConfig.PICKER_IMAGE_VIDEO) |
| 75 | 75 | .defaultSelectList(new ArrayList<Media>()) |
| 76 | - .needCamera(false) | |
| 76 | + .needCamera(true) | |
| 77 | 77 | .builder() |
| 78 | 78 | // .doCrop(1, 1, 900, 900) |
| 79 | 79 | .start(this, PickerConfig.PICKER_IMAGE, PickerConfig.DEFAULT_RESULT_CODE); | ... | ... |
app/src/main/res/xml/app_files.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<resources> | |
| 3 | + <paths xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 4 | + <external-path | |
| 5 | + name="external_files" | |
| 6 | + path="" /> | |
| 7 | + <path> | |
| 8 | + <root-path | |
| 9 | + name="root_path" | |
| 10 | + path="." /> | |
| 11 | + </path> | |
| 12 | + <!-- MediaPicker --> | |
| 13 | + <external-path | |
| 14 | + name="camera_photos" | |
| 15 | + path="" /> | |
| 16 | + <!-- 环球优物 --> | |
| 17 | + <external-path | |
| 18 | + name="external_storage_root" | |
| 19 | + path="." /> | |
| 20 | + <grant-uri-permission | |
| 21 | + android:path="string" | |
| 22 | + android:pathPattern="string" | |
| 23 | + android:pathPrefix="string" /> | |
| 24 | + </paths> | |
| 25 | +</resources> | |
| 0 | 26 | \ No newline at end of file | ... | ... |
app/src/main/res/xml/file_paths.xml deleted
100644 → 0
app/src/main/res/xml/network_security_config.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<network-security-config> | |
| 3 | + <base-config cleartextTrafficPermitted="true"> | |
| 4 | + <trust-anchors> | |
| 5 | + <certificates src="system" /> | |
| 6 | + <certificates src="user" /> | |
| 7 | + </trust-anchors> | |
| 8 | + </base-config> | |
| 9 | + <!--<base-config cleartextTrafficPermitted="true" />--> | |
| 10 | +</network-security-config> | ... | ... |
config.gradle
lib_media/src/main/java/com/cnlive/media/frame/view/RecordPreviewView.java
| ... | ... | @@ -11,6 +11,9 @@ import android.view.animation.OvershootInterpolator; |
| 11 | 11 | import android.widget.FrameLayout; |
| 12 | 12 | import android.widget.RelativeLayout; |
| 13 | 13 | |
| 14 | +import com.bumptech.glide.Glide; | |
| 15 | +import com.bumptech.glide.load.engine.DiskCacheStrategy; | |
| 16 | +import com.bumptech.glide.request.RequestOptions; | |
| 14 | 17 | import com.cnlive.libs.base.util.AlertUtil; |
| 15 | 18 | import com.cnlive.media.PickerConfig; |
| 16 | 19 | import com.cnlive.media.media.entity.Media; |
| ... | ... | @@ -53,11 +56,16 @@ public class RecordPreviewView implements MvpView { |
| 53 | 56 | |
| 54 | 57 | if (mFragment.type == 0) { |
| 55 | 58 | mFragment.binding.ivPre.setVisibility(View.VISIBLE); |
| 56 | - mFragment.binding.flVideo.setVisibility(View.GONE); | |
| 59 | + mFragment.binding.rlVideo.setVisibility(View.GONE); | |
| 57 | 60 | GlideCacheUtil.intoItemImageBitmap(mActivity, mActivity.preBitmap, mFragment.binding.ivPre); |
| 58 | 61 | } else if (mFragment.type == 1) { |
| 59 | 62 | mFragment.binding.ivPre.setVisibility(View.GONE); |
| 60 | - mFragment.binding.flVideo.setVisibility(View.VISIBLE); | |
| 63 | + mFragment.binding.rlVideo.setVisibility(View.VISIBLE); | |
| 64 | + RequestOptions option = new RequestOptions(); | |
| 65 | + option.dontTransform() | |
| 66 | + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) | |
| 67 | + .dontAnimate(); | |
| 68 | + Glide.with(mFragment).load(mFragment.path).apply(option).into(mFragment.binding.ivVideo); | |
| 61 | 69 | } |
| 62 | 70 | |
| 63 | 71 | ObjectAnimator animator_cancel = ObjectAnimator.ofFloat(mFragment.binding.tbOk, "translationX", 200, 0); |
| ... | ... | @@ -76,38 +84,8 @@ public class RecordPreviewView implements MvpView { |
| 76 | 84 | PLVideoEditSetting setting = new PLVideoEditSetting(); |
| 77 | 85 | setting.setSourceFilepath(mFragment.path); |
| 78 | 86 | setting.setGifPreviewEnabled(false); |
| 79 | - if (mFragment.mShortVideoEditor == null) | |
| 80 | - mFragment.mShortVideoEditor = new PLShortVideoEditor(mFragment.binding.gvVideo); | |
| 81 | - mFragment.mShortVideoEditor.setVideoEditSetting(setting); | |
| 82 | - mFragment.mShortVideoEditor.setPlaybackLoop(true); | |
| 83 | - mFragment.mShortVideoEditor.setDisplayMode(PLDisplayMode.FULL); | |
| 84 | - mFragment.mShortVideoEditor.startPlayback(); | |
| 85 | - mFragment.isPlaying = true; | |
| 86 | 87 | } |
| 87 | 88 | |
| 88 | - private void initGlSurfaceView() { | |
| 89 | - RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mFragment.binding.flVideo.getLayoutParams(); | |
| 90 | - FrameLayout.LayoutParams surfaceLayout = (FrameLayout.LayoutParams) mFragment.binding.gvVideo.getLayoutParams(); | |
| 91 | - int outputWidth = mMediaFile.getVideoWidth(); | |
| 92 | - int outputHeight = mMediaFile.getVideoHeight(); | |
| 93 | - int rotation = mMediaFile.getVideoRotation(); | |
| 94 | - if ((rotation == 90 || rotation == 270)) { | |
| 95 | - int temp = outputWidth; | |
| 96 | - outputWidth = outputHeight; | |
| 97 | - outputHeight = temp; | |
| 98 | - } | |
| 99 | - | |
| 100 | - surfaceLayout.width = mFragment.mScreenSize.x; | |
| 101 | - surfaceLayout.height = Math.round((float) outputHeight * mFragment.mScreenSize.x / outputWidth); | |
| 102 | - ViewGroup.MarginLayoutParams marginParams = null; | |
| 103 | - if (layoutParams instanceof ViewGroup.MarginLayoutParams) { | |
| 104 | - marginParams = (ViewGroup.MarginLayoutParams) surfaceLayout; | |
| 105 | - } else { | |
| 106 | - marginParams = new ViewGroup.MarginLayoutParams(surfaceLayout); | |
| 107 | - } | |
| 108 | - mFragment.binding.flVideo.setLayoutParams(layoutParams); | |
| 109 | - mFragment.binding.gvVideo.setLayoutParams(marginParams); | |
| 110 | - } | |
| 111 | 89 | |
| 112 | 90 | public void showMessage(String message) { |
| 113 | 91 | if (mFragment == null || TextUtils.isEmpty(message)) return; | ... | ... |
lib_media/src/main/java/com/cnlive/media/ui/fragment/RecordPreviewFragment.java
| 1 | 1 | package com.cnlive.media.ui.fragment; |
| 2 | 2 | |
| 3 | -import android.graphics.Point; | |
| 3 | +import android.content.ContentValues; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.content.Intent; | |
| 6 | +import android.net.Uri; | |
| 4 | 7 | import android.os.Bundle; |
| 8 | +import android.provider.MediaStore; | |
| 9 | +import android.util.Log; | |
| 5 | 10 | import android.view.View; |
| 6 | 11 | |
| 7 | 12 | import androidx.activity.OnBackPressedCallback; |
| 8 | 13 | import androidx.annotation.Nullable; |
| 14 | +import androidx.core.content.FileProvider; | |
| 9 | 15 | |
| 10 | 16 | import com.cnlive.libs.base.frame.fragment.MvpBindingFragment; |
| 17 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 11 | 18 | import com.cnlive.libs.base.util.DoublePressed; |
| 12 | 19 | import com.cnlive.media.R; |
| 20 | +import com.cnlive.media.databinding.FragmentRecordPreviewBinding; | |
| 13 | 21 | import com.cnlive.media.frame.presenter.RecordPreviewPresenter; |
| 14 | 22 | import com.cnlive.media.frame.view.RecordPreviewView; |
| 15 | 23 | import com.cnlive.media.ui.activity.RecordActivity; |
| 16 | -import com.cnlive.media.utils.Utils; | |
| 17 | -import com.cnlive.media.databinding.FragmentRecordPreviewBinding; | |
| 18 | -import com.qiniu.pili.droid.shortvideo.PLShortVideoEditor; | |
| 24 | +import com.cnlive.media.utils.AndroidQUtil; | |
| 25 | + | |
| 26 | +import java.io.File; | |
| 19 | 27 | |
| 20 | 28 | /** |
| 21 | 29 | * 作 者 : wkq |
| ... | ... | @@ -32,10 +40,6 @@ public class RecordPreviewFragment extends MvpBindingFragment<RecordPreviewView, |
| 32 | 40 | public int type; |
| 33 | 41 | //路径 |
| 34 | 42 | public String path; |
| 35 | - public PLShortVideoEditor mShortVideoEditor; | |
| 36 | - public Point mScreenSize; | |
| 37 | - //播放状态 | |
| 38 | - public boolean isPlaying; | |
| 39 | 43 | // 处理 返回事件的监听 |
| 40 | 44 | public OnBackPressedCallback callback = new OnBackPressedCallback(true) { |
| 41 | 45 | @Override |
| ... | ... | @@ -75,7 +79,6 @@ public class RecordPreviewFragment extends MvpBindingFragment<RecordPreviewView, |
| 75 | 79 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 76 | 80 | super.onViewCreated(view, savedInstanceState); |
| 77 | 81 | mActivity = (RecordActivity) getActivity(); |
| 78 | - mScreenSize = Utils.getScreenSize(mActivity); | |
| 79 | 82 | binding.setOnClick(this); |
| 80 | 83 | if (getMvpView() != null) getMvpView().initView(mActivity); |
| 81 | 84 | |
| ... | ... | @@ -84,39 +87,37 @@ public class RecordPreviewFragment extends MvpBindingFragment<RecordPreviewView, |
| 84 | 87 | @Override |
| 85 | 88 | public void onResume() { |
| 86 | 89 | super.onResume(); |
| 87 | - if (type == 1&& getMvpView()!=null){ | |
| 90 | + if (type == 1 && getMvpView() != null) { | |
| 88 | 91 | getMvpView().initPre(); |
| 89 | 92 | } |
| 90 | - isPlaying = true; | |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | 95 | @Override |
| 94 | 96 | public void onPause() { |
| 95 | 97 | super.onPause(); |
| 96 | - if (mShortVideoEditor != null) mShortVideoEditor.stopPlayback(); | |
| 97 | - isPlaying = false; | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | @Override |
| 101 | 101 | public void onDestroy() { |
| 102 | 102 | super.onDestroy(); |
| 103 | 103 | if (callback != null) callback.remove(); |
| 104 | - if (mShortVideoEditor != null) mShortVideoEditor.stopPlayback(); | |
| 105 | 104 | } |
| 106 | 105 | |
| 107 | 106 | @Override |
| 108 | 107 | public void onClick(View v) { |
| 109 | - if (v.getId() == R.id.gv_video) { | |
| 110 | - if (isPlaying) { | |
| 111 | - if (mShortVideoEditor != null) mShortVideoEditor.pausePlayback(); | |
| 112 | - binding.playControlIv.setVisibility(View.VISIBLE); | |
| 113 | - isPlaying = false; | |
| 114 | - } | |
| 115 | - } else if (v.getId() == R.id.play_control_iv) { | |
| 116 | - if (!isPlaying) { | |
| 117 | - if (mShortVideoEditor != null) mShortVideoEditor.resumePlayback(); | |
| 118 | - isPlaying = true; | |
| 119 | - binding.playControlIv.setVisibility(View.GONE); | |
| 108 | + if (v.getId() == R.id.play_control_iv) { | |
| 109 | + try { | |
| 110 | + Uri uri = FileProvider.getUriForFile(getActivity(), getActivity().getApplicationContext().getPackageName() + ".fileprovider", new File(path)); | |
| 111 | + Intent intent = new Intent(Intent.ACTION_VIEW); | |
| 112 | + intent.setDataAndType(uri, "video/*"); | |
| 113 | + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |
| 114 | + if (getActivity().getPackageManager().queryIntentActivities(intent, 0).isEmpty()) { | |
| 115 | + getMvpView().showMessage("未检测到播放器"); | |
| 116 | + } else { | |
| 117 | + startActivity(intent); | |
| 118 | + } | |
| 119 | + } catch (Exception e) { | |
| 120 | + Log.e("异常:", e.getMessage()); | |
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | } else if (v.getId() == R.id.tb_cancel) { | ... | ... |
lib_media/src/main/res/layout/fragment_record_preview.xml
| ... | ... | @@ -24,29 +24,32 @@ |
| 24 | 24 | android:visibility="gone" /> |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - <FrameLayout | |
| 28 | - android:id="@+id/fl_video" | |
| 27 | + <RelativeLayout | |
| 28 | + | |
| 29 | + android:id="@+id/rl_video" | |
| 29 | 30 | android:layout_width="match_parent" |
| 30 | - android:layout_height="wrap_content" | |
| 31 | + android:layout_height="match_parent" | |
| 31 | 32 | android:layout_centerInParent="true" |
| 32 | 33 | android:visibility="gone"> |
| 33 | 34 | |
| 34 | - <android.opengl.GLSurfaceView | |
| 35 | - android:id="@+id/gv_video" | |
| 36 | - android:layout_width="match_parent" | |
| 37 | - android:layout_height="match_parent" | |
| 38 | - android:onClick="@{onClick}" /> | |
| 35 | + <ImageView | |
| 36 | + android:id="@+id/iv_video" | |
| 37 | + android:scaleType="centerCrop" | |
| 38 | + android:layout_width="wrap_content" | |
| 39 | + android:layout_height="wrap_content" /> | |
| 40 | + | |
| 39 | 41 | |
| 40 | 42 | <ImageView |
| 43 | + android:onClick="@{onClick}" | |
| 41 | 44 | android:id="@+id/play_control_iv" |
| 42 | 45 | android:layout_width="wrap_content" |
| 43 | 46 | android:layout_height="wrap_content" |
| 47 | + android:layout_centerInParent="true" | |
| 44 | 48 | android:layout_gravity="center" |
| 45 | - android:onClick="@{onClick}" | |
| 46 | - android:src="@drawable/iv_pre_play" | |
| 47 | - android:visibility="gone" /> | |
| 48 | 49 | |
| 49 | - </FrameLayout> | |
| 50 | + android:src="@drawable/iv_pre_play" /> | |
| 51 | + | |
| 52 | + </RelativeLayout> | |
| 50 | 53 | |
| 51 | 54 | |
| 52 | 55 | <RelativeLayout | ... | ... |