diff --git a/native/cocos/ui/UIVideoPlayer-ios.mm b/native/cocos/ui/UIVideoPlayer-ios.mm index 01417589f8..fb3dd9e931 100644 --- a/native/cocos/ui/UIVideoPlayer-ios.mm +++ b/native/cocos/ui/UIVideoPlayer-ios.mm @@ -45,6 +45,8 @@ using namespace cocos2d::experimental::ui; - (void) resume; - (void) stop; - (void) seekTo:(float) sec; +- (float) currentTime; +- (float) duration; - (void) setVisible:(BOOL) visible; - (void) setKeepRatioEnabled:(bool) enabled; - (void) setFullScreenEnabled:(bool) enabled; @@ -207,6 +209,22 @@ using namespace cocos2d::experimental::ui; } } +-(float) currentTime +{ + if (self.moviePlayer != NULL) { + return [self.moviePlayer currentPlaybackTime]; + } + return -1; +} + +-(float) duration +{ + if (self.moviePlayer != NULL) { + return [self.moviePlayer duration]; + } + return -1; +} + -(void) setVisible:(BOOL)visible { if (self.moviePlayer != NULL) { @@ -409,6 +427,16 @@ void VideoPlayer::seekTo(float sec) } } +float VideoPlayer::currentTime()const +{ + return [((UIVideoViewWrapperIos*)_videoView) currentTime]; +} + +float VideoPlayer::duration()const +{ + return [((UIVideoViewWrapperIos*)_videoView) duration]; +} + bool VideoPlayer::isPlaying() const { return _isPlaying; diff --git a/native/cocos/ui/UIVideoPlayer.h b/native/cocos/ui/UIVideoPlayer.h index 79ebddaa2e..9f672c0fab 100644 --- a/native/cocos/ui/UIVideoPlayer.h +++ b/native/cocos/ui/UIVideoPlayer.h @@ -122,6 +122,13 @@ namespace experimental{ */ virtual void seekTo(float sec); + /** + * Get the current play time, measure in seconds. + */ + float currentTime()const; + + float duration() const; + /** * Checks whether the VideoPlayer is playing. *