iPhone/iPad: animated splash screen? - iphone

I want to create an animated logo that serves as the splash screen for my iphone/ipad app.
I'm thinking of showing the default.png, which then transitions to an .mp4 (where the first frame of the .mp4 matches the default.png), plays a 3 second movie, fades out, and loads my application.
Does anyone have any experience with this? And is my idea (using .mp4) the best way to achieve this? Also, is Apple "cool" with this?
Thanks in advance.

Yes you can absolutely do this and yes Apple is cool with it.
You could use MPMoviePlayerController, place it under a UIImageView with the launch image and when the movie is loaded and ready to go remove the UIImageView and play the movie.
But given the sometimes finicky nature of MPMoviePlayerController you need to time things carefully. Here's a snippet you can use as a starting point:
-(void)setupMovie {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification object:self.playerView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playMovie:)
name:MPMoviePlayerLoadStateDidChangeNotification object:self.playerView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showMovie:)
name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.playerView];
[self.playerView setContentURL:[[NSBundle mainBundle] URLForResource:#"movie" withExtension:#"mov"]];
[self.playerView prepareToPlay];
}
-(void)playMovie:(NSNotification *)notification {
if (self.playerView.loadState == MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:notification.object];
[self.playerView play];
}
}
-(void)showMovie:(NSNotification *)notification {
if (self.playerView.playbackState == 1) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:notification.object];
// should update this to new UIView anim methods
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.2];
self.splashScreen.alpha = 0;
[UIView commitAnimations];
}
}

I think that a tutorial like this one can be helpful: http://www.youtube.com/watch?v=wCsumlHiEc0&feature=channel_video_title

Respond to the UIApplicationDidFinishLaunchingNotification. I agree with #jhocking that you should consider whether such a wait is the best UX, but if it is, it's a pretty straightforward task.

Related

iOS7 issue on Playing mov file in MPMoviePlayerViewController

