iPhone Movie Playback - Here it is.
by Sven Bergström · in Torque 2D for the iPhone · 10/24/2009 (4:18 am) · 27 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
Step 1 : , you need to add the two files to your project tree.


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

Step 3 : , Build and go.
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 :
Script Side
Quite simple , just use iTunes.
Step 1 : ,
Add a video file by opening it in iTunes

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.

Step 3 : ,
Right click the video and convert it to iPhone/iPod version


Always check the settings!

Step 4 : ,
Rinse and repeat :)

Download
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.


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

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

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.

Step 3 : ,
Right click the video and convert it to iPhone/iPod version


Always check the settings!

Step 4 : ,
Rinse and repeat :)

Downloads
Download
#22
10/28/2009 (2:35 am)
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
@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)
10/28/2009 (12:29 pm)
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 (3:11 pm)
Yeah, there is a thread starter, but after that it's all sharing with the group :)
#25
11/04/2009 (1:49 am)
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/04/2009 (1:55 am)
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/12/2009 (2:08 am)
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.
Torque Owner Eyal Erez
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.