I'd like to play a 5 second video clip when my cocos2d game loads. What is the best way to do this? It looks like CocosDenshion doesn't support video and MPMoviePlayerController is 3.0 only. I'd also like my app to be 2.2.1 compatible as well as 3.0. If anyone can just point me in the right direction, I'd really appreciate it!
playing a short video clip when app loads
(13 posts) (9 voices)-
Posted 2 years ago #
-
If I am not mistaken, AVFoundation class supports video playback and it's available since 2.2 Check it out I think it fits your needs.
Posted 2 years ago # -
If you are going to play a video, allow the user to tap out of it and get to the game as quickly as possible. As a person who uses the iPhone to play games whenever I have a free moment, I want to be able to get into the game as quickly as possible and play for whatever time I have.
The games that require a longer (5-10 second) loading time only get played when I have more than 10 minutes to play a game. In those cases, I know I can't do anything about it as the Dev is making sure that there's no stopping while I'm actually playing the game and I appreciate that. So the wait is going to actually have a meaning later on.
A video, on the other hand, is just a time waste as far as I'm concerned, I've actually stopped playing certain games that take too long to load. I'd prefer to in and out as quickly as possible..
My $0.02..
Regards
Posted 2 years ago # -
Where did you get the information that MPMoviePlayerController is 3.0 only? I think you'll find it is in 2.2.1.
Posted 2 years ago # -
I got it working now. I first had to add #import <MediaPlayer/MediaPlayer.h> to the headers.
Then, I had to add existing framework manually from the following folder: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/library/Frameworks
To answer Cypher, my game will generally take 5-15 minutes to play, so a 5 seconds intro video shouldn't be a big deal, however I'll add an option in the game to skip it.
Thanks everyone for your help!
Posted 2 years ago # -
@chuck: you should add an easy way to skip the video: the first time, 5 seconds is not that big deal, but the next time, and the following 10 times it's going to be boring and the user will want to skip it.
As @cypher says, videos are good, but usually people watches them only once.Posted 2 years ago # -
i want to play small video using Cocos2d. so can anyone help me for that? Should i use CCSprite and put it on layer or i shoud use view controller subclass in cocos2d and add video by creating nib file?
Posted 1 year ago # -
Cocos2d leaves playing video up to apple, do a search in the forum for MPMoviePlayerController. e.g
http://www.cocos2d-iphone.org/forum/topic/9554#post-54982
If you're wanting the user to be able to play their own audio the video will interrupt it.
Posted 1 year ago # -
thanks for replying..... i want to play video on single tap by user... i have checked this link but i am not getting where to add video,.. how to declare and initialize it in cocos2d...
Posted 1 year ago # -
I also want to play a short video after the splash screen. When the splashscreen disappears I get a black screen for about 2 secs. Any solutions for this?
I wrote this in the appDelegate:
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"test6" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[viewController.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.controlStyle = MPMovieControlStyleNone;[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];[moviePlayerController play];
Posted 4 months ago # -
You need to preload the movie before playing it to get rid of the flash. Have a look at the newest version of CCVideoPlayer (part of the cocos2d iphone extensions), I modified the code to use preloading instead of direct playing.
So either look up the "prepareToPlay" method of MPMoviePlayerController or use CCVideoPlayer.
Posted 4 months ago # -
Hi Hactor,
Thanks for your response. The thing is, where do I do this? The video needs to play after the splashscreen. Right now I got my code in the appDelegate. So where do I need to prepare the player to play?
Posted 4 months ago # -
You need to prepare to play in the app delegate, but dont add its view to the screen yet. Then once you get the notification back that the movie is ready to play add the view to the screen and play the movie. Below is some of the code I use in Zen Wars.
On Launch:
if ([theMovie respondsToSelector:@selector(prepareToPlay)]) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preparedToPlayerCallback:) name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification object:theMovie]; [theMovie prepareToPlay]; }Then when you get the notification
-(void)preparedToPlayerCallback:(NSNotification*)aNotification { MPMoviePlayerController* theMovie = [aNotification object]; if (theMovie.isPreparedToPlay) { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification object:theMovie]; [self setupViewAndPlay]; } }Again have a look at CCVideoPlayer for details.
Posted 4 months ago #
Reply
You must log in to post.