2014-05-08 18:12:53 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
#include "UIVideoPlayer.h"
|
2014-05-08 18:12:53 +08:00
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
2014-05-09 11:30:07 +08:00
|
|
|
|
|
|
|
using namespace cocos2d::experimental::ui;
|
2014-05-08 18:12:53 +08:00
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
#include "CCEAGLView.h"
|
2014-06-04 14:26:21 +08:00
|
|
|
#include "CCGLView.h"
|
2014-05-08 18:12:53 +08:00
|
|
|
#import <MediaPlayer/MediaPlayer.h>
|
2014-06-04 14:26:21 +08:00
|
|
|
#include "base/CCDirector.h"
|
2014-05-08 18:12:53 +08:00
|
|
|
|
|
|
|
@interface UIVideoViewWrapperIos : NSObject
|
|
|
|
|
|
|
|
@property (strong,nonatomic) MPMoviePlayerController * moviePlayer;
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
- (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;
|
2014-05-08 18:12:53 +08:00
|
|
|
- (void) setFullScreenEnabled:(bool) enabled;
|
|
|
|
- (bool) isFullScreenEnabled;
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
-(id) init:(void*) videoPlayer;
|
2014-05-08 18:12:53 +08:00
|
|
|
|
|
|
|
-(void) videoFinished:(NSNotification*) notification;
|
|
|
|
-(void) playStateChange;
|
|
|
|
|
|
|
|
+(NSString*) fullPathFromRelativePath:(NSString*) relPath;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation UIVideoViewWrapperIos
|
|
|
|
{
|
|
|
|
int _left;
|
|
|
|
int _top;
|
|
|
|
int _width;
|
|
|
|
int _height;
|
|
|
|
bool _keepRatioEnabled;
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
VideoPlayer* _videoPlayer;
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
-(id)init:(void*)videoPlayer
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
self.moviePlayer = nullptr;
|
2014-05-09 11:30:07 +08:00
|
|
|
_videoPlayer = (VideoPlayer*)videoPlayer;
|
2014-05-08 18:12:53 +08:00
|
|
|
_keepRatioEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) dealloc
|
|
|
|
{
|
|
|
|
if (self.moviePlayer != nullptr) {
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer];
|
|
|
|
|
|
|
|
[self.moviePlayer stop];
|
|
|
|
[self.moviePlayer.view removeFromSuperview];
|
|
|
|
self.moviePlayer = nullptr;
|
2014-05-09 11:30:07 +08:00
|
|
|
_videoPlayer = nullptr;
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) setFrame:(int)left :(int)top :(int)width :(int)height
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
_left = left;
|
|
|
|
_width = width;
|
|
|
|
_top = top;
|
|
|
|
_height = height;
|
|
|
|
if (self.moviePlayer != nullptr) {
|
|
|
|
[self.moviePlayer.view setFrame:CGRectMake(left, top, width, height)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) setFullScreenEnabled:(bool) enabled
|
|
|
|
{
|
|
|
|
if (self.moviePlayer != nullptr) {
|
|
|
|
[self.moviePlayer setFullscreen:enabled animated:(true)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-(bool) isFullScreenEnabled
|
|
|
|
{
|
|
|
|
if (self.moviePlayer != nullptr) {
|
|
|
|
return [self.moviePlayer isFullscreen];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) setURL:(int)videoSource :(std::string &)videoUrl
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self.moviePlayer != nullptr) {
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer];
|
|
|
|
|
|
|
|
[self.moviePlayer stop];
|
|
|
|
[self.moviePlayer.view removeFromSuperview];
|
|
|
|
self.moviePlayer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (videoSource == 1) {
|
|
|
|
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@(videoUrl.c_str())]];
|
|
|
|
self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
|
|
|
|
} else {
|
|
|
|
NSString *path = [UIVideoViewWrapperIos fullPathFromRelativePath:@(videoUrl.c_str())];
|
|
|
|
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
|
|
|
|
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
|
|
|
|
}
|
|
|
|
self.moviePlayer.allowsAirPlay = false;
|
|
|
|
self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
|
|
|
|
self.moviePlayer.view.userInteractionEnabled = true;
|
|
|
|
|
|
|
|
auto clearColor = [UIColor clearColor];
|
|
|
|
self.moviePlayer.backgroundView.backgroundColor = clearColor;
|
|
|
|
self.moviePlayer.view.backgroundColor = clearColor;
|
|
|
|
for (UIView * subView in self.moviePlayer.view.subviews) {
|
|
|
|
subView.backgroundColor = clearColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_keepRatioEnabled) {
|
|
|
|
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
|
|
|
|
} else {
|
|
|
|
self.moviePlayer.scalingMode = MPMovieScalingModeFill;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto view = cocos2d::Director::getInstance()->getOpenGLView();
|
|
|
|
auto eaglview = (CCEAGLView *) view->getEAGLView();
|
|
|
|
[eaglview addSubview:self.moviePlayer.view];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playStateChange) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) videoFinished:(NSNotification *)notification
|
|
|
|
{
|
2014-05-09 11:30:07 +08:00
|
|
|
if(_videoPlayer != nullptr)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if([self.moviePlayer playbackState] != MPMoviePlaybackStateStopped)
|
|
|
|
{
|
2014-07-17 21:44:33 +08:00
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::COMPLETED);
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) playStateChange
|
|
|
|
{
|
|
|
|
MPMoviePlaybackState state = [self.moviePlayer playbackState];
|
|
|
|
switch (state) {
|
|
|
|
case MPMoviePlaybackStatePaused:
|
2014-07-17 21:44:33 +08:00
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::PAUSED);
|
2014-05-08 18:12:53 +08:00
|
|
|
break;
|
|
|
|
case MPMoviePlaybackStateStopped:
|
2014-07-17 21:44:33 +08:00
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::STOPPED);
|
2014-05-08 18:12:53 +08:00
|
|
|
break;
|
|
|
|
case MPMoviePlaybackStatePlaying:
|
2014-07-17 21:44:33 +08:00
|
|
|
_videoPlayer->onPlayEvent((int)VideoPlayer::EventType::PLAYING);
|
2014-05-08 18:12:53 +08:00
|
|
|
break;
|
|
|
|
case MPMoviePlaybackStateInterrupted:
|
|
|
|
break;
|
|
|
|
case MPMoviePlaybackStateSeekingBackward:
|
|
|
|
break;
|
|
|
|
case MPMoviePlaybackStateSeekingForward:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) seekTo:(float)sec
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self.moviePlayer != NULL) {
|
|
|
|
[self.moviePlayer setCurrentPlaybackTime:(sec)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) setVisible:(bool)visible
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self.moviePlayer != NULL) {
|
|
|
|
[self.moviePlayer.view setHidden:visible];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) setKeepRatioEnabled:(bool)enabled
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
_keepRatioEnabled = enabled;
|
|
|
|
if (self.moviePlayer != NULL) {
|
|
|
|
if (enabled) {
|
|
|
|
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
|
|
|
|
} else {
|
|
|
|
self.moviePlayer.scalingMode = MPMovieScalingModeFill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) play
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self.moviePlayer != NULL) {
|
|
|
|
[self.moviePlayer.view setFrame:CGRectMake(_left, _top, _width, _height)];
|
|
|
|
[self.moviePlayer play];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) pause
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self.moviePlayer != NULL) {
|
|
|
|
[self.moviePlayer pause];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) resume
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self.moviePlayer != NULL) {
|
|
|
|
if([self.moviePlayer playbackState] == MPMoviePlaybackStatePaused)
|
|
|
|
{
|
|
|
|
[self.moviePlayer play];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
-(void) stop
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (self.moviePlayer != NULL) {
|
|
|
|
[self.moviePlayer stop];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+(NSString*) fullPathFromRelativePath:(NSString*) relPath
|
|
|
|
{
|
|
|
|
// do not convert an absolute path (starting with '/')
|
|
|
|
if(([relPath length] > 0) && ([relPath characterAtIndex:0] == '/'))
|
|
|
|
{
|
|
|
|
return relPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]];
|
|
|
|
NSString *file = [imagePathComponents lastObject];
|
|
|
|
|
|
|
|
[imagePathComponents removeLastObject];
|
|
|
|
NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents];
|
|
|
|
|
|
|
|
NSString *fullpath = [[NSBundle mainBundle] pathForResource:file ofType:nil inDirectory:imageDirectory];
|
|
|
|
if (fullpath == nil)
|
|
|
|
fullpath = relPath;
|
|
|
|
|
|
|
|
return fullpath;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
//------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
VideoPlayer::VideoPlayer()
|
|
|
|
: _videoPlayerIndex(-1)
|
2014-05-14 11:18:11 +08:00
|
|
|
, _eventCallback(nullptr)
|
2014-05-08 18:12:53 +08:00
|
|
|
, _fullScreenEnabled(false)
|
|
|
|
, _fullScreenDirty(false)
|
|
|
|
, _keepAspectRatioEnabled(false)
|
|
|
|
, _isPlaying(false)
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
_videoView = [[UIVideoViewWrapperIos alloc] init:this];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
VideoPlayer::~VideoPlayer()
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
if(_videoView)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) dealloc];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::setFileName(const std::string& fileName)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
_videoURL = fileName;
|
|
|
|
_videoSource = VideoPlayer::Source::FILENAME;
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) setURL:(int)_videoSource :_videoURL];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::setURL(const std::string& videoUrl)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
_videoURL = videoUrl;
|
|
|
|
_videoSource = VideoPlayer::Source::URL;
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) setURL:(int)_videoSource :_videoURL];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void VideoPlayer::draw(Renderer* renderer, const Mat4 &transform, uint32_t flags)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-06-03 07:02:54 +08:00
|
|
|
cocos2d::ui::Widget::draw(renderer,transform,flags);
|
2014-05-08 18:12:53 +08:00
|
|
|
|
2014-06-03 07:02:54 +08:00
|
|
|
if (flags & FLAGS_TRANSFORM_DIRTY)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
auto directorInstance = Director::getInstance();
|
|
|
|
auto glView = directorInstance->getOpenGLView();
|
|
|
|
auto frameSize = glView->getFrameSize();
|
2014-07-25 15:41:12 +08:00
|
|
|
auto scaleFactor = [static_cast<CCEAGLView *>(glView->getEAGLView()) contentScaleFactor];
|
2014-05-08 18:12:53 +08:00
|
|
|
|
|
|
|
auto winSize = directorInstance->getWinSize();
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
auto leftBottom = convertToWorldSpace(Vec2::ZERO);
|
|
|
|
auto rightTop = convertToWorldSpace(Vec2(_contentSize.width,_contentSize.height));
|
2014-05-08 18:12:53 +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;
|
|
|
|
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) setFrame :uiLeft :uiTop
|
2014-05-08 18:12:53 +08:00
|
|
|
:(rightTop.x - leftBottom.x) * glView->getScaleX() / scaleFactor
|
|
|
|
:( (rightTop.y - leftBottom.y) * glView->getScaleY()/scaleFactor)];
|
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
#if CC_VIDEOPLAYER_DEBUG_DRAW
|
2014-05-08 18:12:53 +08:00
|
|
|
_customDebugDrawCommand.init(_globalZOrder);
|
2014-05-09 11:30:07 +08:00
|
|
|
_customDebugDrawCommand.func = CC_CALLBACK_0(VideoPlayer::drawDebugData, this);
|
2014-05-08 18:12:53 +08:00
|
|
|
renderer->addCommand(&_customDebugDrawCommand);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-27 11:17:13 +08:00
|
|
|
bool VideoPlayer::isFullScreenEnabled()const
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
return [((UIVideoViewWrapperIos*)_videoView) isFullScreenEnabled];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
void VideoPlayer::setFullScreenEnabled(bool enabled)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) setFullScreenEnabled:enabled];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
void VideoPlayer::setKeepAspectRatioEnabled(bool enable)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
if (_keepAspectRatioEnabled != enable)
|
|
|
|
{
|
|
|
|
_keepAspectRatioEnabled = enable;
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) setKeepRatioEnabled:enable];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
#if CC_VIDEOPLAYER_DEBUG_DRAW
|
|
|
|
void VideoPlayer::drawDebugData()
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
|
|
|
|
|
|
|
auto size = getContentSize();
|
|
|
|
|
|
|
|
Point vertices[4]=
|
|
|
|
{
|
|
|
|
Point::ZERO,
|
|
|
|
Point(size.width, 0),
|
|
|
|
Point(size.width, size.height),
|
|
|
|
Point(0, size.height)
|
|
|
|
};
|
|
|
|
|
|
|
|
DrawPrimitives::drawPoly(vertices, 4, true);
|
|
|
|
|
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::play()
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
if (! _videoURL.empty())
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) play];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::pause()
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
if (! _videoURL.empty())
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) pause];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::resume()
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
if (! _videoURL.empty())
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) resume];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::stop()
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
if (! _videoURL.empty())
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) stop];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::seekTo(float sec)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
if (! _videoURL.empty())
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) seekTo:sec];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
bool VideoPlayer::isPlaying() const
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
return _isPlaying;
|
|
|
|
}
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
void VideoPlayer::setVisible(bool visible)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
|
|
|
cocos2d::ui::Widget::setVisible(visible);
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
if (! _videoURL.empty())
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
[((UIVideoViewWrapperIos*)_videoView) setVisible:visible];
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
void VideoPlayer::addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-05-14 11:18:11 +08:00
|
|
|
_eventCallback = callback;
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
|
2014-07-17 21:10:26 +08:00
|
|
|
void VideoPlayer::onPlayEvent(int event)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-07-17 21:44:33 +08:00
|
|
|
if (event == (int)VideoPlayer::EventType::PLAYING) {
|
2014-05-08 18:12:53 +08:00
|
|
|
_isPlaying = true;
|
|
|
|
} else {
|
|
|
|
_isPlaying = false;
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:18:11 +08:00
|
|
|
if (_eventCallback)
|
2014-05-08 18:12:53 +08:00
|
|
|
{
|
2014-07-17 21:10:26 +08:00
|
|
|
_eventCallback(this, (VideoPlayer::EventType)event);
|
2014-05-08 18:12:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:03:46 +08:00
|
|
|
cocos2d::ui::Widget* VideoPlayer::createCloneInstance()
|
|
|
|
{
|
|
|
|
return VideoPlayer::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::copySpecialProperties(Widget *widget)
|
|
|
|
{
|
|
|
|
VideoPlayer* videoPlayer = dynamic_cast<VideoPlayer*>(widget);
|
|
|
|
if (videoPlayer)
|
|
|
|
{
|
|
|
|
_isPlaying = videoPlayer->_isPlaying;
|
|
|
|
_fullScreenEnabled = videoPlayer->_fullScreenEnabled;
|
|
|
|
_fullScreenDirty = videoPlayer->_fullScreenDirty;
|
|
|
|
_videoURL = videoPlayer->_videoURL;
|
|
|
|
_keepAspectRatioEnabled = videoPlayer->_keepAspectRatioEnabled;
|
|
|
|
_videoSource = videoPlayer->_videoSource;
|
|
|
|
_videoPlayerIndex = videoPlayer->_videoPlayerIndex;
|
|
|
|
_eventCallback = videoPlayer->_eventCallback;
|
|
|
|
_videoView = videoPlayer->_videoView;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 18:12:53 +08:00
|
|
|
#endif
|