diff --git a/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java b/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java index fda28608c7..782e337778 100644 --- a/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java +++ b/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java @@ -28,17 +28,14 @@ import android.graphics.Rect; import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.util.Log; import android.util.SparseArray; import android.view.View; import android.widget.FrameLayout; -import android.widget.VideoView; import org.cocos2dx.lib.Cocos2dxVideoView.OnVideoEventListener; import java.lang.ref.WeakReference; import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; @@ -70,8 +67,6 @@ public class Cocos2dxVideoHelper { private final static int VideoTaskRestart = 10; private final static int VideoTaskKeepRatio = 11; private final static int VideoTaskFullScreen = 12; - private final static int VideoTaskCurrentTime = 13; - private final static int VideoTaskDuration = 14; final static int KeyEventBack = 1000; static class VideoHandler extends Handler{ @@ -393,10 +388,10 @@ public class Cocos2dxVideoHelper { Callable callable = new Callable() { @Override public Float call() throws Exception { - Cocos2dxVideoView viedo = mVideoViews.get(index); + Cocos2dxVideoView video = mVideoViews.get(index); float currentPosition = -1; - if (viedo != null) { - currentPosition = viedo.getCurrentPosition() / 1000.0f; + if (video != null) { + currentPosition = video.getCurrentPosition() / 1000.0f; } return new Float(currentPosition); } @@ -415,10 +410,10 @@ public class Cocos2dxVideoHelper { Callable callable = new Callable() { @Override public Float call() throws Exception { - Cocos2dxVideoView viedo = mVideoViews.get(index); + Cocos2dxVideoView video = mVideoViews.get(index); float duration = -1; - if (viedo != null) { - duration = viedo.getDuration() / 1000.0f; + if (video != null) { + duration = video.getDuration() / 1000.0f; } return new Float(duration); } @@ -433,6 +428,24 @@ public class Cocos2dxVideoHelper { } } + public static boolean isPlaying(final int index) { + Callable callable = new Callable() { + @Override + public Boolean call() throws Exception { + Cocos2dxVideoView video = mVideoViews.get(index); + return video != null && video.isPlaying(); + } + }; + + try { + return callInMainThread(callable); + } catch (ExecutionException e) { + return false; + } catch (InterruptedException e) { + return false; + } + } + public static void setVideoVisible(int index, boolean visible) { Message msg = Message.obtain(); diff --git a/native/cocos/ui/UIVideoPlayer-android.cpp b/native/cocos/ui/UIVideoPlayer-android.cpp index 8db8dde37c..4a8f866a2b 100644 --- a/native/cocos/ui/UIVideoPlayer-android.cpp +++ b/native/cocos/ui/UIVideoPlayer-android.cpp @@ -227,7 +227,7 @@ void VideoPlayer::seekTo(float sec) bool VideoPlayer::isPlaying() const { - return _isPlaying; + return JniHelper::callStaticBooleanMethod(videoHelperClassName, "isPlaying", _videoPlayerIndex); } void VideoPlayer::setVisible(bool visible)