iOS 9 is 'Picture In Picture' mode available with 'Requires Fullscreen' set to YES? - cocoa-touch

I have an app that requires fullscreen, but want to make Picture In Picture feature available when user opens video playback modal controller (My own player written with AVFoundation).
I have 'app requires fullscreen' flag set to YES in settings.
Can I use Picture in Picture mode for video playback while all my app requires to be fullscreen?

I've created a sample project and found that YES, Picture In Picture feature doesn't depend whether your app needs fullscreen or not.
Maybe this would be helpful for those who are looking for the same question as I did.
Set base SDK version to latest (9.0)
Set "App requires fullscreen" flag in the project settings
Set AVAudioSession category to AVAudioSessionCategoryPlayback in application:didFinishLaunchingWithOptions:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
Just created AVPlayerViewController and presented it from my root controller
AVPlayerViewController *moviePlayerController = [[AVPlayerViewController alloc] init];
AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:#"http://127.0.0.1:12345/movie.mp4"]];
moviePlayerController.player = player;
[self presentViewController:moviePlayerController animated:YES completion:nil];
PiP button appeared at the bottom right corner of playback controls and it works!
P.S. I may remove the question and answer if it's obvious or too simple and nobody find it useful.

Related

How to stop AVAudioPlayer once we navigate from one view to into other view in iOS8?

