@cometchat/chat-uikit-react-native 4.2.2 → 4.3.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 +26 -67
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +2 -1
- package/android/src/main/java/com/reactnativecometchatuikit/ReactVideoView.java +796 -0
- package/android/src/main/java/com/reactnativecometchatuikit/ReactVideoViewManager.java +172 -0
- package/android/src/main/java/com/scalablevideoview/BuildConfig.java +10 -0
- package/android/src/main/java/com/scalablevideoview/PivotPoint.java +13 -0
- package/android/src/main/java/com/scalablevideoview/ScalableType.java +34 -0
- package/android/src/main/java/com/scalablevideoview/ScalableVideoView.java +255 -0
- package/android/src/main/java/com/scalablevideoview/ScaleManager.java +188 -0
- package/android/src/main/java/com/scalablevideoview/Size.java +20 -0
- package/android/src/main/java/com/zipfile/APEZProvider.java +287 -0
- package/android/src/main/java/com/zipfile/APKExpansionSupport.java +81 -0
- package/android/src/main/java/com/zipfile/ZipResourceFile.java +428 -0
- package/android/src/main/res/values/attrs.xml +37 -0
- package/ios/FileManager.m +75 -5
- package/ios/Video/CCRCTVideo.h +67 -0
- package/ios/Video/CCRCTVideo.m +2031 -0
- package/ios/Video/CCRCTVideoManager.h +6 -0
- package/ios/Video/CCRCTVideoManager.m +133 -0
- package/ios/Video/CCRCTVideoPlayerViewController.h +20 -0
- package/ios/Video/CCRCTVideoPlayerViewController.m +43 -0
- package/ios/Video/CCRCTVideoPlayerViewControllerDelegate.h +7 -0
- package/ios/Video/UIView+FindUIViewController.h +15 -0
- package/ios/Video/UIView+FindUIViewController.m +21 -0
- package/ios/VideoCaching/RCTVideoCache.h +38 -0
- package/ios/VideoCaching/RCTVideoCache.m +174 -0
- package/ios/VideoPickerModule.h +7 -0
- package/ios/VideoPickerModule.mm +95 -0
- package/package.json +3 -4
- package/react-native-cometchat-ui-kit.podspec +24 -10
- package/src/CometChatContacts/CometChatContacts.tsx +12 -9
- package/src/CometChatConversations/CometChatConversations.tsx +84 -64
- package/src/CometChatDetails/CometChatDetails.tsx +14 -12
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +8 -4
- package/src/CometChatGroupMembers/resources/check.png +0 -0
- package/src/CometChatGroupMembers/resources/index.ts +2 -0
- package/src/CometChatGroups/CometChatGroups.tsx +4 -4
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +57 -15
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +9 -2
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +1 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +596 -181
- package/src/CometChatMessageList/MessageListConfiguration.ts +55 -4
- package/src/CometChatMessageList/resources/index.ts +5 -1
- package/src/CometChatMessageList/resources/leftarrowcurve.png +0 -0
- package/src/CometChatMessageList/resources/rightarrowcurve.png +0 -0
- package/src/CometChatMessages/CometChatMessages.tsx +1 -1
- package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +4 -12
- package/src/CometChatThreadedMessages/style.ts +3 -1
- package/src/CometChatUsers/CometChatUsers.tsx +1 -1
- package/src/calls/CallUtils.ts +4 -8
- package/src/calls/CallingExtentionDecorator.tsx +5 -2
- package/src/calls/CometChatCallBubble/styles.ts +2 -1
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +14 -3
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +9 -9
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +80 -73
- package/src/extensions/CollaborativeBubble/styles.ts +2 -0
- package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +11 -0
- package/src/extensions/index.ts +0 -4
- package/src/index.ts +53 -8
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +14 -2
- package/src/shared/constants/UIKitConstants.ts +1 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +6 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +8 -0
- package/src/shared/events/ListenerInitializer.ts +6 -0
- package/src/shared/events/messages.ts +2 -0
- package/src/shared/framework/MessageDataSource.tsx +29 -25
- package/src/shared/index.ts +49 -1
- package/src/shared/libs/VideoPlayer/DRMType.js +6 -0
- package/src/shared/libs/VideoPlayer/FilterType.js +18 -0
- package/src/shared/libs/VideoPlayer/TextTrackType.js +5 -0
- package/src/shared/libs/VideoPlayer/Video.js +519 -0
- package/src/shared/libs/VideoPlayer/VideoResizeMode.js +5 -0
- package/src/shared/libs/VideoPlayerControls/OSSupport/PlatformSupport.tsx +43 -0
- package/src/shared/libs/VideoPlayerControls/OSSupport/TVOSSupport.tsx +16 -0
- package/src/shared/libs/VideoPlayerControls/OSSupport/index.tsx +1 -0
- package/src/shared/libs/VideoPlayerControls/VideoPlayer.tsx +511 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/back.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/back@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/back@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/bottom-vignette.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/bottom-vignette@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/bottom-vignette@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/error-icon.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/error-icon@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/error-icon@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/expand.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/expand@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/expand@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/forward.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/forward@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/forward@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/loader-icon.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/loader-icon@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/loader-icon@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/pause.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/pause@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/pause@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/play.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/play@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/play@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/rewind.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/rewind@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/rewind@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/shrink.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/shrink@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/shrink@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/top-vignette.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/top-vignette@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/top-vignette@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/volume.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/volume@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/volume@3x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/components/Back/Back.tsx +28 -0
- package/src/shared/libs/VideoPlayerControls/components/Back/index.ts +1 -0
- package/src/shared/libs/VideoPlayerControls/components/BottomControls.tsx +142 -0
- package/src/shared/libs/VideoPlayerControls/components/Control.tsx +45 -0
- package/src/shared/libs/VideoPlayerControls/components/Error/Error.tsx +22 -0
- package/src/shared/libs/VideoPlayerControls/components/Error/index.ts +1 -0
- package/src/shared/libs/VideoPlayerControls/components/Error/styles.ts +21 -0
- package/src/shared/libs/VideoPlayerControls/components/Fullscreen.tsx +36 -0
- package/src/shared/libs/VideoPlayerControls/components/Loader/Loader.tsx +15 -0
- package/src/shared/libs/VideoPlayerControls/components/Loader/index.ts +1 -0
- package/src/shared/libs/VideoPlayerControls/components/Loader/styles.ts +16 -0
- package/src/shared/libs/VideoPlayerControls/components/NullControl.tsx +7 -0
- package/src/shared/libs/VideoPlayerControls/components/Overlay.tsx +23 -0
- package/src/shared/libs/VideoPlayerControls/components/PlayPause/PlayPause.tsx +109 -0
- package/src/shared/libs/VideoPlayerControls/components/PlayPause/index.ts +1 -0
- package/src/shared/libs/VideoPlayerControls/components/PlayPause/styles.ts +21 -0
- package/src/shared/libs/VideoPlayerControls/components/Seekbar/Seekbar.tsx +47 -0
- package/src/shared/libs/VideoPlayerControls/components/Seekbar/index.ts +1 -0
- package/src/shared/libs/VideoPlayerControls/components/Seekbar/styles.ts +37 -0
- package/src/shared/libs/VideoPlayerControls/components/Timer/Timer.tsx +28 -0
- package/src/shared/libs/VideoPlayerControls/components/Timer/index.ts +1 -0
- package/src/shared/libs/VideoPlayerControls/components/Timer/styles.ts +12 -0
- package/src/shared/libs/VideoPlayerControls/components/Title.tsx +35 -0
- package/src/shared/libs/VideoPlayerControls/components/TopControls.tsx +110 -0
- package/src/shared/libs/VideoPlayerControls/components/Volume/Volume.tsx +37 -0
- package/src/shared/libs/VideoPlayerControls/components/Volume/index.ts +1 -0
- package/src/shared/libs/VideoPlayerControls/components/Volume/styles.ts +31 -0
- package/src/shared/libs/VideoPlayerControls/components/index.ts +14 -0
- package/src/shared/libs/VideoPlayerControls/components/styles.ts +30 -0
- package/src/shared/libs/VideoPlayerControls/hooks/index.ts +3 -0
- package/src/shared/libs/VideoPlayerControls/hooks/useAnimations.ts +68 -0
- package/src/shared/libs/VideoPlayerControls/hooks/useControlTimeout.tsx +67 -0
- package/src/shared/libs/VideoPlayerControls/hooks/usePanResponders.tsx +96 -0
- package/src/shared/libs/VideoPlayerControls/index.ts +4 -0
- package/src/shared/libs/VideoPlayerControls/styles.ts +19 -0
- package/src/shared/libs/VideoPlayerControls/types.ts +290 -0
- package/src/shared/libs/VideoPlayerControls/utils.ts +76 -0
- package/src/shared/modals/CometChatMessageTemplate.ts +113 -9
- package/src/shared/modals/InteractiveData/InteractiveMessage/SchedulerMessage.ts +23 -21
- package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/de/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/en/translation.json +6 -3
- package/src/shared/resources/CometChatLocalize/resources/es/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +4 -1
- package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +4 -1
- package/src/shared/resources/CometChatTheme/Palette.ts +79 -45
- package/src/shared/resources/CometChatTheme/Typography.ts +18 -0
- package/src/shared/utils/CommonUtils.ts +71 -0
- package/src/shared/utils/PermissionUtilIOS.ts +104 -0
- package/src/shared/views/CometChatActionSheet/ActionSheetStyle.ts +3 -1
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +6 -6
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +28 -5
- package/src/shared/views/CometChatAudioBubble/style.ts +4 -2
- package/src/shared/views/CometChatAvatar/AvatarStyle.ts +1 -1
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -3
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +47 -31
- package/src/shared/views/CometChatEmojiKeyboard/EmojiKeyboardConfiguration.ts +5 -5
- package/src/shared/views/CometChatEmojiKeyboard/EmojiKeyboardStyle.ts +12 -13
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +52 -5
- package/src/shared/views/CometChatFileBubble/style.ts +4 -2
- package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +25 -2
- package/src/shared/views/CometChatList/CometChatList.tsx +2 -1
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +51 -2
- package/src/shared/views/CometChatQuickReactions/CometChatQuickReactions.tsx +76 -0
- package/src/shared/views/CometChatQuickReactions/QuickReactionsConfiguration.tsx +12 -0
- package/src/shared/views/CometChatQuickReactions/QuickReactionsStyle.tsx +35 -0
- package/src/shared/views/CometChatQuickReactions/index.ts +12 -0
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +166 -0
- package/src/shared/views/CometChatReactions/ReactionsConfiguration.tsx +12 -0
- package/src/shared/views/CometChatReactions/ReactionsStyle.tsx +43 -0
- package/src/shared/views/CometChatReactions/index.ts +12 -0
- package/src/{extensions/Reactions/CometChatMessageReactions → shared/views/CometChatReactions}/style.ts +7 -7
- package/src/shared/views/CometChatReactionsList/CometChatReactionsList.tsx +335 -0
- package/src/shared/views/CometChatReactionsList/ReactionsListConfiguration.tsx +14 -0
- package/src/shared/views/CometChatReactionsList/ReactionsListStyle.tsx +67 -0
- package/src/shared/views/CometChatReactionsList/index.ts +12 -0
- package/src/shared/views/CometChatReactionsList/resources/Spineer.png +0 -0
- package/src/shared/views/CometChatReactionsList/resources/index.ts +5 -0
- package/src/shared/views/CometChatReceipt/CometChatReceipt.tsx +21 -4
- package/src/shared/views/CometChatReceipt/MessageConfiguration.ts +12 -0
- package/src/shared/views/CometChatReceipt/resources/error.png +0 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +1 -1
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +78 -12
- package/src/shared/views/CometChatVideoBubble/VideoBubbleStyle.ts +52 -2
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +134 -0
- package/src/shared/views/CometChatVideoPlayer/index.tsx +1 -0
- package/src/shared/views/index.ts +30 -0
- package/android/.gradle/7.4.2/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4.2/gc.properties +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.idea/gradle.xml +0 -13
- package/android/.idea/misc.xml +0 -8
- package/android/.idea/modules/android.iml +0 -18
- package/android/.idea/modules.xml +0 -8
- package/android/.idea/vcs.xml +0 -6
- package/android/local.properties +0 -8
- package/src/extensions/Reactions/CometChatMessageReactions/CometChatMessageReactions.tsx +0 -249
- package/src/extensions/Reactions/CometChatMessageReactions/index.ts +0 -3
- package/src/extensions/Reactions/ReactionsDecorator.tsx +0 -164
- package/src/extensions/Reactions/ReactionsExtension.tsx +0 -48
- package/src/extensions/Reactions/index.ts +0 -4
- /package/src/{extensions/Reactions → shared/views/CometChatQuickReactions}/resources/AddReactions.png +0 -0
- /package/src/{extensions/Reactions → shared/views/CometChatQuickReactions}/resources/index.ts +0 -0
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
package com.reactnativecometchatuikit;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.annotation.TargetApi;
|
|
5
|
+
import android.app.Activity;
|
|
6
|
+
import android.content.res.AssetFileDescriptor;
|
|
7
|
+
import android.graphics.Matrix;
|
|
8
|
+
import android.media.MediaPlayer;
|
|
9
|
+
import android.media.TimedMetaData;
|
|
10
|
+
import android.net.Uri;
|
|
11
|
+
import android.os.Build;
|
|
12
|
+
import android.os.Handler;
|
|
13
|
+
import android.util.Log;
|
|
14
|
+
import android.view.MotionEvent;
|
|
15
|
+
import android.view.WindowManager;
|
|
16
|
+
import android.view.View;
|
|
17
|
+
import android.view.Window;
|
|
18
|
+
import android.webkit.CookieManager;
|
|
19
|
+
import android.widget.MediaController;
|
|
20
|
+
|
|
21
|
+
import com.zipfile.APKExpansionSupport;
|
|
22
|
+
import com.zipfile.ZipResourceFile;
|
|
23
|
+
import com.facebook.react.bridge.Arguments;
|
|
24
|
+
import com.facebook.react.bridge.LifecycleEventListener;
|
|
25
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
26
|
+
import com.facebook.react.bridge.WritableMap;
|
|
27
|
+
import com.facebook.react.bridge.WritableArray;
|
|
28
|
+
import com.facebook.react.bridge.WritableNativeArray;
|
|
29
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
30
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
31
|
+
import com.scalablevideoview.ScalableType;
|
|
32
|
+
import com.scalablevideoview.ScalableVideoView;
|
|
33
|
+
import com.scalablevideoview.ScaleManager;
|
|
34
|
+
import com.scalablevideoview.Size;
|
|
35
|
+
|
|
36
|
+
import java.io.IOException;
|
|
37
|
+
import java.io.UnsupportedEncodingException;
|
|
38
|
+
import java.util.HashMap;
|
|
39
|
+
import java.util.Map;
|
|
40
|
+
import java.lang.Math;
|
|
41
|
+
import java.math.BigDecimal;
|
|
42
|
+
|
|
43
|
+
import javax.annotation.Nullable;
|
|
44
|
+
|
|
45
|
+
@SuppressLint("ViewConstructor")
|
|
46
|
+
public class ReactVideoView extends ScalableVideoView implements
|
|
47
|
+
MediaPlayer.OnPreparedListener,
|
|
48
|
+
MediaPlayer.OnErrorListener,
|
|
49
|
+
MediaPlayer.OnBufferingUpdateListener,
|
|
50
|
+
MediaPlayer.OnSeekCompleteListener,
|
|
51
|
+
MediaPlayer.OnCompletionListener,
|
|
52
|
+
MediaPlayer.OnInfoListener,
|
|
53
|
+
LifecycleEventListener,
|
|
54
|
+
MediaController.MediaPlayerControl {
|
|
55
|
+
|
|
56
|
+
public enum Events {
|
|
57
|
+
EVENT_LOAD_START("onVideoLoadStart"),
|
|
58
|
+
EVENT_LOAD("onVideoLoad"),
|
|
59
|
+
EVENT_ERROR("onVideoError"),
|
|
60
|
+
EVENT_PROGRESS("onVideoProgress"),
|
|
61
|
+
EVENT_TIMED_METADATA("onTimedMetadata"),
|
|
62
|
+
EVENT_SEEK("onVideoSeek"),
|
|
63
|
+
EVENT_END("onVideoEnd"),
|
|
64
|
+
EVENT_STALLED("onPlaybackStalled"),
|
|
65
|
+
EVENT_RESUME("onPlaybackResume"),
|
|
66
|
+
EVENT_READY_FOR_DISPLAY("onReadyForDisplay"),
|
|
67
|
+
EVENT_FULLSCREEN_WILL_PRESENT("onVideoFullscreenPlayerWillPresent"),
|
|
68
|
+
EVENT_FULLSCREEN_DID_PRESENT("onVideoFullscreenPlayerDidPresent"),
|
|
69
|
+
EVENT_FULLSCREEN_WILL_DISMISS("onVideoFullscreenPlayerWillDismiss"),
|
|
70
|
+
EVENT_FULLSCREEN_DID_DISMISS("onVideoFullscreenPlayerDidDismiss");
|
|
71
|
+
|
|
72
|
+
private final String mName;
|
|
73
|
+
|
|
74
|
+
Events(final String name) {
|
|
75
|
+
mName = name;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Override
|
|
79
|
+
public String toString() {
|
|
80
|
+
return mName;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public static final String EVENT_PROP_FAST_FORWARD = "canPlayFastForward";
|
|
85
|
+
public static final String EVENT_PROP_SLOW_FORWARD = "canPlaySlowForward";
|
|
86
|
+
public static final String EVENT_PROP_SLOW_REVERSE = "canPlaySlowReverse";
|
|
87
|
+
public static final String EVENT_PROP_REVERSE = "canPlayReverse";
|
|
88
|
+
public static final String EVENT_PROP_STEP_FORWARD = "canStepForward";
|
|
89
|
+
public static final String EVENT_PROP_STEP_BACKWARD = "canStepBackward";
|
|
90
|
+
|
|
91
|
+
public static final String EVENT_PROP_DURATION = "duration";
|
|
92
|
+
public static final String EVENT_PROP_PLAYABLE_DURATION = "playableDuration";
|
|
93
|
+
public static final String EVENT_PROP_SEEKABLE_DURATION = "seekableDuration";
|
|
94
|
+
public static final String EVENT_PROP_CURRENT_TIME = "currentTime";
|
|
95
|
+
public static final String EVENT_PROP_SEEK_TIME = "seekTime";
|
|
96
|
+
public static final String EVENT_PROP_NATURALSIZE = "naturalSize";
|
|
97
|
+
public static final String EVENT_PROP_WIDTH = "width";
|
|
98
|
+
public static final String EVENT_PROP_HEIGHT = "height";
|
|
99
|
+
public static final String EVENT_PROP_ORIENTATION = "orientation";
|
|
100
|
+
public static final String EVENT_PROP_METADATA = "metadata";
|
|
101
|
+
public static final String EVENT_PROP_TARGET = "target";
|
|
102
|
+
public static final String EVENT_PROP_METADATA_IDENTIFIER = "identifier";
|
|
103
|
+
public static final String EVENT_PROP_METADATA_VALUE = "value";
|
|
104
|
+
|
|
105
|
+
public static final String EVENT_PROP_ERROR = "error";
|
|
106
|
+
public static final String EVENT_PROP_WHAT = "what";
|
|
107
|
+
public static final String EVENT_PROP_EXTRA = "extra";
|
|
108
|
+
|
|
109
|
+
private ThemedReactContext mThemedReactContext;
|
|
110
|
+
private RCTEventEmitter mEventEmitter;
|
|
111
|
+
|
|
112
|
+
private Handler mProgressUpdateHandler = new Handler();
|
|
113
|
+
private Runnable mProgressUpdateRunnable = null;
|
|
114
|
+
private Handler videoControlHandler = new Handler();
|
|
115
|
+
private MediaController mediaController;
|
|
116
|
+
|
|
117
|
+
private String mSrcUriString = null;
|
|
118
|
+
private String mSrcType = "mp4";
|
|
119
|
+
private ReadableMap mRequestHeaders = null;
|
|
120
|
+
private boolean mSrcIsNetwork = false;
|
|
121
|
+
private boolean mSrcIsAsset = false;
|
|
122
|
+
private ScalableType mResizeMode = ScalableType.LEFT_TOP;
|
|
123
|
+
private boolean mRepeat = false;
|
|
124
|
+
private boolean mPaused = false;
|
|
125
|
+
private boolean mMuted = false;
|
|
126
|
+
private boolean mPreventsDisplaySleepDuringVideoPlayback = true;
|
|
127
|
+
private float mVolume = 1.0f;
|
|
128
|
+
private float mStereoPan = 0.0f;
|
|
129
|
+
private float mProgressUpdateInterval = 250.0f;
|
|
130
|
+
private float mRate = 1.0f;
|
|
131
|
+
private float mActiveRate = 1.0f;
|
|
132
|
+
private long mSeekTime = 0;
|
|
133
|
+
private boolean mPlayInBackground = false;
|
|
134
|
+
private boolean mBackgroundPaused = false;
|
|
135
|
+
private boolean mIsFullscreen = false;
|
|
136
|
+
|
|
137
|
+
private int mMainVer = 0;
|
|
138
|
+
private int mPatchVer = 0;
|
|
139
|
+
|
|
140
|
+
private boolean mMediaPlayerValid = false; // True if mMediaPlayer is in prepared, started, paused or completed state.
|
|
141
|
+
|
|
142
|
+
private int mVideoDuration = 0;
|
|
143
|
+
private int mVideoBufferedDuration = 0;
|
|
144
|
+
private boolean isCompleted = false;
|
|
145
|
+
private boolean mUseNativeControls = false;
|
|
146
|
+
|
|
147
|
+
public ReactVideoView(ThemedReactContext themedReactContext) {
|
|
148
|
+
super(themedReactContext);
|
|
149
|
+
|
|
150
|
+
mThemedReactContext = themedReactContext;
|
|
151
|
+
mEventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class);
|
|
152
|
+
themedReactContext.addLifecycleEventListener(this);
|
|
153
|
+
|
|
154
|
+
initializeMediaPlayerIfNeeded();
|
|
155
|
+
setSurfaceTextureListener(this);
|
|
156
|
+
|
|
157
|
+
mProgressUpdateRunnable = new Runnable() {
|
|
158
|
+
@Override
|
|
159
|
+
public void run() {
|
|
160
|
+
|
|
161
|
+
if (mMediaPlayerValid && !isCompleted && !mPaused && !mBackgroundPaused) {
|
|
162
|
+
WritableMap event = Arguments.createMap();
|
|
163
|
+
event.putDouble(EVENT_PROP_CURRENT_TIME, mMediaPlayer.getCurrentPosition() / 1000.0);
|
|
164
|
+
event.putDouble(EVENT_PROP_PLAYABLE_DURATION, mVideoBufferedDuration / 1000.0); //TODO:mBufferUpdateRunnable
|
|
165
|
+
event.putDouble(EVENT_PROP_SEEKABLE_DURATION, mVideoDuration / 1000.0);
|
|
166
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_PROGRESS.toString(), event);
|
|
167
|
+
|
|
168
|
+
// Check for update after an interval
|
|
169
|
+
mProgressUpdateHandler.postDelayed(mProgressUpdateRunnable, Math.round(mProgressUpdateInterval));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@Override
|
|
176
|
+
public boolean onTouchEvent(MotionEvent event) {
|
|
177
|
+
if (mUseNativeControls) {
|
|
178
|
+
initializeMediaControllerIfNeeded();
|
|
179
|
+
mediaController.show();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return super.onTouchEvent(event);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@Override
|
|
186
|
+
@SuppressLint("DrawAllocation")
|
|
187
|
+
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
188
|
+
super.onLayout(changed, left, top, right, bottom);
|
|
189
|
+
|
|
190
|
+
if (!changed || !mMediaPlayerValid) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
int videoWidth = getVideoWidth();
|
|
195
|
+
int videoHeight = getVideoHeight();
|
|
196
|
+
|
|
197
|
+
if (videoWidth == 0 || videoHeight == 0) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
Size viewSize = new Size(getWidth(), getHeight());
|
|
202
|
+
Size videoSize = new Size(videoWidth, videoHeight);
|
|
203
|
+
ScaleManager scaleManager = new ScaleManager(viewSize, videoSize);
|
|
204
|
+
Matrix matrix = scaleManager.getScaleMatrix(mScalableType);
|
|
205
|
+
if (matrix != null) {
|
|
206
|
+
setTransform(matrix);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private void initializeMediaPlayerIfNeeded() {
|
|
211
|
+
if (mMediaPlayer == null) {
|
|
212
|
+
mMediaPlayerValid = false;
|
|
213
|
+
mMediaPlayer = new MediaPlayer();
|
|
214
|
+
mMediaPlayer.setOnVideoSizeChangedListener(this);
|
|
215
|
+
mMediaPlayer.setOnErrorListener(this);
|
|
216
|
+
mMediaPlayer.setOnPreparedListener(this);
|
|
217
|
+
mMediaPlayer.setOnBufferingUpdateListener(this);
|
|
218
|
+
mMediaPlayer.setOnSeekCompleteListener(this);
|
|
219
|
+
mMediaPlayer.setOnCompletionListener(this);
|
|
220
|
+
mMediaPlayer.setOnInfoListener(this);
|
|
221
|
+
if (Build.VERSION.SDK_INT >= 23) {
|
|
222
|
+
mMediaPlayer.setOnTimedMetaDataAvailableListener(new TimedMetaDataAvailableListener());
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private void initializeMediaControllerIfNeeded() {
|
|
228
|
+
if (mediaController == null) {
|
|
229
|
+
mediaController = new MediaController(this.getContext());
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public void cleanupMediaPlayerResources() {
|
|
234
|
+
if ( mediaController != null ) {
|
|
235
|
+
mediaController.hide();
|
|
236
|
+
}
|
|
237
|
+
if ( mMediaPlayer != null ) {
|
|
238
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
239
|
+
mMediaPlayer.setOnTimedMetaDataAvailableListener(null);
|
|
240
|
+
}
|
|
241
|
+
mMediaPlayerValid = false;
|
|
242
|
+
release();
|
|
243
|
+
}
|
|
244
|
+
if (mIsFullscreen) {
|
|
245
|
+
setFullscreen(false);
|
|
246
|
+
}
|
|
247
|
+
if (mThemedReactContext != null) {
|
|
248
|
+
mThemedReactContext.removeLifecycleEventListener(this);
|
|
249
|
+
mThemedReactContext = null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset, final ReadableMap requestHeaders) {
|
|
254
|
+
setSrc(uriString, type, isNetwork, isAsset, requestHeaders, 0, 0);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset, final ReadableMap requestHeaders, final int expansionMainVersion, final int expansionPatchVersion) {
|
|
258
|
+
|
|
259
|
+
mSrcUriString = uriString;
|
|
260
|
+
mSrcType = type;
|
|
261
|
+
mSrcIsNetwork = isNetwork;
|
|
262
|
+
mSrcIsAsset = isAsset;
|
|
263
|
+
mRequestHeaders = requestHeaders;
|
|
264
|
+
mMainVer = expansionMainVersion;
|
|
265
|
+
mPatchVer = expansionPatchVersion;
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
mMediaPlayerValid = false;
|
|
269
|
+
mVideoDuration = 0;
|
|
270
|
+
mVideoBufferedDuration = 0;
|
|
271
|
+
|
|
272
|
+
initializeMediaPlayerIfNeeded();
|
|
273
|
+
mMediaPlayer.reset();
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
if (isNetwork) {
|
|
277
|
+
// Use the shared CookieManager to access the cookies
|
|
278
|
+
// set by WebViews inside the same app
|
|
279
|
+
CookieManager cookieManager = CookieManager.getInstance();
|
|
280
|
+
|
|
281
|
+
Uri parsedUrl = Uri.parse(uriString);
|
|
282
|
+
Uri.Builder builtUrl = parsedUrl.buildUpon();
|
|
283
|
+
|
|
284
|
+
String cookie = cookieManager.getCookie(builtUrl.build().toString());
|
|
285
|
+
|
|
286
|
+
Map<String, String> headers = new HashMap<String, String>();
|
|
287
|
+
|
|
288
|
+
if (cookie != null) {
|
|
289
|
+
headers.put("Cookie", cookie);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (mRequestHeaders != null) {
|
|
293
|
+
headers.putAll(toStringMap(mRequestHeaders));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* According to https://github.com/react-native-community/react-native-video/pull/537
|
|
297
|
+
* there is an issue with this where it can cause a IOException.
|
|
298
|
+
* TODO: diagnose this exception and fix it
|
|
299
|
+
*/
|
|
300
|
+
setDataSource(mThemedReactContext, parsedUrl, headers);
|
|
301
|
+
} else if (isAsset) {
|
|
302
|
+
if (uriString.startsWith("content://")) {
|
|
303
|
+
Uri parsedUrl = Uri.parse(uriString);
|
|
304
|
+
setDataSource(mThemedReactContext, parsedUrl);
|
|
305
|
+
} else {
|
|
306
|
+
setDataSource(uriString);
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
ZipResourceFile expansionFile= null;
|
|
310
|
+
AssetFileDescriptor fd= null;
|
|
311
|
+
if(mMainVer>0) {
|
|
312
|
+
try {
|
|
313
|
+
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(mThemedReactContext, mMainVer, mPatchVer);
|
|
314
|
+
fd = expansionFile.getAssetFileDescriptor(uriString.replace(".mp4","") + ".mp4");
|
|
315
|
+
} catch (IOException e) {
|
|
316
|
+
e.printStackTrace();
|
|
317
|
+
} catch (NullPointerException e) {
|
|
318
|
+
e.printStackTrace();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if(fd==null) {
|
|
322
|
+
int identifier = mThemedReactContext.getResources().getIdentifier(
|
|
323
|
+
uriString,
|
|
324
|
+
"drawable",
|
|
325
|
+
mThemedReactContext.getPackageName()
|
|
326
|
+
);
|
|
327
|
+
if (identifier == 0) {
|
|
328
|
+
identifier = mThemedReactContext.getResources().getIdentifier(
|
|
329
|
+
uriString,
|
|
330
|
+
"raw",
|
|
331
|
+
mThemedReactContext.getPackageName()
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
setRawData(identifier);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
setDataSource(fd.getFileDescriptor(), fd.getStartOffset(),fd.getLength());
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
} catch (Exception e) {
|
|
341
|
+
e.printStackTrace();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
WritableMap src = Arguments.createMap();
|
|
346
|
+
|
|
347
|
+
WritableMap wRequestHeaders = Arguments.createMap();
|
|
348
|
+
wRequestHeaders.merge(mRequestHeaders);
|
|
349
|
+
|
|
350
|
+
src.putString(ReactVideoViewManager.PROP_SRC_URI, uriString);
|
|
351
|
+
src.putString(ReactVideoViewManager.PROP_SRC_TYPE, type);
|
|
352
|
+
src.putMap(ReactVideoViewManager.PROP_SRC_HEADERS, wRequestHeaders);
|
|
353
|
+
src.putBoolean(ReactVideoViewManager.PROP_SRC_IS_NETWORK, isNetwork);
|
|
354
|
+
if(mMainVer>0) {
|
|
355
|
+
src.putInt(ReactVideoViewManager.PROP_SRC_MAINVER, mMainVer);
|
|
356
|
+
if(mPatchVer>0) {
|
|
357
|
+
src.putInt(ReactVideoViewManager.PROP_SRC_PATCHVER, mPatchVer);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
WritableMap event = Arguments.createMap();
|
|
361
|
+
event.putMap(ReactVideoViewManager.PROP_SRC, src);
|
|
362
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD_START.toString(), event);
|
|
363
|
+
isCompleted = false;
|
|
364
|
+
|
|
365
|
+
try {
|
|
366
|
+
prepareAsync(this);
|
|
367
|
+
} catch (Exception e) {
|
|
368
|
+
e.printStackTrace();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
public void setResizeModeModifier(final ScalableType resizeMode) {
|
|
373
|
+
mResizeMode = resizeMode;
|
|
374
|
+
|
|
375
|
+
if (mMediaPlayerValid) {
|
|
376
|
+
setScalableType(resizeMode);
|
|
377
|
+
invalidate();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
public void setRepeatModifier(final boolean repeat) {
|
|
382
|
+
|
|
383
|
+
mRepeat = repeat;
|
|
384
|
+
|
|
385
|
+
if (mMediaPlayerValid) {
|
|
386
|
+
setLooping(repeat);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
public void setPausedModifier(final boolean paused) {
|
|
391
|
+
mPaused = paused;
|
|
392
|
+
|
|
393
|
+
if (!mMediaPlayerValid) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (mPaused) {
|
|
398
|
+
if (mMediaPlayer.isPlaying()) {
|
|
399
|
+
pause();
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
if (!mMediaPlayer.isPlaying()) {
|
|
403
|
+
start();
|
|
404
|
+
// Setting the rate unpauses, so we have to wait for an unpause
|
|
405
|
+
if (mRate != mActiveRate) {
|
|
406
|
+
setRateModifier(mRate);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Also Start the Progress Update Handler
|
|
410
|
+
mProgressUpdateHandler.post(mProgressUpdateRunnable);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
setKeepScreenOn(!mPaused && mPreventsDisplaySleepDuringVideoPlayback);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// reduces the volume based on stereoPan
|
|
417
|
+
private float calulateRelativeVolume() {
|
|
418
|
+
float relativeVolume = (mVolume * (1 - Math.abs(mStereoPan)));
|
|
419
|
+
// only one decimal allowed
|
|
420
|
+
BigDecimal roundRelativeVolume = new BigDecimal(relativeVolume).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
421
|
+
return roundRelativeVolume.floatValue();
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
public void setPreventsDisplaySleepDuringVideoPlaybackModifier(final boolean preventsDisplaySleepDuringVideoPlayback) {
|
|
425
|
+
mPreventsDisplaySleepDuringVideoPlayback = preventsDisplaySleepDuringVideoPlayback;
|
|
426
|
+
|
|
427
|
+
if (!mMediaPlayerValid) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
mMediaPlayer.setScreenOnWhilePlaying(mPreventsDisplaySleepDuringVideoPlayback);
|
|
432
|
+
setKeepScreenOn(mPreventsDisplaySleepDuringVideoPlayback);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
public void setMutedModifier(final boolean muted) {
|
|
436
|
+
mMuted = muted;
|
|
437
|
+
|
|
438
|
+
if (!mMediaPlayerValid) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (mMuted) {
|
|
443
|
+
setVolume(0, 0);
|
|
444
|
+
} else if (mStereoPan < 0) {
|
|
445
|
+
// louder on the left channel
|
|
446
|
+
setVolume(mVolume, calulateRelativeVolume());
|
|
447
|
+
} else if (mStereoPan > 0) {
|
|
448
|
+
// louder on the right channel
|
|
449
|
+
setVolume(calulateRelativeVolume(), mVolume);
|
|
450
|
+
} else {
|
|
451
|
+
// same volume on both channels
|
|
452
|
+
setVolume(mVolume, mVolume);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
public void setVolumeModifier(final float volume) {
|
|
457
|
+
mVolume = volume;
|
|
458
|
+
setMutedModifier(mMuted);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
public void setStereoPan(final float stereoPan) {
|
|
462
|
+
mStereoPan = stereoPan;
|
|
463
|
+
setMutedModifier(mMuted);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
public void setProgressUpdateInterval(final float progressUpdateInterval) {
|
|
467
|
+
mProgressUpdateInterval = progressUpdateInterval;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
public void setRateModifier(final float rate) {
|
|
471
|
+
mRate = rate;
|
|
472
|
+
|
|
473
|
+
if (mMediaPlayerValid) {
|
|
474
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
475
|
+
if (!mPaused) { // Applying the rate while paused will cause the video to start
|
|
476
|
+
/* Per https://stackoverflow.com/questions/39442522/setplaybackparams-causes-illegalstateexception
|
|
477
|
+
* Some devices throw an IllegalStateException if you set the rate without first calling reset()
|
|
478
|
+
* TODO: Call reset() then reinitialize the player
|
|
479
|
+
*/
|
|
480
|
+
try {
|
|
481
|
+
mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(rate));
|
|
482
|
+
mActiveRate = rate;
|
|
483
|
+
} catch (Exception e) {
|
|
484
|
+
Log.e(ReactVideoViewManager.REACT_CLASS, "Unable to set rate, unsupported on this device");
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
} else {
|
|
488
|
+
Log.e(ReactVideoViewManager.REACT_CLASS, "Setting playback rate is not yet supported on Android versions below 6.0");
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
public void setFullscreen(boolean isFullscreen) {
|
|
494
|
+
if (isFullscreen == mIsFullscreen) {
|
|
495
|
+
return; // Avoid generating events when nothing is changing
|
|
496
|
+
}
|
|
497
|
+
mIsFullscreen = isFullscreen;
|
|
498
|
+
|
|
499
|
+
Activity activity = mThemedReactContext.getCurrentActivity();
|
|
500
|
+
if (activity == null) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
Window window = activity.getWindow();
|
|
504
|
+
View decorView = window.getDecorView();
|
|
505
|
+
int uiOptions;
|
|
506
|
+
if (mIsFullscreen) {
|
|
507
|
+
if (Build.VERSION.SDK_INT >= 19) { // 4.4+
|
|
508
|
+
uiOptions = SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
509
|
+
| SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
|
510
|
+
| SYSTEM_UI_FLAG_FULLSCREEN;
|
|
511
|
+
} else {
|
|
512
|
+
uiOptions = SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
513
|
+
| SYSTEM_UI_FLAG_FULLSCREEN;
|
|
514
|
+
}
|
|
515
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_WILL_PRESENT.toString(), null);
|
|
516
|
+
decorView.setSystemUiVisibility(uiOptions);
|
|
517
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_DID_PRESENT.toString(), null);
|
|
518
|
+
} else {
|
|
519
|
+
uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
|
|
520
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_WILL_DISMISS.toString(), null);
|
|
521
|
+
decorView.setSystemUiVisibility(uiOptions);
|
|
522
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_DID_DISMISS.toString(), null);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
public void applyModifiers() {
|
|
527
|
+
setResizeModeModifier(mResizeMode);
|
|
528
|
+
setRepeatModifier(mRepeat);
|
|
529
|
+
setPausedModifier(mPaused);
|
|
530
|
+
setMutedModifier(mMuted);
|
|
531
|
+
setPreventsDisplaySleepDuringVideoPlaybackModifier(mPreventsDisplaySleepDuringVideoPlayback);
|
|
532
|
+
setProgressUpdateInterval(mProgressUpdateInterval);
|
|
533
|
+
setRateModifier(mRate);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
public void setPlayInBackground(final boolean playInBackground) {
|
|
537
|
+
|
|
538
|
+
mPlayInBackground = playInBackground;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
public void setControls(boolean controls) {
|
|
542
|
+
this.mUseNativeControls = controls;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
@Override
|
|
546
|
+
public void onPrepared(MediaPlayer mp) {
|
|
547
|
+
|
|
548
|
+
mMediaPlayerValid = true;
|
|
549
|
+
mVideoDuration = mp.getDuration();
|
|
550
|
+
|
|
551
|
+
WritableMap naturalSize = Arguments.createMap();
|
|
552
|
+
naturalSize.putInt(EVENT_PROP_WIDTH, mp.getVideoWidth());
|
|
553
|
+
naturalSize.putInt(EVENT_PROP_HEIGHT, mp.getVideoHeight());
|
|
554
|
+
if (mp.getVideoWidth() > mp.getVideoHeight())
|
|
555
|
+
naturalSize.putString(EVENT_PROP_ORIENTATION, "landscape");
|
|
556
|
+
else
|
|
557
|
+
naturalSize.putString(EVENT_PROP_ORIENTATION, "portrait");
|
|
558
|
+
|
|
559
|
+
WritableMap event = Arguments.createMap();
|
|
560
|
+
event.putDouble(EVENT_PROP_DURATION, mVideoDuration / 1000.0);
|
|
561
|
+
event.putDouble(EVENT_PROP_CURRENT_TIME, mp.getCurrentPosition() / 1000.0);
|
|
562
|
+
event.putMap(EVENT_PROP_NATURALSIZE, naturalSize);
|
|
563
|
+
// TODO: Actually check if you can.
|
|
564
|
+
event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
|
|
565
|
+
event.putBoolean(EVENT_PROP_SLOW_FORWARD, true);
|
|
566
|
+
event.putBoolean(EVENT_PROP_SLOW_REVERSE, true);
|
|
567
|
+
event.putBoolean(EVENT_PROP_REVERSE, true);
|
|
568
|
+
event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
|
|
569
|
+
event.putBoolean(EVENT_PROP_STEP_BACKWARD, true);
|
|
570
|
+
event.putBoolean(EVENT_PROP_STEP_FORWARD, true);
|
|
571
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD.toString(), event);
|
|
572
|
+
|
|
573
|
+
applyModifiers();
|
|
574
|
+
|
|
575
|
+
if (mUseNativeControls) {
|
|
576
|
+
initializeMediaControllerIfNeeded();
|
|
577
|
+
mediaController.setMediaPlayer(this);
|
|
578
|
+
mediaController.setAnchorView(this);
|
|
579
|
+
|
|
580
|
+
videoControlHandler.post(new Runnable() {
|
|
581
|
+
@Override
|
|
582
|
+
public void run() {
|
|
583
|
+
mediaController.setEnabled(true);
|
|
584
|
+
mediaController.show();
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
selectTimedMetadataTrack(mp);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
@Override
|
|
593
|
+
public boolean onError(MediaPlayer mp, int what, int extra) {
|
|
594
|
+
|
|
595
|
+
WritableMap error = Arguments.createMap();
|
|
596
|
+
error.putInt(EVENT_PROP_WHAT, what);
|
|
597
|
+
error.putInt(EVENT_PROP_EXTRA, extra);
|
|
598
|
+
WritableMap event = Arguments.createMap();
|
|
599
|
+
event.putMap(EVENT_PROP_ERROR, error);
|
|
600
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_ERROR.toString(), event);
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
@Override
|
|
605
|
+
public boolean onInfo(MediaPlayer mp, int what, int extra) {
|
|
606
|
+
switch (what) {
|
|
607
|
+
case MediaPlayer.MEDIA_INFO_BUFFERING_START:
|
|
608
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_STALLED.toString(), Arguments.createMap());
|
|
609
|
+
break;
|
|
610
|
+
case MediaPlayer.MEDIA_INFO_BUFFERING_END:
|
|
611
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_RESUME.toString(), Arguments.createMap());
|
|
612
|
+
break;
|
|
613
|
+
case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
|
|
614
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_READY_FOR_DISPLAY.toString(), Arguments.createMap());
|
|
615
|
+
break;
|
|
616
|
+
|
|
617
|
+
default:
|
|
618
|
+
}
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
@Override
|
|
623
|
+
public void onBufferingUpdate(MediaPlayer mp, int percent) {
|
|
624
|
+
selectTimedMetadataTrack(mp);
|
|
625
|
+
mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
public void onSeekComplete(MediaPlayer mp) {
|
|
629
|
+
WritableMap event = Arguments.createMap();
|
|
630
|
+
event.putDouble(EVENT_PROP_CURRENT_TIME, getCurrentPosition() / 1000.0);
|
|
631
|
+
event.putDouble(EVENT_PROP_SEEK_TIME, mSeekTime / 1000.0);
|
|
632
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_SEEK.toString(), event);
|
|
633
|
+
mSeekTime = 0;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
@Override
|
|
637
|
+
public void seekTo(int msec) {
|
|
638
|
+
if (mMediaPlayerValid) {
|
|
639
|
+
mSeekTime = msec;
|
|
640
|
+
super.seekTo(msec);
|
|
641
|
+
if (isCompleted && mVideoDuration != 0 && msec < mVideoDuration) {
|
|
642
|
+
isCompleted = false;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
@Override
|
|
648
|
+
public int getBufferPercentage() {
|
|
649
|
+
return 0;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
@Override
|
|
653
|
+
public boolean canPause() {
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
@Override
|
|
658
|
+
public boolean canSeekBackward() {
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
@Override
|
|
663
|
+
public boolean canSeekForward() {
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
@Override
|
|
668
|
+
public int getAudioSessionId() {
|
|
669
|
+
return 0;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
@Override
|
|
673
|
+
public void onCompletion(MediaPlayer mp) {
|
|
674
|
+
isCompleted = true;
|
|
675
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_END.toString(), null);
|
|
676
|
+
if (!mRepeat) {
|
|
677
|
+
setKeepScreenOn(false);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// This is not fully tested and does not work for all forms of timed metadata
|
|
682
|
+
@TargetApi(23) // 6.0
|
|
683
|
+
public class TimedMetaDataAvailableListener
|
|
684
|
+
implements MediaPlayer.OnTimedMetaDataAvailableListener
|
|
685
|
+
{
|
|
686
|
+
public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) {
|
|
687
|
+
WritableMap event = Arguments.createMap();
|
|
688
|
+
|
|
689
|
+
try {
|
|
690
|
+
String rawMeta = new String(data.getMetaData(), "UTF-8");
|
|
691
|
+
WritableMap id3 = Arguments.createMap();
|
|
692
|
+
|
|
693
|
+
id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1));
|
|
694
|
+
id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN");
|
|
695
|
+
|
|
696
|
+
WritableArray metadata = new WritableNativeArray();
|
|
697
|
+
|
|
698
|
+
metadata.pushMap(id3);
|
|
699
|
+
|
|
700
|
+
event.putArray(EVENT_PROP_METADATA, metadata);
|
|
701
|
+
event.putDouble(EVENT_PROP_TARGET, getId());
|
|
702
|
+
} catch (UnsupportedEncodingException e) {
|
|
703
|
+
e.printStackTrace();
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
@Override
|
|
711
|
+
protected void onDetachedFromWindow() {
|
|
712
|
+
mMediaPlayerValid = false;
|
|
713
|
+
super.onDetachedFromWindow();
|
|
714
|
+
setKeepScreenOn(false);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
@Override
|
|
718
|
+
protected void onAttachedToWindow() {
|
|
719
|
+
super.onAttachedToWindow();
|
|
720
|
+
|
|
721
|
+
if(mMainVer>0) {
|
|
722
|
+
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer);
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders);
|
|
726
|
+
}
|
|
727
|
+
setKeepScreenOn(mPreventsDisplaySleepDuringVideoPlayback);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
@Override
|
|
731
|
+
public void onHostPause() {
|
|
732
|
+
if (mMediaPlayerValid && !mPaused && !mPlayInBackground) {
|
|
733
|
+
/* Pause the video in background
|
|
734
|
+
* Don't update the paused prop, developers should be able to update it on background
|
|
735
|
+
* so that when you return to the app the video is paused
|
|
736
|
+
*/
|
|
737
|
+
mBackgroundPaused = true;
|
|
738
|
+
mMediaPlayer.pause();
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
@Override
|
|
743
|
+
public void onHostResume() {
|
|
744
|
+
mBackgroundPaused = false;
|
|
745
|
+
if (mMediaPlayerValid && !mPlayInBackground && !mPaused) {
|
|
746
|
+
new Handler().post(new Runnable() {
|
|
747
|
+
@Override
|
|
748
|
+
public void run() {
|
|
749
|
+
// Restore original state
|
|
750
|
+
setPausedModifier(false);
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
@Override
|
|
757
|
+
public void onHostDestroy() {
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* toStringMap converts a {@link ReadableMap} into a HashMap.
|
|
762
|
+
*
|
|
763
|
+
* @param readableMap The ReadableMap to be conveted.
|
|
764
|
+
* @return A HashMap containing the data that was in the ReadableMap.
|
|
765
|
+
* @see 'Adapted from https://github.com/artemyarulin/react-native-eval/blob/master/android/src/main/java/com/evaluator/react/ConversionUtil.java'
|
|
766
|
+
*/
|
|
767
|
+
public static Map<String, String> toStringMap(@Nullable ReadableMap readableMap) {
|
|
768
|
+
Map<String, String> result = new HashMap<>();
|
|
769
|
+
if (readableMap == null)
|
|
770
|
+
return result;
|
|
771
|
+
|
|
772
|
+
com.facebook.react.bridge.ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
|
|
773
|
+
while (iterator.hasNextKey()) {
|
|
774
|
+
String key = iterator.nextKey();
|
|
775
|
+
result.put(key, readableMap.getString(key));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
return result;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// Select track (so we can use it to listen to timed meta data updates)
|
|
782
|
+
private void selectTimedMetadataTrack(MediaPlayer mp) {
|
|
783
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
try { // It's possible this could throw an exception if the framework doesn't support getting track info
|
|
787
|
+
MediaPlayer.TrackInfo[] trackInfo = mp.getTrackInfo();
|
|
788
|
+
for (int i = 0; i < trackInfo.length; ++i) {
|
|
789
|
+
if (trackInfo[i].getTrackType() == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
|
|
790
|
+
mp.selectTrack(i);
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
} catch (Exception e) {}
|
|
795
|
+
}
|
|
796
|
+
}
|