shakebug-react-native 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/VideoPlayer/index.js +37 -23
- package/android/build.gradle +0 -1
- package/android/src/main/java/com/shakebug/CreateThumbnailModule.java +217 -0
- package/android/src/main/java/com/shakebug/NetInfoModule.java +1 -2
- package/android/src/main/java/com/shakebug/RNDeviceModule.java +1 -3
- package/android/src/main/java/com/shakebug/ShakebugPackage.java +10 -10
- package/android/src/main/java/com/shakebug/{Shakebug.java → ShakebugSensors.java} +16 -22
- package/ios/GetLocals/ShakebugSDKRNLocalize.h +1 -0
- package/ios/Thumbnaill/{VideoThumbnailManager.h → CreateThumbnail.h} +2 -1
- package/ios/Thumbnaill/CreateThumbnail.m +82 -0
- package/package.json +2 -5
- package/shakebug-react-native.podspec +0 -1
- package/src/APIs/AddIssue.js +13 -4
- package/src/APIs/AddReview.js +46 -0
- package/src/APIs/CustomUserId.js +47 -0
- package/src/APIs/Event.js +8 -3
- package/src/APIs/StartSession.js +6 -2
- package/src/Assets/images/solar_star-bold.png +0 -0
- package/src/Assets/images/solar_star-line-duotone.png +0 -0
- package/src/Componanats/ReviewModal.js +171 -0
- package/src/Componanats/ShakeFunction.js +6 -3
- package/src/Screens/AddDetailsScreen.js +14 -10
- package/src/Screens/FirstScreen.js +2 -2
- package/src/Screens/Shakebug.js +63 -6
- package/src/Screens/TrimVideoScreen.js +13 -7
- package/src/index.tsx +6 -2
- package/android/src/main/java/com/shakebug/ShakebugSDKScreenShotModule.java +0 -196
- package/android/src/main/java/com/shakebug/VideoPlayerModule.java +0 -199
- package/android/src/main/java/com/shakebug/VideoThumbnailModule.java +0 -215
- package/android/src/main/java/com/shakebug/VideoTrimModule.java +0 -372
- package/android/src/main/java/com/shakebug/adapters/VideoTrimmerAdapter.java +0 -54
- package/android/src/main/java/com/shakebug/utils/StorageUtil.java +0 -139
- package/android/src/main/java/com/shakebug/utils/VideoTrimmerUtil.java +0 -89
- package/android/src/main/java/com/shakebug/widgets/RangeSeekBarView.java +0 -534
- package/android/src/main/java/com/shakebug/widgets/VideoPlayerView.java +0 -429
- package/android/src/main/java/com/shakebug/widgets/VideoTrimmerView.java +0 -477
- package/ios/Thumbnaill/VideoThumbnailManager.m +0 -73
- package/ios/TrimVideo/ShakebugSDKVideoTrim.swift +0 -372
- package/ios/TrimVideo/VideoTrim-Bridging-Header.h +0 -10
- package/ios/TrimVideo/VideoTrim.m +0 -23
- package/ios/TrimVideo/VideoTrimmer.swift +0 -810
- package/ios/TrimVideo/VideoTrimmerThumb.swift +0 -119
- package/ios/TrimVideo/VideoTrimmerViewController.swift +0 -301
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
package com.shakebug.widgets;
|
|
2
|
-
|
|
3
|
-
import static com.shakebug.utils.VideoTrimmerUtil.RECYCLER_VIEW_PADDING;
|
|
4
|
-
import static com.shakebug.utils.VideoTrimmerUtil.VIDEO_FRAMES_WIDTH;
|
|
5
|
-
|
|
6
|
-
import android.animation.ValueAnimator;
|
|
7
|
-
import android.content.Context;
|
|
8
|
-
import android.content.pm.ActivityInfo;
|
|
9
|
-
import android.content.res.Configuration;
|
|
10
|
-
import android.graphics.Bitmap;
|
|
11
|
-
import android.media.MediaMetadataRetriever;
|
|
12
|
-
import android.media.MediaPlayer;
|
|
13
|
-
import android.net.Uri;
|
|
14
|
-
import android.os.Handler;
|
|
15
|
-
import android.util.AttributeSet;
|
|
16
|
-
import android.view.LayoutInflater;
|
|
17
|
-
import android.view.MotionEvent;
|
|
18
|
-
import android.view.View;
|
|
19
|
-
import android.view.ViewGroup;
|
|
20
|
-
import android.view.animation.LinearInterpolator;
|
|
21
|
-
import android.widget.FrameLayout;
|
|
22
|
-
import android.widget.ImageView;
|
|
23
|
-
import android.widget.LinearLayout;
|
|
24
|
-
import android.widget.RelativeLayout;
|
|
25
|
-
import android.widget.TextView;
|
|
26
|
-
import android.widget.Toast;
|
|
27
|
-
|
|
28
|
-
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
29
|
-
import androidx.recyclerview.widget.RecyclerView;
|
|
30
|
-
|
|
31
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
32
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
33
|
-
import com.shakebug.DeviceUtil;
|
|
34
|
-
import com.shakebug.R;
|
|
35
|
-
import com.shakebug.adapters.VideoTrimmerAdapter;
|
|
36
|
-
import com.shakebug.interfaces.IVideoTrimmerView;
|
|
37
|
-
import com.shakebug.interfaces.VideoTrimListener;
|
|
38
|
-
import com.shakebug.thread.BackgroundExecutor;
|
|
39
|
-
import com.shakebug.thread.UiThreadExecutor;
|
|
40
|
-
import com.shakebug.utils.StorageUtil;
|
|
41
|
-
import com.shakebug.utils.VideoTrimmerUtil;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Author:J.Chou
|
|
45
|
-
* Date: 2016.08.01 2:23 PM
|
|
46
|
-
* Email: who_know_me@163.com
|
|
47
|
-
* Describe:
|
|
48
|
-
*/
|
|
49
|
-
public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
|
|
50
|
-
|
|
51
|
-
private static final String TAG = VideoTrimmerView.class.getSimpleName();
|
|
52
|
-
|
|
53
|
-
private int mMaxWidth = VIDEO_FRAMES_WIDTH;
|
|
54
|
-
private ReactApplicationContext mContext;
|
|
55
|
-
private RelativeLayout mLinearVideo;
|
|
56
|
-
private ZVideoView mVideoView;
|
|
57
|
-
private ImageView mPlayView;
|
|
58
|
-
private RecyclerView mVideoThumbRecyclerView;
|
|
59
|
-
private RangeSeekBarView mRangeSeekBarView;
|
|
60
|
-
private LinearLayout mSeekBarLayout;
|
|
61
|
-
private ImageView mRedProgressIcon;
|
|
62
|
-
private float mAverageMsPx;//每毫秒所占的px
|
|
63
|
-
private float averagePxMs;//每px所占用的ms毫秒
|
|
64
|
-
private Uri mSourceUri;
|
|
65
|
-
private VideoTrimListener mOnTrimVideoListener;
|
|
66
|
-
private int mDuration = 0;
|
|
67
|
-
private VideoTrimmerAdapter mVideoThumbAdapter;
|
|
68
|
-
private boolean isFromRestore = false;
|
|
69
|
-
//new
|
|
70
|
-
private long mLeftProgressPos, mRightProgressPos;
|
|
71
|
-
private long mRedProgressBarPos = 0;
|
|
72
|
-
private long scrollPos = 0;
|
|
73
|
-
private int mScaledTouchSlop;
|
|
74
|
-
private int lastScrollX;
|
|
75
|
-
private boolean isSeeking;
|
|
76
|
-
private boolean isOverScaledTouchSlop;
|
|
77
|
-
private int mThumbsTotalCount;
|
|
78
|
-
private ValueAnimator mRedProgressAnimator;
|
|
79
|
-
private Handler mAnimationHandler = new Handler();
|
|
80
|
-
private Boolean mIsPrepared = false;
|
|
81
|
-
private int mMaxDuration = 0;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
public VideoTrimmerView(ReactApplicationContext context, AttributeSet attrs) {
|
|
85
|
-
this(context, attrs, 0, null);
|
|
86
|
-
}
|
|
87
|
-
public VideoTrimmerView(ReactApplicationContext context, ReadableMap config, AttributeSet attrs) {
|
|
88
|
-
this(context, attrs, 0, config);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public VideoTrimmerView(ReactApplicationContext context, AttributeSet attrs, int defStyleAttr, ReadableMap config) {
|
|
92
|
-
super(context, attrs, defStyleAttr);
|
|
93
|
-
init(context, config);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private void init(ReactApplicationContext context, ReadableMap config) {
|
|
97
|
-
this.mContext = context;
|
|
98
|
-
|
|
99
|
-
// listen to onConfigurationChanged doesn't work for this, it runs too soon
|
|
100
|
-
context.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
101
|
-
LayoutInflater.from(context).inflate(R.layout.video_trimmer_view, this, true);
|
|
102
|
-
|
|
103
|
-
mLinearVideo = findViewById(R.id.layout_surface_view);
|
|
104
|
-
mVideoView = findViewById(R.id.video_loader);
|
|
105
|
-
mPlayView = findViewById(R.id.icon_video_play);
|
|
106
|
-
mSeekBarLayout = findViewById(R.id.seekBarLayout);
|
|
107
|
-
mRedProgressIcon = findViewById(R.id.positionIcon);
|
|
108
|
-
mVideoThumbRecyclerView = findViewById(R.id.video_frames_recyclerView);
|
|
109
|
-
mVideoThumbRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
|
|
110
|
-
mVideoThumbAdapter = new VideoTrimmerAdapter(mContext);
|
|
111
|
-
mVideoThumbRecyclerView.setAdapter(mVideoThumbAdapter);
|
|
112
|
-
mVideoThumbRecyclerView.addOnScrollListener(mOnScrollListener);
|
|
113
|
-
|
|
114
|
-
configure(config);
|
|
115
|
-
setUpListeners();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private void initRangeSeekBarView() {
|
|
119
|
-
if(mRangeSeekBarView != null) return;
|
|
120
|
-
mLeftProgressPos = 0;
|
|
121
|
-
|
|
122
|
-
VideoTrimmerUtil.SCREEN_WIDTH_FULL = this.getScreenWidthInPortraitMode();
|
|
123
|
-
VideoTrimmerUtil.VIDEO_FRAMES_WIDTH = VideoTrimmerUtil.SCREEN_WIDTH_FULL - RECYCLER_VIEW_PADDING * 2;
|
|
124
|
-
VideoTrimmerUtil.MAX_COUNT_RANGE = Math.max(((int) VIDEO_FRAMES_WIDTH / VideoTrimmerUtil.mThumbWidth), VideoTrimmerUtil.MAX_COUNT_RANGE);
|
|
125
|
-
|
|
126
|
-
if (mDuration <= VideoTrimmerUtil.maxShootDuration) {
|
|
127
|
-
mThumbsTotalCount = VideoTrimmerUtil.MAX_COUNT_RANGE;
|
|
128
|
-
mRightProgressPos = mDuration;
|
|
129
|
-
} else {
|
|
130
|
-
mThumbsTotalCount = (int) (mDuration * 1.0f / (VideoTrimmerUtil.maxShootDuration * 1.0f) * VideoTrimmerUtil.MAX_COUNT_RANGE);
|
|
131
|
-
mRightProgressPos = VideoTrimmerUtil.maxShootDuration;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
mVideoThumbRecyclerView.addItemDecoration(new SpacesItemDecoration2(RECYCLER_VIEW_PADDING, mThumbsTotalCount));
|
|
135
|
-
mRangeSeekBarView = new RangeSeekBarView(mContext, mLeftProgressPos, mRightProgressPos);
|
|
136
|
-
mRangeSeekBarView.setSelectedMinValue(mLeftProgressPos);
|
|
137
|
-
mRangeSeekBarView.setSelectedMaxValue(mRightProgressPos);
|
|
138
|
-
mRangeSeekBarView.setStartEndTime(mLeftProgressPos, mRightProgressPos);
|
|
139
|
-
mRangeSeekBarView.setMinShootTime(VideoTrimmerUtil.MIN_SHOOT_DURATION);
|
|
140
|
-
mRangeSeekBarView.setNotifyWhileDragging(true);
|
|
141
|
-
mRangeSeekBarView.setOnRangeSeekBarChangeListener(mOnRangeSeekBarChangeListener);
|
|
142
|
-
mSeekBarLayout.addView(mRangeSeekBarView);
|
|
143
|
-
if(mThumbsTotalCount - VideoTrimmerUtil.MAX_COUNT_RANGE > 0) {
|
|
144
|
-
mAverageMsPx = (mDuration - VideoTrimmerUtil.maxShootDuration) / (float) (mThumbsTotalCount - VideoTrimmerUtil.MAX_COUNT_RANGE);
|
|
145
|
-
} else {
|
|
146
|
-
mAverageMsPx = 0f;
|
|
147
|
-
}
|
|
148
|
-
averagePxMs = (mMaxWidth * 1.0f / (mRightProgressPos - mLeftProgressPos));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public void initVideoByURI(final Uri videoURI) {
|
|
152
|
-
mSourceUri = videoURI;
|
|
153
|
-
mVideoView.setVideoURI(videoURI);
|
|
154
|
-
mVideoView.requestFocus();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private void startShootVideoThumbs(final Context context, final Uri videoUri, int totalThumbsCount, long startPosition, long endPosition) {
|
|
158
|
-
VideoTrimmerUtil.shootVideoThumbInBackground(context, videoUri, totalThumbsCount, startPosition, endPosition,
|
|
159
|
-
(bitmap, interval) -> {
|
|
160
|
-
if (bitmap != null) {
|
|
161
|
-
UiThreadExecutor.runTask("", () -> mVideoThumbAdapter.addBitmaps(bitmap), 0L);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private void videoPrepared(MediaPlayer mp) {
|
|
167
|
-
ViewGroup.LayoutParams lp = mVideoView.getLayoutParams();
|
|
168
|
-
int videoWidth = mp.getVideoWidth();
|
|
169
|
-
int videoHeight = mp.getVideoHeight();
|
|
170
|
-
|
|
171
|
-
float videoProportion = (float) videoWidth / (float) videoHeight;
|
|
172
|
-
int screenWidth = mLinearVideo.getWidth();
|
|
173
|
-
int screenHeight = mLinearVideo.getHeight();
|
|
174
|
-
|
|
175
|
-
if (videoHeight > videoWidth) {
|
|
176
|
-
lp.width = screenWidth;
|
|
177
|
-
lp.height = screenHeight;
|
|
178
|
-
} else {
|
|
179
|
-
lp.width = screenWidth;
|
|
180
|
-
float r = videoHeight / (float) videoWidth;
|
|
181
|
-
lp.height = (int) (lp.width * r);
|
|
182
|
-
}
|
|
183
|
-
mVideoView.setLayoutParams(lp);
|
|
184
|
-
mDuration = mVideoView.getDuration();
|
|
185
|
-
|
|
186
|
-
VideoTrimmerUtil.maxShootDuration = mMaxDuration > 0 ? Math.min(mMaxDuration * 1000L, mDuration) : mDuration;
|
|
187
|
-
|
|
188
|
-
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
|
189
|
-
mediaMetadataRetriever.setDataSource(mContext, mSourceUri);
|
|
190
|
-
// take first frame
|
|
191
|
-
Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
|
|
192
|
-
int width = VideoTrimmerUtil.THUMB_HEIGHT * bitmap.getWidth() / bitmap.getHeight();
|
|
193
|
-
VideoTrimmerUtil.mThumbWidth = width;
|
|
194
|
-
|
|
195
|
-
if (!getRestoreState()) {
|
|
196
|
-
seekTo((int) mRedProgressBarPos);
|
|
197
|
-
} else {
|
|
198
|
-
setRestoreState(false);
|
|
199
|
-
seekTo((int) mRedProgressBarPos);
|
|
200
|
-
}
|
|
201
|
-
initRangeSeekBarView();
|
|
202
|
-
startShootVideoThumbs(mContext, mSourceUri, mThumbsTotalCount, 0, mDuration);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
private void videoCompleted() {
|
|
206
|
-
seekTo(mLeftProgressPos);
|
|
207
|
-
setPlayPauseViewIcon(false);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private void onVideoReset() {
|
|
211
|
-
mVideoView.pause();
|
|
212
|
-
setPlayPauseViewIcon(false);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private void playVideoOrPause() {
|
|
216
|
-
mRedProgressBarPos = mVideoView.getCurrentPosition();
|
|
217
|
-
if (mVideoView.isPlaying()) {
|
|
218
|
-
mVideoView.pause();
|
|
219
|
-
pauseRedProgressAnimation();
|
|
220
|
-
} else {
|
|
221
|
-
mVideoView.start();
|
|
222
|
-
playingRedProgressAnimation();
|
|
223
|
-
}
|
|
224
|
-
setPlayPauseViewIcon(mVideoView.isPlaying());
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
public void onVideoPause() {
|
|
228
|
-
if (mVideoView.isPlaying()) {
|
|
229
|
-
seekTo(mLeftProgressPos);//复位
|
|
230
|
-
mVideoView.pause();
|
|
231
|
-
setPlayPauseViewIcon(false);
|
|
232
|
-
mRedProgressIcon.setVisibility(GONE);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
public void setOnTrimVideoListener(VideoTrimListener onTrimVideoListener) {
|
|
237
|
-
mOnTrimVideoListener = onTrimVideoListener;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
private void setUpListeners() {
|
|
241
|
-
findViewById(R.id.cancelBtn).setOnClickListener(view -> {
|
|
242
|
-
mOnTrimVideoListener.onCancel();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
findViewById(R.id.saveBtn).setOnClickListener(view -> {
|
|
246
|
-
mOnTrimVideoListener.onSave();
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
mVideoView.setOnPreparedListener(mp -> {
|
|
250
|
-
// this is called everytime activity goes active, and can fire multiple times
|
|
251
|
-
// so that we create a flag to not run below code more than once
|
|
252
|
-
if (mIsPrepared) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
mp.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
|
|
256
|
-
videoPrepared(mp);
|
|
257
|
-
mIsPrepared = true;
|
|
258
|
-
});
|
|
259
|
-
mVideoView.setOnCompletionListener(mp -> {
|
|
260
|
-
videoCompleted();
|
|
261
|
-
});
|
|
262
|
-
mPlayView.setOnClickListener(view -> {
|
|
263
|
-
playVideoOrPause();
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
public void onSaveClicked() {
|
|
268
|
-
if (mRightProgressPos - mLeftProgressPos < VideoTrimmerUtil.MIN_SHOOT_DURATION) {
|
|
269
|
-
Toast.makeText(mContext, "Video shorter than 3s, can't proceed", Toast.LENGTH_SHORT).show();
|
|
270
|
-
} else {
|
|
271
|
-
mVideoView.pause();
|
|
272
|
-
VideoTrimmerUtil.trim(
|
|
273
|
-
mSourceUri.getPath(),
|
|
274
|
-
StorageUtil.getOutputPath(mContext),
|
|
275
|
-
mDuration,
|
|
276
|
-
mLeftProgressPos,
|
|
277
|
-
mRightProgressPos,
|
|
278
|
-
mOnTrimVideoListener);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
private void seekTo(long msec) {
|
|
283
|
-
mVideoView.seekTo((int) msec);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
private boolean getRestoreState() {
|
|
287
|
-
return isFromRestore;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
public void setRestoreState(boolean fromRestore) {
|
|
291
|
-
isFromRestore = fromRestore;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
private void setPlayPauseViewIcon(boolean isPlaying) {
|
|
295
|
-
mPlayView.setImageResource(isPlaying ? R.drawable.ic_video_pause_black : R.drawable.ic_video_play_black);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
private final RangeSeekBarView.OnRangeSeekBarChangeListener mOnRangeSeekBarChangeListener = new RangeSeekBarView.OnRangeSeekBarChangeListener() {
|
|
299
|
-
@Override public void onRangeSeekBarValuesChanged(RangeSeekBarView bar, long minValue, long maxValue, int action, boolean isMin,
|
|
300
|
-
RangeSeekBarView.Thumb pressedThumb) {
|
|
301
|
-
mLeftProgressPos = minValue + scrollPos;
|
|
302
|
-
mRedProgressBarPos = mLeftProgressPos;
|
|
303
|
-
|
|
304
|
-
// when dragging the highlighted section mRightProgressPos in some cases can bigger than mDuration
|
|
305
|
-
// Eg: mDuration=62006, then mRightProgressPos can be 63000
|
|
306
|
-
mRightProgressPos = Math.min(maxValue + scrollPos, mDuration);
|
|
307
|
-
switch (action) {
|
|
308
|
-
case MotionEvent.ACTION_DOWN:
|
|
309
|
-
isSeeking = false;
|
|
310
|
-
break;
|
|
311
|
-
case MotionEvent.ACTION_MOVE:
|
|
312
|
-
isSeeking = true;
|
|
313
|
-
seekTo((int) (pressedThumb == RangeSeekBarView.Thumb.MIN ? mLeftProgressPos : mRightProgressPos));
|
|
314
|
-
break;
|
|
315
|
-
case MotionEvent.ACTION_UP:
|
|
316
|
-
isSeeking = false;
|
|
317
|
-
seekTo((int) mLeftProgressPos);
|
|
318
|
-
break;
|
|
319
|
-
default:
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
mRangeSeekBarView.setStartEndTime(mLeftProgressPos, mRightProgressPos);
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
private final RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
|
|
329
|
-
@Override
|
|
330
|
-
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
331
|
-
super.onScrollStateChanged(recyclerView, newState);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
@Override
|
|
335
|
-
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
336
|
-
super.onScrolled(recyclerView, dx, dy);
|
|
337
|
-
isSeeking = false;
|
|
338
|
-
int scrollX = calcScrollXDistance();
|
|
339
|
-
//达不到滑动的距离
|
|
340
|
-
if (Math.abs(lastScrollX - scrollX) < mScaledTouchSlop) {
|
|
341
|
-
isOverScaledTouchSlop = false;
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
isOverScaledTouchSlop = true;
|
|
345
|
-
//初始状态,why ? 因为默认的时候有35dp的空白!
|
|
346
|
-
if (scrollX == -RECYCLER_VIEW_PADDING) {
|
|
347
|
-
scrollPos = 0;
|
|
348
|
-
mLeftProgressPos = mRangeSeekBarView.getSelectedMinValue() + scrollPos;
|
|
349
|
-
|
|
350
|
-
// when scrolling the highlighted section mRightProgressPos in some cases can bigger than mDuration
|
|
351
|
-
// Eg: mDuration=62006, then mRightProgressPos can be 63000
|
|
352
|
-
mRightProgressPos = Math.min(mRangeSeekBarView.getSelectedMaxValue() + scrollPos, mDuration);
|
|
353
|
-
mRedProgressBarPos = mLeftProgressPos;
|
|
354
|
-
} else {
|
|
355
|
-
isSeeking = true;
|
|
356
|
-
scrollPos = (long) (mAverageMsPx * (RECYCLER_VIEW_PADDING + scrollX) / VideoTrimmerUtil.mThumbWidth);
|
|
357
|
-
mLeftProgressPos = mRangeSeekBarView.getSelectedMinValue() + scrollPos;
|
|
358
|
-
|
|
359
|
-
// when scrolling the highlighted section mRightProgressPos in some cases can bigger than mDuration
|
|
360
|
-
// Eg: mDuration=62006, then mRightProgressPos can be 63000
|
|
361
|
-
mRightProgressPos = Math.min(mRangeSeekBarView.getSelectedMaxValue() + scrollPos, mDuration);
|
|
362
|
-
mRedProgressBarPos = mLeftProgressPos;
|
|
363
|
-
if (mVideoView.isPlaying()) {
|
|
364
|
-
mVideoView.pause();
|
|
365
|
-
setPlayPauseViewIcon(false);
|
|
366
|
-
}
|
|
367
|
-
mRedProgressIcon.setVisibility(GONE);
|
|
368
|
-
seekTo(mLeftProgressPos);
|
|
369
|
-
|
|
370
|
-
mRangeSeekBarView.setStartEndTime(mLeftProgressPos, mRightProgressPos);
|
|
371
|
-
mRangeSeekBarView.invalidate();
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
lastScrollX = scrollX;
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* 水平滑动了多少px
|
|
380
|
-
*/
|
|
381
|
-
private int calcScrollXDistance() {
|
|
382
|
-
LinearLayoutManager layoutManager = (LinearLayoutManager) mVideoThumbRecyclerView.getLayoutManager();
|
|
383
|
-
int position = layoutManager.findFirstVisibleItemPosition();
|
|
384
|
-
View firstVisibleChildView = layoutManager.findViewByPosition(position);
|
|
385
|
-
int itemWidth = firstVisibleChildView.getWidth();
|
|
386
|
-
return (position) * itemWidth - firstVisibleChildView.getLeft();
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
private void playingRedProgressAnimation() {
|
|
390
|
-
pauseRedProgressAnimation();
|
|
391
|
-
playingAnimation();
|
|
392
|
-
mAnimationHandler.post(mAnimationRunnable);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
private void playingAnimation() {
|
|
396
|
-
if (mRedProgressIcon.getVisibility() == View.GONE) {
|
|
397
|
-
mRedProgressIcon.setVisibility(View.VISIBLE);
|
|
398
|
-
}
|
|
399
|
-
final LayoutParams params = (LayoutParams) mRedProgressIcon.getLayoutParams();
|
|
400
|
-
int start = (int) (RECYCLER_VIEW_PADDING + (mRedProgressBarPos - scrollPos) * averagePxMs);
|
|
401
|
-
int end = (int) (RECYCLER_VIEW_PADDING + (mRightProgressPos - scrollPos) * averagePxMs);
|
|
402
|
-
mRedProgressAnimator = ValueAnimator.ofInt(start, end).setDuration((mRightProgressPos - scrollPos) - (mRedProgressBarPos - scrollPos));
|
|
403
|
-
mRedProgressAnimator.setInterpolator(new LinearInterpolator());
|
|
404
|
-
mRedProgressAnimator.addUpdateListener(animation -> {
|
|
405
|
-
params.leftMargin = (int) animation.getAnimatedValue();
|
|
406
|
-
mRedProgressIcon.setLayoutParams(params);
|
|
407
|
-
});
|
|
408
|
-
mRedProgressAnimator.start();
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
private void pauseRedProgressAnimation() {
|
|
412
|
-
mRedProgressIcon.clearAnimation();
|
|
413
|
-
if (mRedProgressAnimator != null && mRedProgressAnimator.isRunning()) {
|
|
414
|
-
mAnimationHandler.removeCallbacks(mAnimationRunnable);
|
|
415
|
-
mRedProgressAnimator.cancel();
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
private Runnable mAnimationRunnable = () -> updateVideoProgress();
|
|
420
|
-
|
|
421
|
-
private void updateVideoProgress() {
|
|
422
|
-
long currentPosition = mVideoView.getCurrentPosition();
|
|
423
|
-
if (currentPosition >= (mRightProgressPos)) {
|
|
424
|
-
mRedProgressBarPos = mLeftProgressPos;
|
|
425
|
-
pauseRedProgressAnimation();
|
|
426
|
-
onVideoPause();
|
|
427
|
-
} else {
|
|
428
|
-
mAnimationHandler.post(mAnimationRunnable);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
@Override
|
|
433
|
-
protected void onDetachedFromWindow() {
|
|
434
|
-
super.onDetachedFromWindow();
|
|
435
|
-
mContext.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Cancel trim thread execute action when finish
|
|
440
|
-
*/
|
|
441
|
-
@Override public void onDestroy() {
|
|
442
|
-
BackgroundExecutor.cancelAll("", true);
|
|
443
|
-
UiThreadExecutor.cancelAll("");
|
|
444
|
-
mContext.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
private int getScreenWidthInPortraitMode() {
|
|
448
|
-
int screenWidth = DeviceUtil.getDeviceWidth();
|
|
449
|
-
int screenHeight = DeviceUtil.getDeviceHeight();
|
|
450
|
-
|
|
451
|
-
// Check the current orientation
|
|
452
|
-
int currentOrientation = getResources().getConfiguration().orientation;
|
|
453
|
-
|
|
454
|
-
// Swap width and height if the current orientation is landscape
|
|
455
|
-
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
456
|
-
return screenHeight;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return screenWidth;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
private void configure(ReadableMap config) {
|
|
463
|
-
if (config.hasKey("maxDuration")) {
|
|
464
|
-
this.mMaxDuration = config.getInt("maxDuration");
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (config.hasKey("cancelButtonText")) {
|
|
468
|
-
TextView tv = findViewById(R.id.cancelBtn);
|
|
469
|
-
tv.setText(config.getString("cancelButtonText"));
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
if (config.hasKey("saveButtonText")) {
|
|
473
|
-
TextView tv = findViewById(R.id.saveBtn);
|
|
474
|
-
tv.setText(config.getString("saveButtonText"));
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// VideoThumbnailManager.m
|
|
3
|
-
// Shakebug
|
|
4
|
-
//
|
|
5
|
-
// Created by ideveloper2 on 26/04/24.
|
|
6
|
-
// Copyright © 2024 Facebook. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import "VideoThumbnailManager.h"
|
|
10
|
-
#import <AVFoundation/AVFoundation.h>
|
|
11
|
-
|
|
12
|
-
@implementation ShakebugSDKVideoThumbnailManager
|
|
13
|
-
|
|
14
|
-
RCT_EXPORT_MODULE(ShakebugSDKCreateThumbnail);
|
|
15
|
-
|
|
16
|
-
RCT_EXPORT_METHOD(create:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
17
|
-
{
|
|
18
|
-
[self generateThumbnailWithOptions:options resolver:resolve rejecter:reject];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
- (void)generateThumbnailWithOptions:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
|
22
|
-
NSString *videoURLString = options[@"url"];
|
|
23
|
-
NSURL *videoURL = [NSURL URLWithString:videoURLString];
|
|
24
|
-
NSNumber *timeStamp = options[@"timeStamp"] ? options[@"timeStamp"] : @0;
|
|
25
|
-
NSString *format = options[@"format"] ? options[@"format"] : @"jpeg";
|
|
26
|
-
NSString *cacheName = options[@"cacheName"];
|
|
27
|
-
NSString *cacheDir = [NSTemporaryDirectory() stringByAppendingPathComponent:@"thumbnails"];
|
|
28
|
-
|
|
29
|
-
// Create the cache directory if it does not exist
|
|
30
|
-
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
31
|
-
if (![fileManager fileExistsAtPath:cacheDir]) {
|
|
32
|
-
[fileManager createDirectoryAtPath:cacheDir withIntermediateDirectories:YES attributes:nil error:nil];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
NSString *filePath = [cacheDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", cacheName ?: [[NSUUID UUID] UUIDString], format]];
|
|
36
|
-
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
|
|
37
|
-
|
|
38
|
-
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
|
|
39
|
-
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
|
|
40
|
-
imageGenerator.appliesPreferredTrackTransform = YES;
|
|
41
|
-
CMTime time = CMTimeMake([timeStamp doubleValue] * 1000, 1000);
|
|
42
|
-
|
|
43
|
-
NSError *error = nil;
|
|
44
|
-
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:nil error:&error];
|
|
45
|
-
if (error) {
|
|
46
|
-
reject(@"create_thumbnail_error", @"Failed to create thumbnail", error);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
UIImage *image = [UIImage imageWithCGImage:imageRef];
|
|
51
|
-
CGImageRelease(imageRef);
|
|
52
|
-
|
|
53
|
-
NSData *imageData;
|
|
54
|
-
if ([format isEqualToString:@"png"]) {
|
|
55
|
-
imageData = UIImagePNGRepresentation(image);
|
|
56
|
-
} else {
|
|
57
|
-
imageData = UIImageJPEGRepresentation(image, 0.9);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
[imageData writeToURL:fileURL atomically:YES];
|
|
61
|
-
|
|
62
|
-
NSMutableDictionary *result = [NSMutableDictionary dictionary];
|
|
63
|
-
result[@"path"] = fileURL.absoluteString;
|
|
64
|
-
result[@"size"] = @(imageData.length);
|
|
65
|
-
result[@"mime"] = [format isEqualToString:@"png"] ? @"image/png" : @"image/jpeg";
|
|
66
|
-
result[@"width"] = @(image.size.width);
|
|
67
|
-
result[@"height"] = @(image.size.height);
|
|
68
|
-
|
|
69
|
-
resolve(result);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@end
|
|
73
|
-
|