Game Development Community

iPhone Movie Playback - Here it is.

by Sven Bergström · in iTorque 2D · 10/23/2009 (9:18 pm) · 48 replies

One thing that was always a cool idea was playing cinematics and, intro movies in an iPhone game. Up until now there have been people planning to add it but i had already started so here it is.

Notes

The code is asynchronous - Meaning that the game/other stuff still runs in the background. This is great for loading stuff in the background while the movie is playing :) One thing i will add is that a movieID will be returned, and call the console function for movieDidFinishPlayback(%ID), so that you can time things better.

Todo
make it use ~/ paths.
maybe add datablocks for videos


"Installation"


Step 1 : , you need to add the two files to your project tree.

img190.imageshack.us/img190/1749/vid07.png

img18.imageshack.us/img18/4365/vid08.png


Step 2 : , you need to add the MediaPlayer Framework.

On the target -> Right click -> Get Info
Select the general tab
Make sure you are adding from the iPhoneOS SDK

img14.imageshack.us/img14/3808/vid09.png


Step 3 : , Build and go.

Usage


NO EXTENSION is passed in, m4v is the only one atm, it looks in the bundle based on the file name, starting at / (which is "Resources" in XCode.

Someone asked about it being modal and not dismissable, if you set the controlsMode to hidden or volume only there is no way to dismiss the movie (meaning you can force them to watch it). The other thing i will add is the callback for handling when they are attempting to dismiss the video from modal mode as well - So that you can perhaps show another loading screen if your background loading is not complete.

There is only one function needed. The scalemode and controlMode are from the OS :

For scaling - None, Aspect Fit, Aspect Fill, Fill
For controls - Default controls, Volume Only, Hidden

Code side :
//If you going to code it, just look at the parameters in the code :)
#include "platformiPhone/iPhoneMoviePlayback.h"

playMovie(...);

Script Side

//You will have to use numbers or constants here for now
playiPhoneMovie( %filename, %scaleMode, %controlMode );

Creating a movie for the game


Quite simple , just use iTunes.

Step 1 : ,

Add a video file by opening it in iTunes

img190.imageshack.us/img190/709/vid00.png
Step 2 : ,

Change the view to be this view, so you can see the "Movies" tab on the left, and the items in a list format.

img194.imageshack.us/img194/7697/vid01.png
Step 3 : ,

Right click the video and convert it to iPhone/iPod version


img196.imageshack.us/img196/6153/vid03.png
img196.imageshack.us/img196/3793/vid04.png

Always check the settings!

img8.imageshack.us/img8/1349/vid05.png
Step 4 : ,

Rinse and repeat :)

img18.imageshack.us/img18/528/vid06.png

Downloads


Download
#21
10/27/2009 (7:34 pm)
yes, I thought it would require some additional iPhone magic. and I really don't think it's that important.
What are you using the video for? I'm just using it to cross advertise my other games so this solution is perfect as is.
#22
10/27/2009 (7:35 pm)
We're using it for cut scenes in one game, and to display music videos that the player has earned in the Shinobi Ninja game.
#23
10/28/2009 (5:29 am)
Thats cool, Dave. and i do believe there is no "my thread" mentality in the context of community ;) Also the script callback was an idea, but i had not implemented it just yet. Feel free to add/change it and post an update and ill edit the first post to reflect.

@Eyal : the idea is intriguing, and actually it would not be hard to achieve at all. Its not a priority and it would add the need for actual iPhone programming on the users end (unless it was something super generic)
#24
10/28/2009 (8:11 am)
Yeah, there is a thread starter, but after that it's all sharing with the group :)
#25
11/03/2009 (5:49 pm)
I just realized that after I play a movie. I completely loose sound for my game. Do you guys have the same problem?
#26
11/03/2009 (5:55 pm)
This is a bug in the TGB implementation of the iPhone sound APIs. We fixed it on our end.... Lemme see if I can track down the fix in our codebase and I'll share it your way.
#27
11/11/2009 (6:08 pm)
Dave, have you found the fix for that problem. Now I'm having the same issue when I display a rich media ad via Greystripe.
#28
12/03/2009 (5:56 am)
any idea how to check when the video is finished or skipped?

when my game will play the video I hear the music background of my main menu!!!!
#29
02/18/2010 (4:25 pm)
I'm having a hard time hiding the controls. I just want to play an mpeg4 movie as the intro to my game, then go to the main menu. I can't figure out how to hide the play/pause, volume etc. and all that stuff. I just want to play the animation and then click once to go to main menu.

Any help greatly appreciated! )
#30
02/23/2010 (12:06 pm)
Ok, need to ask to make the magic.

I did convert my video. Include it in my game/data/videos folder.

load a level and script:

function mylevel::onLevelLoaded(%this){
%filename = "game/data/videos/myIntroVideo.mp4";
%scaleMode = 0;
%controlMode = 0;
playiPhoneMovie(%filename,%scalemode,%controlmode);
}

but the level is loaded and nothing happens... will somebody be more specific on how to play movies withing iTGB?

Thanks in advance
#31
02/23/2010 (12:08 pm)
console says "unable to find funcion playIphoneMovie".???
#32
02/23/2010 (12:18 pm)
playiPhoneMovie

I can see a case difference there, is it something like that?
#33
02/23/2010 (12:24 pm)
A case issue from script? really?!
#34
02/23/2010 (5:29 pm)
@Sven, sorry I can´t see the case difference... what will the problem be?

playiPhoneMovie(%filename,%scalemode,%controlmode);
playiPhoneMovie

should be this?:
playiPhoneMovie( %filename, %scaleMode, %controlMode );
Thanks
#35
02/23/2010 (5:45 pm)
Isaac, I don't think your filename is correct... that says .mp4 but I believe that the iPhone will only load M4V (anyone who knows otherwise feel free to prove me wrong as I'm not certain on this fact).

Also, your filename isn't getting parsed with the "'s, which could be causing a problem. Once you are certain your video will play on your iPhone (by importing it to your device via iTunes and testing it through iTunes on the device) Try this:

function mylevel::onLevelLoaded(%this){
   %filename = ""game/data/videos/myIntroVideo.mp4"";
   %scaleMode = 0;
   %controlMode = 0;
   playiPhoneMovie(%filename,%scalemode,%controlmode);
}
#36
02/23/2010 (7:05 pm)
if you put that in you could just as well skip the "" as they negate themself right away.

the problem is more that the path includes mp4, while at least the original contribution added the mp4 itself and expected the path + filename without extension
#37
02/24/2010 (12:03 am)
Oh, i see now. The others are correct, the player only supports m4v (the normal video format from iTunes) and the player assumes this.

In fact, its the first line in the Usage section above.

Quote:
Usage

NO EXTENSION is passed in, m4v is the only one atm.
#38
02/24/2010 (11:14 am)
Thanks.

So, the other problem is that I can´t import an mpeg-4 video to itunes so I can convert it to the iPhone format... I have used an external converter to convert to mp4. Why is not possible to import MPEG-4 to iTunes? Is there a trick? Am I missing something?

I will try to play the m4v... is I found how to convert to this format ;)

Thanks guys
#39
02/24/2010 (12:05 pm)
solved: I can convert to m4v using iMovie :)

unsolved: I can´t yet play the movie into the iPod :(
#40
02/24/2010 (12:10 pm)
did you try the movie on the regular iphone movie player by adding it to the movies? potentially you just didn't use the right format -> unsupported