2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2022-02-23 17:38:21 +08:00
|
|
|
Copyright (c) 2022 Bytedance Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
#include "ui/UIVideoPlayer.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// No Available on tvOS
|
2022-07-16 10:43:05 +08:00
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_IOS && !defined(AX_TARGET_OS_TVOS)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
using namespace ax::ui;
|
2019-11-23 20:27:39 +08:00
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
# include "platform/ios/CCEAGLView-ios.h"
|
|
|
|
# import <AVKit/AVPlayerViewController.h>
|
|
|
|
# import <CoreMedia/CMTime.h>
|
|
|
|
# include "base/CCDirector.h"
|
|
|
|
# include "platform/CCFileUtils.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
@interface UIVideoViewWrapperIos : NSObject
|
|
|
|
|
|
|
|
typedef NS_ENUM(NSInteger, PlayerbackState) {
|
|
|
|
PlayerbackStateUnknown = 0,
|
|
|
|
PlayerbackStatePaused,
|
|
|
|
PlayerbackStopped,
|
|
|
|
PlayerbackStatePlaying,
|
|
|
|
PlayerbackStateCompleted
|
|
|
|
};
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
@property(assign, nonatomic) AVPlayerViewController* playerController;
|
|
|
|
|
|
|
|
- (void)setFrame:(int)left:(int)top:(int)width:(int)height;
|
|
|
|
- (void)setURL:(int)videoSource:(std::string&)videoUrl;
|
|
|
|
- (void)play;
|
|
|
|
- (void)pause;
|
|
|
|
- (void)resume;
|
|
|
|
- (void)stop;
|
|
|
|
- (void)seekTo:(float)sec;
|
|
|
|
- (void)setVisible:(BOOL)visible;
|
|
|
|
- (void)setKeepRatioEnabled:(BOOL)enabled;
|
|
|
|
- (void)setFullScreenEnabled:(BOOL)enabled;
|
|
|
|
- (BOOL)isFullScreenEnabled;
|
|
|
|
- (void)showPlaybackControls:(BOOL)value;
|
|
|
|
- (void)setRepeatEnabled:(BOOL)enabled;
|
|
|
|
- (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled;
|
|
|
|
|
|
|
|
- (id)init:(void*)videoPlayer;
|
|
|
|
- (void)videoFinished:(NSNotification*)notification;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
@implementation UIVideoViewWrapperIos {
|
2019-11-23 20:27:39 +08:00
|
|
|
int _left;
|
|
|
|
int _top;
|
|
|
|
int _width;
|
|
|
|
int _height;
|
|
|
|
BOOL _keepRatioEnabled;
|
|
|
|
BOOL _repeatEnabled;
|
|
|
|
BOOL _showPlaybackControls;
|
|
|
|
BOOL _userInteractionEnabled;
|
|
|
|
PlayerbackState _state;
|
|
|
|
VideoPlayer* _videoPlayer;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (id)init:(void*)videoPlayer
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (self = [super init])
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
self.playerController = [AVPlayerViewController new];
|
|
|
|
|
|
|
|
[self setRepeatEnabled:FALSE];
|
|
|
|
[self showPlaybackControls:TRUE];
|
|
|
|
[self setUserInteractionEnabled:TRUE];
|
|
|
|
[self setKeepRatioEnabled:FALSE];
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_videoPlayer = (VideoPlayer*)videoPlayer;
|
2021-12-31 12:12:40 +08:00
|
|
|
_state = PlayerbackStateUnknown;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)dealloc
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
_videoPlayer = nullptr;
|
|
|
|
[self clean];
|
|
|
|
[self.playerController release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)clean
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
[self stop];
|
|
|
|
[self removePlayerEventListener];
|
|
|
|
[self.playerController.view removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setFrame:(int)left:(int)top:(int)width:(int)height
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
_left = left;
|
|
|
|
_width = width;
|
|
|
|
_top = top;
|
2019-11-23 20:27:39 +08:00
|
|
|
_height = height;
|
|
|
|
[self.playerController.view setFrame:CGRectMake(left, top, width, height)];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setFullScreenEnabled:(BOOL)enabled
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// AVPlayerViewController doesn't provide API to enable fullscreen. But you can toggle
|
|
|
|
// fullsreen by the playback controllers.
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (BOOL)isFullScreenEnabled
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)showPlaybackControls:(BOOL)value
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
_showPlaybackControls = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
self.playerController.showsPlaybackControls = value;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setRepeatEnabled:(BOOL)enabled
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
_repeatEnabled = enabled;
|
2021-12-31 12:12:40 +08:00
|
|
|
if (self.playerController.player)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
if (_repeatEnabled)
|
|
|
|
self.playerController.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
|
|
|
|
else
|
|
|
|
self.playerController.player.actionAtItemEnd = AVPlayerActionAtItemEndPause;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
_userInteractionEnabled = userInteractionEnabled;
|
2019-11-23 20:27:39 +08:00
|
|
|
self.playerController.view.userInteractionEnabled = _userInteractionEnabled;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setURL:(int)videoSource:(std::string&)videoUrl
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
[self clean];
|
|
|
|
|
|
|
|
if (videoSource == 1)
|
2021-12-31 12:12:40 +08:00
|
|
|
self.playerController.player =
|
|
|
|
[[[AVPlayer alloc] initWithURL:[NSURL URLWithString:@(videoUrl.c_str())]] autorelease];
|
2019-11-23 20:27:39 +08:00
|
|
|
else
|
2021-12-31 12:12:40 +08:00
|
|
|
self.playerController.player =
|
|
|
|
[[[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:@(videoUrl.c_str())]] autorelease];
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
[self setRepeatEnabled:_repeatEnabled];
|
|
|
|
[self setKeepRatioEnabled:_keepRatioEnabled];
|
|
|
|
[self setUserInteractionEnabled:_userInteractionEnabled];
|
|
|
|
[self showPlaybackControls:_showPlaybackControls];
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
auto view = ax::Director::getInstance()->getOpenGLView();
|
2022-09-05 14:13:52 +08:00
|
|
|
auto eaglView = (CCEAGLView*)view->getEAGLView();
|
|
|
|
[eaglView addSubview:self.playerController.view];
|
2019-11-23 20:27:39 +08:00
|
|
|
[self registerPlayerEventListener];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)videoFinished:(NSNotification*)notification
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_videoPlayer != nullptr)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::COMPLETED);
|
|
|
|
_state = PlayerbackStateCompleted;
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_repeatEnabled)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
[self seekTo:0];
|
|
|
|
[self play];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)seekTo:(float)sec
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (self.playerController.player)
|
|
|
|
[self.playerController.player seekToTime:CMTimeMake(sec, 1)];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setVisible:(BOOL)visible
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
[self.playerController.view setHidden:!visible];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setKeepRatioEnabled:(BOOL)enabled
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
_keepRatioEnabled = enabled;
|
|
|
|
if (_keepRatioEnabled)
|
|
|
|
self.playerController.videoGravity = AVLayerVideoGravityResizeAspect;
|
|
|
|
else
|
|
|
|
self.playerController.videoGravity = AVLayerVideoGravityResizeAspectFill;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)play
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (self.playerController.player && _state != PlayerbackStatePlaying)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
[self.playerController.player play];
|
|
|
|
_state = PlayerbackStatePlaying;
|
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::PLAYING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)pause
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (self.playerController.player && _state == PlayerbackStatePlaying)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
[self.playerController.player pause];
|
|
|
|
_state = PlayerbackStatePaused;
|
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::PAUSED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)resume
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (self.playerController.player && _state == PlayerbackStatePaused)
|
|
|
|
[self play];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)stop
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// AVPlayer doesn't have stop, so just pause it, and seek time to 0.
|
2021-12-31 12:12:40 +08:00
|
|
|
if (self.playerController.player && _state != PlayerbackStopped)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
[self seekTo:0];
|
|
|
|
[self.playerController.player pause];
|
|
|
|
_state = PlayerbackStopped;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// stop() will be invoked in dealloc, which is invoked by _videoPlayer's destructor,
|
|
|
|
// so do't send the message when _videoPlayer is being deleted.
|
|
|
|
if (_videoPlayer)
|
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::STOPPED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)registerPlayerEventListener
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (self.playerController.player)
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(videoFinished:)
|
2021-12-31 12:12:40 +08:00
|
|
|
name:AVPlayerItemDidPlayToEndTimeNotification
|
|
|
|
object:self.playerController.player.currentItem];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)removePlayerEventListener
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (self.playerController.player)
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
2021-12-31 12:12:40 +08:00
|
|
|
name:AVPlayerItemDidPlayToEndTimeNotification
|
|
|
|
object:self.playerController.player.currentItem];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
VideoPlayer::VideoPlayer()
|
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
_videoContext = [[UIVideoViewWrapperIos alloc] init:this];
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
# if AX_VIDEOPLAYER_DEBUG_DRAW
|
2019-11-23 20:27:39 +08:00
|
|
|
_debugDrawNode = DrawNode::create();
|
|
|
|
addChild(_debugDrawNode);
|
2021-12-31 12:12:40 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoPlayer::~VideoPlayer()
|
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
if (_videoContext)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) dealloc];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void VideoPlayer::setFileName(std::string_view fileName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
_videoURL = FileUtils::getInstance()->fullPathForFilename(fileName);
|
2019-11-23 20:27:39 +08:00
|
|
|
_videoSource = VideoPlayer::Source::FILENAME;
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setURL:(int) _videoSource:_videoURL];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void VideoPlayer::setURL(std::string_view videoUrl)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
_videoURL = videoUrl;
|
2019-11-23 20:27:39 +08:00
|
|
|
_videoSource = VideoPlayer::Source::URL;
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setURL:(int) _videoSource:_videoURL];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::setLooping(bool looping)
|
|
|
|
{
|
|
|
|
_isLooping = looping;
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setRepeatEnabled:_isLooping];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::setUserInputEnabled(bool enableInput)
|
|
|
|
{
|
|
|
|
_isUserInputEnabled = enableInput;
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setUserInteractionEnabled:enableInput];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::setStyle(StyleType style)
|
|
|
|
{
|
|
|
|
_styleType = style;
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
switch (style)
|
|
|
|
{
|
|
|
|
case StyleType::DEFAULT:
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) showPlaybackControls:TRUE];
|
2021-12-31 12:12:40 +08:00
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
case StyleType::NONE:
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) showPlaybackControls:FALSE];
|
2021-12-31 12:12:40 +08:00
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-28 12:14:08 +08:00
|
|
|
void VideoPlayer::setPlayRate(float fRate) {}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void VideoPlayer::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::ui::Widget::draw(renderer, transform, flags);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (flags & FLAGS_TRANSFORM_DIRTY)
|
|
|
|
{
|
|
|
|
auto directorInstance = Director::getInstance();
|
2021-12-31 12:12:40 +08:00
|
|
|
auto glView = directorInstance->getOpenGLView();
|
|
|
|
auto frameSize = glView->getFrameSize();
|
|
|
|
auto scaleFactor = [static_cast<CCEAGLView*>(glView->getEAGLView()) contentScaleFactor];
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto winSize = directorInstance->getWinSize();
|
|
|
|
|
|
|
|
auto leftBottom = convertToWorldSpace(Vec2::ZERO);
|
2021-12-31 12:12:40 +08:00
|
|
|
auto rightTop = convertToWorldSpace(Vec2(_contentSize.width, _contentSize.height));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
auto uiLeft = (frameSize.width / 2 + (leftBottom.x - winSize.width / 2) * glView->getScaleX()) / scaleFactor;
|
|
|
|
auto uiTop = (frameSize.height / 2 - (rightTop.y - winSize.height / 2) * glView->getScaleY()) / scaleFactor;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setFrame:
|
2022-04-28 12:14:08 +08:00
|
|
|
uiLeft:uiTop:(rightTop.x - leftBottom.x) * glView->getScaleX() /
|
|
|
|
scaleFactor:((rightTop.y - leftBottom.y) * glView->getScaleY() /
|
|
|
|
scaleFactor)];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
# if AX_VIDEOPLAYER_DEBUG_DRAW
|
2019-11-23 20:27:39 +08:00
|
|
|
_debugDrawNode->clear();
|
2021-12-31 12:12:40 +08:00
|
|
|
auto size = getContentSize();
|
|
|
|
Point vertices[4] = {Point::ZERO, Point(size.width, 0), Point(size.width, size.height), Point(0, size.height)};
|
2019-11-23 20:27:39 +08:00
|
|
|
_debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
|
2021-12-31 12:12:40 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
bool VideoPlayer::isFullScreenEnabled() const
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
return [((UIVideoViewWrapperIos*)_videoContext) isFullScreenEnabled];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::setFullScreenEnabled(bool enabled)
|
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setFullScreenEnabled:enabled];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::setKeepAspectRatioEnabled(bool enable)
|
|
|
|
{
|
|
|
|
if (_keepAspectRatioEnabled != enable)
|
|
|
|
{
|
|
|
|
_keepAspectRatioEnabled = enable;
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setKeepRatioEnabled:enable];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::play()
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (!_videoURL.empty())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) play];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::pause()
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (!_videoURL.empty())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) pause];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::resume()
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (!_videoURL.empty())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) resume];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::stop()
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (!_videoURL.empty())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) stop];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::seekTo(float sec)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (!_videoURL.empty())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) seekTo:sec];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoPlayer::isPlaying() const
|
|
|
|
{
|
|
|
|
return _isPlaying;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoPlayer::isLooping() const
|
|
|
|
{
|
|
|
|
return _isLooping;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoPlayer::isUserInputEnabled() const
|
|
|
|
{
|
|
|
|
return _isUserInputEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::setVisible(bool visible)
|
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::ui::Widget::setVisible(visible);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (!visible)
|
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setVisible:NO];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
else if (isRunning())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setVisible:YES];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::onEnter()
|
|
|
|
{
|
|
|
|
Widget::onEnter();
|
|
|
|
if (isVisible())
|
|
|
|
{
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setVisible:YES];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::onExit()
|
|
|
|
{
|
|
|
|
Widget::onExit();
|
2022-02-23 17:38:21 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoContext) setVisible:NO];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback)
|
|
|
|
{
|
|
|
|
_eventCallback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::onPlayEvent(int event)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (event == (int)VideoPlayer::EventType::PLAYING)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
_isPlaying = true;
|
2021-12-31 12:12:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
_isPlaying = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_eventCallback)
|
|
|
|
{
|
|
|
|
_eventCallback(this, (VideoPlayer::EventType)event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
void VideoPlayer::setContentSize(const Size& contentSize)
|
|
|
|
{
|
|
|
|
Widget::setContentSize(contentSize);
|
|
|
|
// reinterpret_cast<PrivateVideoDescriptor*>(_videoContext)->_originalViewSize = contentSize;
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::ui::Widget* VideoPlayer::createCloneInstance()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return VideoPlayer::create();
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void VideoPlayer::copySpecialProperties(Widget* widget)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
VideoPlayer* videoPlayer = dynamic_cast<VideoPlayer*>(widget);
|
|
|
|
if (videoPlayer)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
_isPlaying = videoPlayer->_isPlaying;
|
|
|
|
_isLooping = videoPlayer->_isLooping;
|
|
|
|
_isUserInputEnabled = videoPlayer->_isUserInputEnabled;
|
|
|
|
_styleType = videoPlayer->_styleType;
|
|
|
|
_fullScreenEnabled = videoPlayer->_fullScreenEnabled;
|
|
|
|
_fullScreenDirty = videoPlayer->_fullScreenDirty;
|
|
|
|
_videoURL = videoPlayer->_videoURL;
|
2019-11-23 20:27:39 +08:00
|
|
|
_keepAspectRatioEnabled = videoPlayer->_keepAspectRatioEnabled;
|
2021-12-31 12:12:40 +08:00
|
|
|
_videoSource = videoPlayer->_videoSource;
|
|
|
|
_videoPlayerIndex = videoPlayer->_videoPlayerIndex;
|
|
|
|
_eventCallback = videoPlayer->_eventCallback;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|