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?
Related
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.
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];
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.
I get twice notification on keyboard down and once on keyboard up…
In my class I put notifications for keyboard:
-(id)init… {
…
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
…
}
to do frame adjustment on keyboard slide.
Later during the class work I use 'ABPeoplePickerNavigationController' to select address.
…
ABPeoplePickerNavigationController *userPicker=[[ABPeoplePickerNavigationController alloc] init];
…
[viewController presentModalViewController:userPicker animated:YES];
…
I’ve found that on ‘presentModalViewController’ I get twice ‘UIKeyboardWillHideNotification’ , BUT once ‘UIKeyboardWillShowNotification’ – when the picker goes out.
Pretty strange.
I tried to remove observer for ‘UIKeyboardWillHideNotification’ from the class initialization (to find any double observer declarations). However, after this remove no ‘UIKeyboardWillHideNotification’ notifications at all.
Why I get different amount of notifications on keyboard up and down?
May be I do something wrong?
Thanks.
It is quite common (especially with the *WillDoSomething message) to receive a notification twice though you expected just once.
What you could do to fix the problem is to have a boolean somewhere which stores the state of the UI. For instance, if keyboardUp is false would mean that you already move the UI to the default state.
The code below is more or less taken from the example MPMoviePlayerController sample code. In an app I wrote last year, it used to play videos fullscreen without an issue. Since iOS 4.0, there's just audio in the background. It's like the movie player doesn't have a view or the view is behind my app. I can still interact with my app, even 'start' a new video (audio only).
It's like the movie player now needs a view, but I don't see any way of supplying this in the API or the sample code (which does seem to be a version or two behind.
I load my videos from a URL and if I type these into Safari, they play just fine.
Here's the relevant code fragments, for what it's worth:
- (void)playMovieUrl:(NSURL*)url
delegate:(id)delegate
callbackSelector:(SEL)selector
{
#try {
movieFinishedCallbackDelegate = delegate;
movieFinishedCallbackSelector = selector;
movieURL = url;
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie play];
}
#catch (NSException * e) {
return;
}
}
// When the movie is done,release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie release];
[movieURL release];
[movieFinishedCallbackDelegate performSelector:movieFinishedCallbackSelector];
}
You probably need to present theMovie:
[self presentMoviePlayerViewControllerAnimated:theMovie];
And change to:
MPMoviePlayerViewController
in ios 3.2 letter use MPMoviePlayerViewController. it behave like a modelViewcontroller