My game crashes right after a movie plays, i have tried everything I can think of. Is anyone else having this issue? Is there a fix?
Thanks,
My game crashes right after a movie plays, i have tried everything I can think of. Is anyone else having this issue? Is there a fix?
Thanks,
Does this happen everywhere you try to play a movie or just one particular place or one project? Is there any more detail you can give about what is happening in the game when the movie starts and finishes?
It seems to crash right after the movie stops playing, right as it loads the next scene. I have two movies in my game. Using unity 1.7 and SDK 3.X I everything worked great. Here is the setup for Unity 1.7 and SDK 3.X for both movies:
Regular game scene / empty pre movie scene / movie scene / empty post movie scene / regular game scene.
I added empty movie scenes because I was getting memory warnings when I played the game without them.
As soon as I got SDK 4, this no longer worked.
The first movie I had to take out both empty movie scenes, so this is the setup for that:
Regular game scene with added movie / regular game scene
I guess SDK 4 doesn’t like empty scenes with nothing more then a script to load the next scene.
This unfortunately is not working on the second movie scene. I’m still trying some things, I hope to have it working soon.
We ran into this issue too, eventually we just said screw it and ran our own movie player in Xcode. It’s a lot nicer too, instead of having the movie touch to cancel we have a movie controller that allows the user to fast forward, rewind or even expand the window to fill the screen.
Cool, can you provide any instructions on how to accomplish this in xcode? I have very limited knowledge of xCode. I have only programmed in Unity.
Thanks,
JL
The thing about SDK 4 is that they radically changed the MediaPlayer framework. In SDK 3.2 and above you had to make a viewing window and put your movie on that view. You then had to rotate the movie as necessary to get the movie to play in the rotation you wanted.
First you want a variable to transfer message between Unity and iPhone. So in the AppController.h you want to set a define:
AppController.h:
#define UM_INCOMING_MESSAGE @“UM_Message”
You’ll also want to variables for MoviePlayerController and the UIView:
MPMoviePlayerController* movieVC;
UIView* movieView;
You’ll then want to make Xcode check that variable every x amount of seconds. In the AppController.mm you’ll want to run a function that runs itself every x amount of seconds.
AppController.mm:
The function should look something like this in the AppController.mm:
-(void)CheckForUnityMessage()
{
NSString *filename = [[NSUserDefaults standardUserDefaults] stringForKey:UM_INCOMING_MESSAGE];
if(filename)
{
NSString *moviePath = [bundle pathForResource:filename ofType:@“m4v” inDirectory:@“Data/Raw”];
NSURL * movieURL;
if (moviePath)
{
movieURL = [NSURL fileURLWithPath:moviePath];
[movieURL retain];
}
movieVC = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
movieView = [movieVC view];
// size of the view window
[movieView setFrame: CGRectMake(0, 0, 480, 320)];
CGAffineTransform landscapeTransform;
// rotate the view window 90 degrees to landscape left
landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
// translate the view so that the origin of the view is at 0,0
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
// set transformations to the view
[movieView setTransform: landscapeTransform];
movieVC.scalingMode = MPMovieScalingModeAspectFit;
movieVC.fullscreen = TRUE;
movieVC.controlStyle = MPMovieControlStyleFullscreen;
movieVC.shouldAutoplay = TRUE;
[[[UIApplication sharedApplication] keyWindow] addSubview: movieView];
UnitySetAudioSessionActive(false);
UnityPause(YES);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// Run the same function in 1 second
[NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(CheckForUnityMessage) userInfo: nil repeats: NO];
}
}
You’ll also want this function for when the movie is done playing so that the game unpauses:
[movieVC stop];
// free the memory
if (movieVC) {
[movieVC release];
movieVC = nil;
}
[[NSNotificationCenter defaultCenter] removeObserver: self name: MPMoviePlayerPlaybackDidFinishNotification object: nil];
//[[NSUserDefaults standardUserDefaults] setObject:@“NO” forKey:@“MoviePlaying”];
// unpause unity since we’re done playing the movie
UnitySetAudioSessionActive(true);
UnityPause(NO);
[movieView removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
}
Now you just add the MediaPlayerFramework under the Frameworks folder by right clicking the Frameworks Folder → Add → Existing Frameworks
Also remember to include the Mediapayer into the header of the AppController via:
#import <MediaPlayer/MediaPlayer.h>
You’ll also need QuartzCore to do rotations:
#import <QuartzCore/QuartzCore.h>
Now all you need to do in Unity is set the variable that Xcode is checking for to the filename of your movie. For example:
PlayerPrefs.SetString(“UM_Message”, “theNameOfMyMovie”);
Check the console of the device to see if you’re receiving memory warnings.
There’s a good chance the OS is killing you for taking too much memory (caused by loading Unity stuff right after playing a movie).
Same issue.
I tried loading 2 empty scenes, but still does not work. Also, once in awhile when i load a new scene (not a movie, just a normal scene), a quick pink screen pops up then it crashes. I think Unity 1.7 and SDK 4 have issues playing nice.
Everything worked great with Unity 1.7 and SDK 3.X, but SDK 4 is killing my app. I’m having a lot os issues.
Hi!
I was trying to play two different movies, and I’m always getting a SIGSEGV crash in Xcode, when running the game on the device.
I play the first movie in the first loaded Unity scene, with
iPhoneUtils.PlayMovie(“Logos.m4v”, Color.black, iPhoneMovieControlMode.CancelOnTouch);
and after two more loaded scenes, I play another movie:
iPhoneUtils.PlayMovie(“Logos.m4v”, Color.black, iPhoneMovieControlMode.CancelOnTouch);
The crash occurs after the second movie stops playing (when resuming to Unity).
Even if I play the same movie file again, it still crashes.
I’ve tested this with a total app memory of 22MB, and also at 15MB, and it still crashes.
This is all on OS4.
If you have any idea how to fix this, I’d be really grateful
Thanks a lot,
Bogdan
Hi!
I was trying to play two different movies, and I’m always getting a SIGSEGV crash in Xcode, when running the game on the device.
I play the first movie in the first loaded Unity scene, with
iPhoneUtils.PlayMovie(“Logos.m4v”, Color.black, iPhoneMovieControlMode.CancelOnTouch);and after two more loaded scenes, I play another movie:
iPhoneUtils.PlayMovie(“Logos.m4v”, Color.black, iPhoneMovieControlMode.CancelOnTouch);The crash occurs after the second movie stops playing (when resuming to Unity).
Even if I play the same movie file again, it still crashes.
I’ve tested this with a total app memory of 22MB, and also at 15MB, and it still crashes.This is all on OS4.
If you have any idea how to fix this, I’d be really grateful
Thanks a lot,
Bogdan
Same thing happens to me with iOS 4. I have not found a fix yet
I’ll try writing our own movie player in Objective-C.
So far, no luck, as I’m a total Obj-C beginner.
I’ve tried using xcodeusa’s code, but it throws a few errors.
If anybody has some code for that, which also works on iOS4, and hopefully can be called by an extern ‘C’ function, please share it with us
Thanks a lot!
Bogdan
I submitted a bug report, I encourage everyone with this issue do the same.
same issue here. i have a intro.mov play at startup then loads a game scene after. no problem yet. after the game scene it plays a movie which crashes right after the movie ends. And same as your problem this worked great before OS4. so far os4 has been a major pain. i love apple.
has anybody found a solution to this?
Has anybody found a solution to this?..
3.2 can’t get it.too.
ps:using Unity3.2
with unity iphone 1.x your only solution is to create your own objc based plugin to use.
Unity iphone 1.x does not support iOS4 so all kind of iOS anomalies are to be expected as apple changed a plentitude of things