Can it play video? if it can,please tell me how,thanks.
One year passed and those references return internal error of redmine…
Yet, i really need some good references on playing video from a arbitrary scene. especially for IOS.
This is a bit out of date but should still help:
http://www.gmtdev.com/blog/2011/02/08/playing-a-video-on-iphoneipadipod-under-cocos2d-x/
Here is example of video player on android.
Its not possible to upload to forum, so I added it to file share server.
Hi Milda,
Did u miss the link or something for the example?
Aikq:
No I didnt.
Promlem was, that I cant upload example zip. Its always end wih “413 Request Entity Too Large”.
I already contacted support, but no answer yet. So be please patient.
MG
Milda Genius wrote:
Aikq:
>
No I didnt.
>
Promlem was, that I cant upload example zip. Its always end wih “413 Request Entity Too Large”.
>
I already contacted support, but no answer yet. So be please patient.
>
MG
Oh, I see,
may be, if possible, you can upload it to some file hosting websites, because I think there are many problems occurred with the forum right now.
looking forward to see the solution, and very appreciate for your help
cheers
I added link to video example to my original post.
Thank you for your code Milda,
I will study on it
GavT, thanks for your link! Playing video in AppController is not the most comfortable solution, calling something like
CQVideoPlayer::sharedVideoPlayer()->playVideo(file, extension)
looks much better to me, here’s the code (for iOS only):
CQVideoPlayer.h:
#ifndef __CQVIDEOPLAYER_H__
#define __CQVIDEOPLAYER_H__
#include
#include
USING_NS_CC;
class CQVideoPlayer
{
public:
bool init();
static CQVideoPlayer* sharedVideoPlayer();
~CQVideoPlayer();
void playVideo(const char* strFileName, const char* strExtension);
static void notificationHandler(CFNotificationCenterRef center, void *observer,
CFStringRef name, const void *object, CFDictionaryRef userInfo);
void videoFinishedCallback();
};
#endif // __CQVIDEOPLAYER_H__
CQVideoPlayer.mm
#include "CQVideoPlayer.h"
#import
static CQVideoPlayer *pSharedVideoPlayer = NULL;
// Keep these pointers to shut everything down in the end
MPMoviePlayerViewController *playerViewController;
MPMoviePlayerController *player;
UIWindow *window;
CQVideoPlayer* CQVideoPlayer::sharedVideoPlayer()
{
if (! pSharedVideoPlayer)
{
pSharedVideoPlayer = new CQVideoPlayer();
pSharedVideoPlayer->init();
}
return pSharedVideoPlayer;
}
bool CQVideoPlayer::init()
{
// Some black magik to hear objC notifications from C++ class
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, ¬ificationHandler,
(CFStringRef)MPMoviePlayerPlaybackDidFinishNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
return true;
}
void CQVideoPlayer::playVideo(const char* strFileName, const char* strExtension)
{
// Init MPMoviePlayerViewController
NSString *url = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:strFileName] ofType:[NSString stringWithUTF8String:strExtension]];
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
// Same thing we're doing in AppController
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
[window addSubview: playerViewController.view];
[window makeKeyAndVisible];
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
[window addSubview: playerViewController.view];
}
else
{
[window setRootViewController:playerViewController];
}
// Actually start a video
player = [playerViewController moviePlayer];
[player prepareToPlay];
player.scalingMode = MPMovieScalingModeAspectFit;
player.shouldAutoplay = TRUE;
player.controlStyle = MPMovieControlStyleNone;
[player play];
}
// React to notification
void CQVideoPlayer::notificationHandler(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
(static_cast(observer))->videoFinishedCallback();
}
void CQVideoPlayer::videoFinishedCallback()
{
// Hide video
[player.view removeFromSuperview];
[window setHidden:YES];
[window release];
[playerViewController release];
// Post a notification to be able to properly react
CCNotificationCenter::sharedNotificationCenter()->postNotification("VideoPlaybackFinished");
}
CQVideoPlayer::~CQVideoPlayer()
{
// Remove observer in the end
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetLocalCenter(), this);
}
Dividing filename and extension may look a bit strange at the first glance, but video playback implementations for android, win32 etc will surely differ and supported file extensions will differ as well. I’ve tested for leaks and rotations, seems to work fine. Feel free to enhance and comment
how to play video on win32?
Hi I am looking for video playing in Android using Cocos2dx.
Thanks,
V. D.
Victor Komarov wrote:
GavT, thanks for your link! Playing video in AppController is not the most comfortable solution, calling something like
>
[…]
>
looks much better to me, here’s the code (for iOS only):
Victor, can you give some hints how to show subtitles over the video, using your code?
You may use closed captions, but seems like user needs to turn them on at first, another option is to show UILabel above, but thats kinda ugly. Finally you can simply make hardsubs
Victor Komarov wrote:
You may use closed captions, but seems like user needs to turn them on at first, another option is to show UILabel above, but thats kinda ugly. Finally you can simply make hardsubs
I’ve made subtitles with help of UILabel. Now I only need to find out how to stop video if player taps the screen (if player does not like my video :-/)
Latest source codes are in the attachement, this version stops playback after screen is touched and sends corresponding notification
To use player include header
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "CQVideoPlayer.h"
#endif
Set listener method for notification somewhere in init method
CCNotificationCenter *nc = CCNotificationCenter::sharedNotificationCenter();
nc->addObserver(this, callfuncO_selector(CQLayer::onVideoPlaybackFinished), "VideoPlaybackFinished", NULL);
To play video just write
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
CQVideoPlayer::sharedVideoPlayer()->playVideo(videoName, videoExtension);
#endif
Victor Komarov wrote:
Latest source codes are in the attachement, this version stops playback after screen is touched and sends corresponding notification
Many thanks for this!
Please let me know if everything works as it should or if there are any problems