MPMoviePlayerLoadStateDidChangeNotification works in iOS 5 but not in iOS 6 - objective-c

I want to play a video with an MPMoviePlayerViewController. So in my view controller I register as an observer for MPMoviePlayerLoadStateDidChangeNotification.
I then initialise the MPMoviePlayerViewController:
self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"<videoURL>"]];
and wait for the notification to arrive. When it does I execute this code:
MPMoviePlayerController* playerController = notification.object;
if ([playerController loadState] & MPMovieLoadStatePlayable) {
if (self.mPlayerVC) {
[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
}
}
Anyone an idea why this works for iOS 5 but not for iOS 6? Thanks

There seems to be a bug in iOS 6' MediaPlayer.framework. To get the video to play I call prepareToPlay after initialising the MPMoviePlayerViewController
self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"<videoURL>"]];
[self.mPlayerVC.moviePlayer prepareToPlay];
Now the notifications come in again but the app crashes when I call [self presentMoviePlayerViewControllerAnimated:self.mPlayerVC]; in the method that is called for the MPMoviePlayerLoadStateDidChangeNotification.
To prevent the crash replace
[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
with something like
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)]) {
[self presentViewController:self.mPlayerVC animated:YES completion:nil];
}
else if ([self respondsToSelector:#selector(presentModalViewController:animated:)]) {
[self presentModalViewController:self.mPlayerVC animated:YES];
}

Related

Change AVPlayer Video MacOS Objective-C Cocoa

For MacOS, not iOS. I am playing a video in an AVPlayerView in an XIB. Just experimenting with video playback. I would like to be able to choose a selection from the File Menu (For instance File / Videos / Video 1, Video2, Video3, etc) and change the currently playing video in the XIB when I select the menu item.
Currently I am using this to play a video:
- (void)windowDidChangeOcclusionState:(NSNotification *)notification
{
if (self.window.occlusionState & NSWindowOcclusionStateVisible)
{
loopPlayer = YES;
[_aspectView setAspectRatio:NSMakeSize(16, 9)];
NSBundle *mb = [NSBundle mainBundle];
NSURL *demoURL = [mb URLForResource:#"Video1" withExtension:#"mp4"];
player = [[AVPlayer alloc] initWithURL:demoURL];
self.playerView.player = player;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:#selector(movieEndDetected:)
name:#"AVPlayerItemDidPlayToEndTimeNotification"
object:player.currentItem];
[player play];
}
else
{
[player pause];
[player seekToTime:kCMTimeZero];
}
}
and to loop the video playing:
- (void) movieEndDetected:(NSNotification *) note
{
if (loopPlayer) {
[player seekToTime:kCMTimeZero];
[player play];
}
}
But I would like to change the playing video in the XIB on the fly by choosing a menu button. Any ideas how this can be done? I have heard of AVPlayerQueue maybe working for this kind of thing, but I am very new and can't get it working on MacOS.
My solution was to use many avplayer views in xibs and when one was open from a menu item, close another.
- (void)Visual02Menu:(id)sender {
if (!visual02Window) {
visual02Window = [[Visual02 alloc] initWithWindowNibName:#"Visual02"]; }
[visual01Window close];
[visual02Window showWindow:self];

nav bar nonresponsive after UIImagePickerController dismissed

On iOS 7 only, the navigation bar in my app does not respond to any touches after a UIImagePickerController is used and then dismissed (whether a pic has been selected or not). The screen below the navigation bar functions as normal, but it is now impossible to navigate Back in the app; the user is stuck on this screen.
I am launching the UIImagePickerController from code, though the rest of the app is laid out in storyboards.
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
mediaUI.mediaTypes = [NSArray arrayWithObject:(NSString *) kUTTypeImage];
mediaUI.allowsEditing = NO;
mediaUI.delegate = self;
[controller presentModalViewController: mediaUI animated: YES];
Thanks in advance for any help.
I hope you are performing these steps correctly!
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
And when you are calling
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
Cheers!
I noticed that the log was showing "Unbalanced calls to begin/end appearance transitions for" the launching controller. I was launching the image picker controller immediately from another controller when it appeared. This works OK on iOS 8 but there needs to be a delay on iOS 7. I fixed it by calling my method after a brief delay:
[self performSelector:#selector(takePicture) withObject:nil afterDelay:.1];

Bugged Game Center Matchmaker appearance

I am developing multiplayer for my game and I have encountered following issue
I am using Cocos 2d 2.1 , iOS 6 and following code to show matchmaker (Landscape orientation)
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:4 viewController:[app navController] delegate:self];
And thats how it appears
Following code is used for that function
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
viewController:(UIViewController *)viewController
delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
GKMatchmakerViewController *mmvc =
[[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
}
is this code in HelloWorldLayer? if so is that the first layer that the director calls? I have the same problem but it's fixes if I follow strictly the cocos2d template that was created for me. Meaning that I use the IntroLayer as the initial layer and from there it transitions into the HelloWorldLayer where I have the game center code. I think it has something to do with the director being loaded too late but I'm not sure
This happens when you try to push on a UIViewController, but you only have a UIView in your app, and no UIViewController. Let me guess, you do not have a rootViewController.
If you are working from the EAGLView template, you must declare a UIViewController for the UIView. This can be as simple as,
- (void) applicationDidFinishLaunching:(UIApplication *)application
{
window.rootViewController = [[UIViewController alloc] init];
window.rootViewController.view = glView; // MUST SET THIS UP,
// NOW THE EAGLView HAS A UIViewController.
[glView startAnimation];
}
Then, anytime you want to push on one of those GameKit UIViewControllers, use the presentViewController method of your Window object's rootViewController
For example:
[self.window.rootViewController presentViewController:vc animated:TRUE completion:^(void){puts("DONE");} ] ;
The bugginess will go away and the window will be correctly formed.

Cancel button does not dismiss ComposeMail window in iOS simulator

My implementation is pretty simple:
In the .h file, I'm implementing MFMailComposeViewControllerDelegate
And in the .m file, I have the following bit of code:
-(void)MailCurrentViewAsAttachment
{
if ( [MFMailComposeViewController canSendMail] ) {
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.delegate = self;
[mailComposer addAttachmentData:imageData mimeType:#"image/jpeg" fileName:#"attachment.jpg"];
[self presentViewController:mailComposer animated:YES completion:nil];
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
The variable imageData above is of the UIImage type, and I know for sure there's nothing wrong with it: the required image shows up properly in the compose mail window.
However clicking the Cancel button does not dismiss the Compose window. What am I missing?
Note: I'm using iOS 6 with the latest version of xcode, and my app is a Universal app.
You are setting the wrong delegate. You want:
mailComposer.mailComposeDelegate = self;
MFMailComposeViewController extends UINavigationController. So setting delegate is for the UINavigationControllerDelegate.

MFMessageComposeViewController doesn't do anything in my iPhone 4.x, why?

I just upgraded to xcode 4.0.2, my iPhone is 4.3.5 and the MFMessageComposeViewController doesn't do anything. It doesn't say "Can't send an SMS", it doesn't crash or abort, but it doesn't open the dialog to send the message either. It simply does nothing.
-(void)sendSMS:(NSString *)message recipientList:(NSArray *)recipients
{
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *controller =
[[[MFMessageComposeViewController alloc] init] autorelease];
if (controller != nil) {
controller.messageComposeDelegate = self;
controller.body = message;
controller.recipients = recipients;
[self presentModalViewController:controller animated:YES];
// [controller release]; // If I really did this it would crash.
}
}
}
OK I finally answered my own question. Now I want no one else to have to go through this.
I was calling this method from just an NSObject. It was a delegate to MFMessageComposeViewControllerDelegate but that made no difference. I had to move this method to my MainViewController, then it worked.