feat: add getCurrentPosition to component's ref (#3824)
* feat: add getCurrentPosition to component's ref --------- Co-authored-by: mostafahasani <hasanie.mostafa@alopeyk.com>
This commit is contained in:
committed by
GitHub
parent
e23e02b359
commit
c7f4d7b83b
@@ -124,6 +124,7 @@ import com.brentvatne.react.R;
|
||||
import com.brentvatne.receiver.AudioBecomingNoisyReceiver;
|
||||
import com.brentvatne.receiver.BecomingNoisyListener;
|
||||
import com.facebook.react.bridge.LifecycleEventListener;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.google.ads.interactivemedia.v3.api.AdError;
|
||||
@@ -697,6 +698,15 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
mainHandler.postDelayed(mainRunnable, 1);
|
||||
}
|
||||
|
||||
public void getCurrentPosition(Promise promise) {
|
||||
if (player != null) {
|
||||
double currentPosition = player.getCurrentPosition() / 1000;
|
||||
promise.resolve(currentPosition);
|
||||
} else {
|
||||
promise.reject("PLAYER_NOT_AVAILABLE", "Player is not initialized.");
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePlayerCore(ReactExoplayerView self) {
|
||||
ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
|
||||
self.trackSelector = new DefaultTrackSelector(getContext(), videoTrackSelectionFactory);
|
||||
|
@@ -2,6 +2,7 @@ package com.brentvatne.react
|
||||
|
||||
import com.brentvatne.common.toolbox.ReactBridgeUtils
|
||||
import com.brentvatne.exoplayer.ReactExoplayerView
|
||||
import com.facebook.react.bridge.Promise
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
||||
import com.facebook.react.bridge.ReactMethod
|
||||
@@ -61,6 +62,13 @@ class VideoManagerModule(reactContext: ReactApplicationContext?) : ReactContextB
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun getCurrentPosition(reactTag: Int, promise: Promise) {
|
||||
performOnPlayerView(reactTag) {
|
||||
it?.getCurrentPosition(promise)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val REACT_CLASS = "VideoManager"
|
||||
}
|
||||
|
Reference in New Issue
Block a user