Is it okay to use MPMoviePlayerController without adding it to our view? - mpmovieplayercontroller

I'm writing an online radio streaming app. I'm using my own buttons to control the playback. I really don't want the view of MPMoviePlayerController.
Will apple reject my app if I just let it play the audio without adding MPMoviePlayerController to my view?
I'm thinking of removing second last line in the code below:
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds];
[myView addSubview: player.view]; //i want to remove this line
[player play];

It is also possible to do the following to hide it without removing that line:
player.view.hidden = YES;

Related

MPMoviePlayerController shows blank screen second time launching

I am using MPMoviePlayerController to play video on iOS.
First time I hit the url and video gets downloaded to documents directory & played well.
Second time I check if the video is already downloaded or not.
If not then it goes to server & download it,
if yes then it should access it from documents directory and should play video.
but when I fetch video from documents directory then it shows the path well, along with video file name, but
it doesn't play the video.
Directly it moves to last view with blank white screen.
What I am doing wrong.
Thanks in advance.
Here is my code.
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docDir = [arrayPaths objectAtIndex:0];
NSString* destinationDirectoryPath=docDir;
NSString *clientPathString = [[NSString alloc] initWithFormat:#"/user"];
destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:clientPathString];
destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:#"/video1/"];
NSString *filePath=[NSString stringWithFormat:#"%#",userVideoDTO.learnerid];//#"author";
filePath=[destinationDirectoryPath stringByAppendingString:[NSString stringWithFormat:#"%#.mp4",filePath]];
NSLog(#"FilePath new one :- %#",filePath);
self.url = [NSURL fileURLWithPath:filePath];
Then this self.url is passed to MPMoviePlayerController as
self.mp =[[MPMoviePlayerController alloc] initWithContentURL:self.url];
[self.view addSubview:mp.view];
[self.mp play];
What I am missing.
Can anyone let me know.
This same code is working fine on lower versions of iOS. like iOS7 and below.
not on iOS8.
Thanks in advance.
I have been having a similar issue, and it turned out that while in iOS7 and below the containing view controller hadn't had it's -viewWillDisappear:animated: called before the movie player was shown, whereas in iOS8 and going further, it does get called. I was releasing the player and unsubscribing from notifications in -viewWillDisappear:animated:, this time I had to move this code to dealloc.

When a view is dismissed, the presenting view throws EXC_BAD_ACCESS

I'm converting my iPhone app to an iPad version, creating new XIBs for the iPad and rigging them to the existing objective C classes using the ~ipad XIB name.
In the iPhone version, I use the navigation controller to step backwards to the app. This should work just fine in the iPad too, but while the navigation controller does appear, it doesnt respond. In fact its invisible to any interaction, if theres a map behind the navigation controller and you double click back, you just zoom on the map where you clicked.
So I'm including a button in the iPad view which should do the same thing. On press I call a
[[self navigationController] popViewControllerAnimated: YES];
When I call this I get the EXC_BAD_ACCESS. I've gone in to the spooky zombie mode which gives me this
*** -[UIWindowLayer superlayer]: message sent to deallocated instance 0x83bb9f0
Ive determined that 0x83bb9f0 is the presenting layers self.view.layer
I'm using ARC to handle my allocations and deallocs.
THE QUESTION IS: How can I prevent self.view.layer from deallocing? or how can I allocate it again at the proper time so that I dont get this error?
I can provide more code if needed. Thanks so much!!
Edit: Heres where the main page (landing page) is created, and the nav controller
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
landingPage *LandingPage = [[landingPage alloc] initWithNibName:#"landingPage" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:LandingPage];
self.window.rootViewController = self.navigationController;
// [self.navigationController pushViewController:LandingPage animated:YES];
[self.window makeKeyAndVisible];
return YES;
Then here is where the inner view is called:
mapView *MapView = nil;
MapView =[[mapView alloc] initWithNibName:#"mapView" bundle:nil];
[self.navigationController pushViewController:MapView animated:YES];
So I got it!
The XIBs I was creating for the iPad version were windows instead of views. I recreated all of these as views and rigged it up and it worked just fine!

AVAudioPlayer is releasing before playing?

I'm making a soundboard app and I use this code to play mp3 files:
-(IBAction)playSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"mysound" ofType:#"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
[theAudio release];
}
When I include [theAudio release]; the sound doesn't play. If I take it out it plays but I don't want to have memory leaks. How can I fix this?
It would be very helpful if you could include whatever code I need to add. I'm new to programming (besides TrueBasic I've used in school) so I'm unfamiliar with Objective-C.
wait til the audio finishes via a delegate to release the audio. I believe there are a number of posts exactly like this on the site if you search, they will have the specific delegate code.
This is only because you use local variable. so theAudio will released immediately.
You should define it as class member and assignment it here. so when this function finished, it still work too.

ios4 - Load new view on clicking a button

I am currently using XCode 3.2.3 and iOS4. I'm working on an app that simply starts with one screen and on a button click moves to the next.
I have gone thorugh the ViewController programming guide and a post here.
What I am doing is very similar to whats happening on the post. So let me explain the steps, I followed:
In IB, drag and drop, a View from the library into the editor. I renamed the new UIView to myView.
In my AppControllerDelegate, I added the new view "myView" as a property of the view controller (File's Owner). I synthesized it as well in the implementation.
Now, in the implementation of the ViewController, within the button pressed action handler, I wrote the following lines of code:
[self.view addSubView: myView];
On clicking the button however, I do not see a new screen or my new view. However if I do this, I get a new screen or new view:
UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame];
[self.view addSubView: anotherView];
I do know that the best way is to do it with separate NIBs for each UIView. However, I am new to iPhone development and have not explored that path as yet.
My question: What am I missing upto step 3?
One way you could be able to do it is by trying it this way
myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle: [NSBundle mainBundle]];
[self.view addSubview: myView.view];
Try that and see if it is working.. if yours is a view based project then instead of [self.view addSubview: myView.view], just give [self.view addSubview : myView];

How to make MPMoviePlayerController respect the ring/silent switch?

I'm trying, unsuccessfully, to get the MPMoviePlayerController to play movies silently if the ring/silent switch on the iPhone is set to silent. There are no interface methods to help me out nor does the player respect the AudioSessionProperty() trick:
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionSetProperty(
kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory);
Has anyone had any success silencing movie playback?
I spent some time trying to get this to work myself. Eventually I gave up after trying, failing and reading this post on the apple dev forums.
"The MPMoviePlayerController establishes its own audio session and there is nothing you can do to affect this"
MPMoviePlayerController has a property useApplicationAudioSession that will allow the player to respect the device's silence setting.
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
player.useApplicationAudioSession = YES;
[player play];
Add this in your code:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];

Resources