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
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
#42
u32 instruction = code[ip++]
no idea what´s wrong.
Still being a newbie on several stuff :(
02/24/2010 (12:15 pm)
now got an "EXC_BAD_ACCESS"...:u32 instruction = code[ip++]
no idea what´s wrong.
Still being a newbie on several stuff :(
#43
02/24/2010 (12:19 pm)
thanks guys, I did the conversion, but now the problem is the Exec Bad Access :(
#44
My solution is nothing elegant: I did my level using 1.2 beta and then I´ve imported the game folder to my 1.3.1 game folder and that did the trick. I can play now videos.
But now, I´ve searched and there is no, or I can´t figure where it is this information: How do you pause a video through code (if possible) and how do you skill and how do you call when the video was finished. Is there something like onVideoFinished() or something?
Thanks in advance
Isaac
02/25/2010 (2:22 pm)
Well, I was unable to run the video using 1.3.1 no matter if I read or not the documentation... it seems that I´m stupid enough to be unable to understand the new datablocks stuff. I´ve tried reading carefully but not, I still having an empty level. My solution is nothing elegant: I did my level using 1.2 beta and then I´ve imported the game folder to my 1.3.1 game folder and that did the trick. I can play now videos.
But now, I´ve searched and there is no, or I can´t figure where it is this information: How do you pause a video through code (if possible) and how do you skill and how do you call when the video was finished. Is there something like onVideoFinished() or something?
Thanks in advance
Isaac
#45
03/17/2010 (1:02 pm)
The solution works great, but as issac im trying to find how to find out when the video finish. If there a event like onFinishVideo() would be great. has someone did this?
#46
Hi, I think you´re the guy I need to ask again: is there a way to do something once the video has been played or when the user decides to quit it? Is there a way to force the player to watch the video?
I know you may be busy working on other stuff, but this is very important for me so I can start working with a project. Otherwise I must stop working since I´m in the newbies side.
Thanks in advance man!
03/18/2010 (4:34 pm)
@Sven,Hi, I think you´re the guy I need to ask again: is there a way to do something once the video has been played or when the user decides to quit it? Is there a way to force the player to watch the video?
I know you may be busy working on other stuff, but this is very important for me so I can start working with a project. Otherwise I must stop working since I´m in the newbies side.
Thanks in advance man!
#48
working in SDK 4.0!
09/11/2010 (10:52 am)
http://www.torquepowered.com/community/forums/viewthread/120465working in SDK 4.0!
Associate Dave Calabrese
Cerulean Games