I was able to play .mov file using following coding in ios 6.1.3 and below but in iOS7 it closed automatically.
MPMoviePlayerViewController *mp1 = [[ MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
if (mp1)
{
self.moviePlayer= mp1;
[mp1 release];
self.moviePlayer.view.userInteractionEnabled=YES;
self.moviePlayer.moviePlayer.repeatMode = MPMovieRepeatModeOne;
self.moviePlayer.view.frame = CGRectMake(0, 0, 320, 460);
[self.moviePlayer.moviePlayer setScalingMode:MPMovieScalingModeAspectFit];
self.moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleDefault;
//Register for the playback finished notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieFinishedCallback:) name:MPMoviePlayerDidExitFullscreenNotification object:self.moviePlayer.moviePlayer];
//setup device rotation notification observer
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[self.masterVC presentMoviePlayerViewControllerAnimated:moviePlayer];
[self.moviePlayer.moviePlayer prepareToPlay];
[self.moviePlayer.moviePlayer play];
[self.moviePlayer.moviePlayer setFullscreen:TRUE];
}
Using above coding I can able to play .mp4 file in iOS7 and all. Does apple restricted mov files?
I may be having the same issue as you. If you look at your logs, do you get the following error:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
The only other idea I have is to use a new class such as AVPlayer or even a third party class to play my media. I don't see any settings that are incorrect in your code nor my code. It is iOS 7 related though.

How to play another video in the same MPMoviePlayerController?

*I'm creating an iPhone app where we can watch videos...
I,ve been making my own controls so I want to implement the next, back buttons, I can show theme so for the UI everything is ok the problem is to restart the MoviePlayer with another content...
Any idea???
I could use the same configuration when the playback did finish, I mean... If the video ends playing to start playing another one...
I've tried to set contentUrl but it trows an exception:
2012-04-17 11:37:41.198 NexTest2[8218:11f03] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 11.5]'
viewController.m
- (void)viewDidLoad{
[super viewDidLoad];
fileURL = [NSURL URLWithString:urlString];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[moviePlayerController setShouldAutoplay:YES];
[self addObservers];
/* Inset the movie frame in the parent view frame. */
CGRect viewInsetRect = CGRectInset ([self.view bounds],0.0, 0.0 );
[[moviePlayerController view] setFrame: viewInsetRect ];
[self.view addSubview:moviePlayerController.view];
[self resizeControlViews];
}
then in resizeControlViews I have this, cause I'm using these two views like controls:
-(void)resizeControlViews{
CGRect barFrame = self.controlBarView.frame;
barFrame.origin.x = round((moviePlayerController.view.frame.size.width - barFrame.size.width) / 2.0);
barFrame.origin.y = round((moviePlayerController.view.frame.size.height - barFrame.size.height)/10.0);
self.controlBarView.frame = barFrame;
[moviePlayerController.view addSubview:controlBarView];
CGRect playFrame = self.controlPlaybackView.frame;
playFrame.origin.x = round((moviePlayerController.view.frame.size.width - playFrame.size.width) / 2.0);
playFrame.origin.y = round((moviePlayerController.view.frame.size.height - playFrame.size.height)/1.1);
self.controlPlaybackView.frame = playFrame;
[moviePlayerController.view addSubview:controlPlaybackView];
}
Here everything is working fine, in one of these views there is a slider who controls the seeking, and in the other one are the play, next and back buttons.
I think maybe the problem is whit the UI components of these views...
I've added these observers to control the playback:
//Add the observers to the player
-(void)addObservers{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackStarted:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(setDurationLabel:) name:MPMovieDurationAvailableNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyWindowChanged:) name:UIWindowDidBecomeKeyNotification object:nil];
}
so to handle when the player is playing I use the MPMoviePlayerPlaybackStateDidChangeNotification with this selector:
//called when the playback state changes of state
- (void)playbackStarted:(NSNotification*)notification {
MPMoviePlayerController *player = notification.object;
if (player.playbackState == MPMoviePlaybackStatePlaying) {
[self timerRunning];
}
}
and if the player is "playing" I monitor it with this method:
-(void)timerRunning{
self.currentTime.text = [self floatToStringTime:(moviePlayerController.currentPlaybackTime)];
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
if (moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {
[self performSelector:#selector(timerRunning) withObject:nil afterDelay:0.5];
}
}
so Maybe here is the issue... but with a single video it works perfectly...
I've four where the mistake is... is while i'm monitoring in the line to set the value to the slider, but I really don't know why, I think it is cause when another video or stoping video it is still executed so the player has not duration or current playback what trows this exception... how could I to solve it... here is the mistake... maybe moving this code to another part...
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
Check your UI related code. You most likely are not properly checking the player status before getting and using content related properties from it.
Well finally it works fine... the setCurrentContentUrl works fine, the problem was my code so I solved it... I just validate that duration was different to 0...
Now I have a player with full custom controls :) cool :)
-(void)timerRunning{
if (moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {
self.currentTime.text = [self floatToStringTime:(moviePlayerController.currentPlaybackTime)];
if (moviePlayerController.duration != 0) {
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
}
[self performSelector:#selector(timerRunning) withObject:nil afterDelay:0.5];
}
}
Thank you anyways

How to apply conditions to play video in full screen and to play in a certain frame

I am playing a video by default in full screen according to this:
Play video by default in full screen
But using this code minimize control is missing.
My exact requirment is that:
As the view will load a video will play by default in full screen and when it will be minimize it should be play in a certain frame.
And when it will end I want to write some code, but What condition will be apply to check to whether the video is finish/end?
Plz help me out.
Thanks.
when ever you alloc your moviePlayer object add bellow notification:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
so when your video will finish playing or you will finish it by done bellow method will be called:
- (void)moviePlayBackDidFinish:(NSNotification*)notification
{
// write your code here
}
You need to register for the notification as below
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieLoaded:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
and then implement the messages as follows:
- (void)movieLoaded:(NSNotification*)notification
- (void)moviePlayBackDidFinish:(NSNotification*)notification
hi use this its work fine
AVAsset *aset=[AVAsset assetWithURL:url];
AVPlayerItem *item=[[AVPlayerItem alloc]initWithAsset:aset];
play=[[AVPlayer alloc]initWithPlayerItem:item];
AVPlayerLayer *layer=[[AVPlayerLayer alloc]init];
layer.player=play;;
layer.frame=CGRectMake(200, 250, 400, 250);
[self.view.layer addSublayer:layer];
[play play];

iPad 3.2 & [MPMoviePlayerController setFullScreen:] not showing up

I have an universal application that plays movies from the internet. It has to support 3.1.x as well as 4.x.
In order to get this to work, I have a branch in the code that detects pre-3.2 devices and utilizes MPMoviePlayerController as it is supposed to work there.
This is how I prepare the player to play the remote movie:
- (void)registerForMovieNotifications {
//for 3.2 devices and above
if ([moviePlayer respondsToSelector:#selector(loadState)]) {
LOG(#"moviePlayer responds to loadState, this is a 3.2+ device");
//register the notification that the movie is ready to play
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didExitFullScreen:)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
LOG(#"preparing moviePlayer...");
[moviePlayer prepareToPlay];
} else {
//for pre-3.2 devices
LOG(#"This is a 3.1.x device");
//register the notification that the movie is ready to play
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
}
//handle when the movie finished
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
- (void)readyPlayer {
if (!moviePlayer) {
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
} else {
[moviePlayer setContentURL:movieURL];
}
[self registerForMovieNotifications];
}
Later on I get this notification, and it sets up the movie player's view, etc.
- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {
LOG(#"3.2/4.x - moviePlayerLoadStateChanged:");
//unless state is unknown, start playback
if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
//remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
//set the frame of the movie player to match
self.view.autoresizesSubviews = YES;
[[moviePlayer view] setFrame:self.view.bounds];
[[moviePlayer view] setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[moviePlayer view] setAutoresizesSubviews:YES];
//add movie player as a subview
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES];
//play the movie
[moviePlayer play];
}
}
And the movie plays. This works perfectly on iPhone 4.2, 4.3, iPad 4.2, 4.3, but it fails on iPad 3.2. The movie plays but all I get is a black screen.
If I remove the [moviePlayer setFullscreen:YES] call I get a visible playing movie in 3.2, however it isn't "fullscreen" and so it doesn't have the Done button and there's no way for me to dismiss the screen.
I'd love some help on what's going on here. Thanks!
I was able to come to an acceptable solution, but I still feel this might be a bug.
If I skip the call to setFullScreen and instead just manually set the controlStyle to MPMovieControlStyleFullScreen then it gives me a view that is mostly correct (the toolbar is about 40 pixels too low).
Then I can get the Done button, which triggers the moviePlayer:didFinishPlaying callback.
So it stinks I now have a smelly if 3.2 branch of logic in my code, but hopefully most people will be on 4.0 anyway.

showing white screen when playing video

Hi
white screen is showing if video is not in supported list. and there is no way user to go back to previous screen(navigation bar too not showing).and
when i initialize the MPMoviePlayerController their retain count is increasing to 4.
here is my code
mMPMovieViewCont=[[MPMoviePlayerViewController alloc]initWithContentURL:theURL];
[theURL release];
theURL=nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieDidFinishForOS4:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self.navigationController presentMoviePlayerViewControllerAnimated:mMPMovieViewCont];
NSLog(#"%d",[mMPMovieViewCont retainCount]); //**here count is 4**
- (void) movieDidFinishForOS4:(NSNotification*)notification {
mMPMovieViewCont.moviePlayer.initialPlaybackTime=-1.0;
[mMPMovieViewCont dismissMoviePlayerViewControllerAnimated];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
NSLog(#"%d",[mMPMovieViewCont retainCount]); //returning 3
[mMPMovieViewCont release];
mMPMovieViewCont = nil;
}
i am using ios4.2
Do not call retainCount. It is useless in production and misleading for debugging.
The retain count is entirely irrelevant to your question, it would seem. I'm not sure I understand exactly what "Hi white screen is showing if video is not in supported list" means, but it sounds like you need to check to see if the video is compatible with the device or on the approved playlist before you start playback?