I am fresher to iOS. I am using AVFoundation framework for AVAudioPlayer. This is used for running background sound when user enters into application home screen. This background sound should be stopped when it goes to other views and should be enabled when user come back to the home screen again. Below code is working fine in IOS7, when I upgrade to IOS8 background sound continuously playing and doesn’t stop when I go to other views. Kindly help me in this issue.
I am using below code for start and stop the player
NSString *pewPewPath = [[NSBundle mainBundle]pathForResource:#"background" ofType:#"mp3"];
NSURL *pewPewURL = [NSURL fileURLWithPath:pewPewPath];
NSData *data1 = [NSData dataWithContentsOfURL:pewPewURL];
audio = [[AVAudioPlayer alloc] initWithData:data1 error:nil];
audio.volume=8;
[audio play];
Call the [audio stop]; and set nil to the audio instance when you are navigating to another view. And write this code before you call the next view controller.

iOS7 sending SMS from inside the app has a misaligned modal view

I'm writing an app where I need to allow the user sending SMS from within the app.
It works fine on iOS6 but not on iOS7.
When I'm trying to send a text message, the modal view appears but there is a strange gap between the "to" field and the list of possible contacts.
After selecting the first contact, the "to" field slides up and disappears and then I see past messages and my new message but with the same gap again.
I'm attaching two images showing the issue:
Here is the code I'm using:
if([MFMessageComposeViewController canSendText]) {
NSArray *recipents = nil;
NSString *message = #"Let's go";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
[self presentModalViewController:messageController animated:YES];
}
Please tell me if know you know how to fix this issue.
Thanks!
Additional info:
This bug only happens in iOS 7.x not in in iOS 6.x
Also, if I use the MFMailComposeViewControllerDelegate to send emails, it works just fine (although they are both implemented by MessageUI.h)...
Ok, I figured it out.
The issue happens because I have a custom UINavigationController.
In my AppDelegate, I had the following code:
UIImage *navBarImage = [UIImage imageNamed:#"BarIos7.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
Once I removed it, everything started working fine.

How to stream online radio from SHOUTCast in my iOS App?

I am developing an iPhone Online Radio Streamer App. I used Matt Gallaher's AudioStreamer class to stream online tune in stations from SHOUTCast. But the problem is that the AudioStreamer API has been abandoned and fails to play various radio channels.
I have googled and found various alternatives including: AVPlayer, MPMoviePlayer etc.
Please recommend which player will fulfill the requirement best.
You can use MPMovieplayerviewcontroller. It is perfect for streaming audio/video. I am also
use this for streaming audio in one of my App & also it looks like default player of iPhone.
Ok here is coding for use of this player as I am doing in my project:
NSString *geturl = [[radiotablearray objectAtIndex:btntag]objectForKey:#"iurl"];
NSLog(#"geturl..%#",geturl);
NSURL *fileURL=[NSURL URLWithString:geturl];
NSLog(#"fileURL..%#",fileURL);
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.moviePlayer.shouldAutoplay=YES;
moviePlayerController.view.frame = self.view.frame;
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer play];
Also add mediaplayer & Avfoundation framework in App.And add or import these two in .h file:
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
& import #import <MediaPlayer/MediaPlayer.h>this in .m file. also make property of player like below in .h file:
MPMoviePlayerViewController *moviePlayerController;
#property(strong,retain) MPMoviePlayerViewController *moviePlayerController;
And add method where you want but also make changes in code according to your need I am just send you my implement code you just change it with your requirement. If you have any problem then ask me. Best of luck.
// viewcontroller.h
MPMoviePlayerViewController *moviePlayer;
//viewcontroller.m
This is implemented in viewDidLoad
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",#"http://sample url"]]];
[moviePlayer.moviePlayer prepareToPlay];
moviePlayer.view.hidden = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];

UIDocumentInteractionController: "Open In" visible on iPhone but not on iPad - why?

For testing purposes I wrote two apps:
First one plays an MP3 file using UIDocumentInteractionController
Second one does nothing but registers for the file type "public.mp3"
If I deploy the apps to the iPhone Simulator, my MP3 player app shows a button on top "Open in 'MP3Test'". If I deploy to the iPad Simulator however, there is no button and no "Open In" menu either.
This has been tested with iOS5.
Can somebody explain if this is a bug or a feature and what the reason is behind it?
Depends upon where you are presenting it from.
If you are presenting it from somewhere around the middle of the screen or below, just present from the frame of the object that you are presenting from.
if that is on the navigation bar, try this:
NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:#"License" ofType:#"pdf"];
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
controller.delegate = self;
CGRect navRect = self.navigationController.navigationBar.frame;
navRect.size = CGSizeMake(1500.0f, 40.0f);
[controller presentOptionsMenuFromRect:navRect inView:self.view animated:YES];
The iPad has an affinity for popovers (see UIPopover), why it presents UIActionSheets in them. Facing a similar issue that you had, I had my UIDocumentInteractionController present itself from an UIBarButtonItem (resulting in a UIPopover presentation), rather than from the view itself (something that worked just fine on the iPhone):
Save a reference to the action button (I have mine in my navigation bar).
Use PresentOpenInMenu using the action button reference, rather than the View reference, resulting in a UIPopover-presentation.
Please note that the change does not effect the iPhone app - it behaves likes before, i.e. opens the OpenInMenu from the bottom of the screen just as it would, if you'd used the View reference to present it.
On iPad UIDocumentInteractionController appearing like Pop Up Try something like this
-(void)shareClick:(UIButton*)sender {
/*some code*/
CGRect rectFor appearing = [sender.superview convertRect:sender.frame toView:self.view];
[interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];
}

Setting the AVAudioSession category in AppDelegate.m

So I hate to have to ask this question but I've spent a fair bit of time searching through Apple's documentation and Google with no avail. I'm simply trying to set the AVAudioSession category for my app ONCE, when the applicationDidFinishLaunching. I have an app that plays an audio stream and I would like it to continue playing when the app enters the background, so I'm trying to use the Playback category. Here is my code for AppDelegate.m :
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Set AudioSession
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error:&sessionError];
[[AVAudioSession sharedInstance] setDelegate:self];
// create window and set up navigation controller
[window addSubview:myNavController.view];
[window makeKeyAndVisible];
}
# pragma mark -
# pragma mark AVAudioSession Delegate Methods
- (void)beginInterruption {
}
- (void)endInterruption {
}
- (void)endInterruptionWithFlags:(NSUInteger)flags {
}
- (void)inputIsAvailableChanged:(BOOL)isInputAvailable {
}
With this code, the audio fades out anytime I hit the home button, putting
the app in the background. Any help is much appreciated, I hope that it
is a quick fix type of answer for anybody who has done this before.
First add the UIBackgroundModes key to your Info.plist file if you haven't done already.
More info here.
If you have done that already, which framework do you use to play your media?
Thanks for the help Irene. You are pretty much right with your answer except I just wanted to provide the steps that were necessary for it to work for me. I read the apple documentation that you posted and for some reason it left these important details out:
When you add the UIBackgroundModes key in the .plist file, you have to make it an array.
The value for Item 0 of the array should be audio.
Of course your app should also take care of setting its audio session category in combination with setting this key.