launching video at application launch fails iOS - ios

I want to show a small video (3 sec video) every time when user opens the application on iOS device.
(If the app is opened from memory then don't show video)
I am having my "dashboard" view as root view controller.
I searched all the links on SO and other sites, but none helps.
Sometimes my video is working but later application get crashed.
My dashboardview is from "Main.storyboard" but there are no controls on storyboard.
Only linking of navigation bar is done via storyboard.
Here is my code.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self showVideo];
}
- (void)showVideo
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"video" ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
NSLog(#"video path :- %#",url);
self.navigationController.navigationBar.hidden = YES;
self.videoController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
self.videoController.moviePlayer.controlStyle = MPMovieControlStyleNone;
//[self presentMoviePlayerViewControllerAnimated:videoController];
[self.navigationController pushViewController:self.videoController animated:NO];
[self.videoController.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.videoController];
}
- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{
self.navigationController.navigationBar.hidden = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self.videoController.view removeFromSuperview];
[self.videoController.moviePlayer stop];
self.videoController = nil;
[self.navigationController popViewControllerAnimated:NO];
//[self.view removeFromSuperview];
}
the nslog is printing video path correctly.
like
video path :- file:///Users/itshastra/Library/Developer/CoreSimulator/Devices/87C93694-66E8-4884-B087-10E1E4CBA4D1/data/Containers/Bundle/Application/DB6C89D4-EE6D-4830-B208-B4AA89FD8E59/Complaint.app/video.mp4
But App get crashed,
Neither it shows the video and then dashboard, not dashboard directly.
Can any one please guide me, what I am doing wrong.
Thanks in advance.
If by mistake I missed any link on SO, please provide that as well.
Thanks.

Try calling method like this,
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:#selector(showVideo) withObject:nil afterDelay:0.1f];
}

Please enable the option "Enable Zombie Objects" under following path:
Edit Scheme -> Diagnostics -> Enable Zombie Objects
and let me know the logs.

Related

MPMoviePlayerController spams 'Received memory warning'

I'm adding a MPMoviePlayerController as background view and while it plays I get spams of the log-message 'Received memory warning'. I don't now why, and maybe there is a workaround or a better solution.
Here is my code:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[self navigationController]setNavigationBarHidden:YES animated:YES];
[moviePlayer play];
}
- (void) viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[moviePlayer pause];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//self.view.backgroundColor = [UIColor appStyleLightOrangeColor];
//Add Video playback
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"happy-female-friends-smartphon" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
moviePlayer.repeatMode = MPMovieRepeatModeOne;
moviePlayer.fullscreen = YES;
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
//set the frame of movie player
moviePlayer.view.frame = self.view.bounds;
[self.view insertSubview:moviePlayer.view atIndex:0];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(appBecameActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[self performSelector:#selector(animationCode) withObject:nil afterDelay:0.1f];
}
-(void)appBecameActive{
[moviePlayer play];
}
The log says it all. You are receiving a printed warning that you are using too much memory and your app will shutdown if you do not free up space. You need to take immediate steps to lower your memory line, so don't just shrug off those warnings. Yeah, your app might not crash immediately, but it is often a sign of a much bigger problem in your code setup.
Run the Allocations Instrument in XCode to see where the bulk of your memory is being used. I'd first check the size of that m4v video also. You should be streaming the video if it is a significant size. Additionally, ensure that you are not leaking memory using the Leaks instrument. But once again, when you receive the didReceiveMemoryWarning callback, take immediate action. Either pick up the notification in the AppDelegate or subscribe to the UIApplicationDidReceiveMemoryWarningNotification and release items/viewControllers that can be recreated later.
Here's the Memory Management Guide if you want to consult.
Thannks first to #tdevoy for your advices.
I finally got rid of the warning. It was the file type! I had to convert it to .3gpand now it works much smoother and without warnings.
On strange thing is I even use now 4mb more memory than before. But everything works great..

UIDeviceOrientation for MPMoviePlayerViewController

I am working on a app in which I have a list of items where i want to click on a thumbnail and video must be played, My requirement is Only MPMovieViewController must rotate remaining screens must not rotate for this I am using below method in list to make it portrait every time. But if i am using it i am not able to rotate the MPMoviePlayerViewController.
- (NSUInteger)supportedInterfaceOrientations{
return (UIInterfaceOrientationMaskPortrait);
}
So i returned "UIInterfaceOrientationMaskAll" after returning i am able to Autorotate the MPMoviePlayerViewController But when i come back clicking on done Button or after video is done when video is in landscape mode then my previous is rotating but i dont want that behaviour i need the previous view in portrait, Below is code for implementing the MPMoviePlayerViewContoller.
NSString *filepath = [[NSBundle mainBundle] pathForResource:[exeDict objectForKey:#"longVideoName"] ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController.moviePlayer];
[moviePlayerController.view setFrame:CGRectMake(0, 0, 320, 480)];
moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayerController.view.userInteractionEnabled =YES;
[moviePlayerController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationMaskAll];
// AppDelegate* myDelegate = (((AppDelegate*) [UIApplication sharedApplication].delegate));
// [myDelegate.window addSubview:moviePlayerController.view];
MainViewController* mainViewController = (MainViewController*)self.mainViewDelegate;
[mainViewController presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer play];
Please let me know how to get it.
you will have have to put code in viewwillappear() method so that your list appears in portrait mode
- (BOOL)shouldAutorotate
{
return NO;
}
Implemented above code in mainViewController??

i develop startup video while app loading instead of image.and also navigate to next page with push viewcontroller in ios

i develop splash video while app loading instead of image.and also navigate to next page with push viewcontroller in ios.But i dono this was correct code or not.But i use this some issue was happenn in third page but it was not used means my app loading fine.My sample code here.
- (void)viewDidLoad
{
[super viewDidLoad];
[self videopage];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)videopage
{
NSURL * url=[NSURL URLWithString:#"http://xyz.opening_ani.mp4"];
MPMoviePlayerController * videos =[[MPMoviePlayerController alloc]initWithContentURL:url];
videos.view.frame=CGRectMake(0, 0, 1024, 768);
videos.controlStyle=MPMovieControlStyleNone;
[self.view addSubview:videos.view];
[videos play];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(startParsing) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
//[self startParsing];
}
-(void)startParsing
{
ViewController * navigation=[[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil]autorelease];
[self.navigationController pushViewController:navigation animated:NO];
}
Please should with the following code. i think, your notification object is nil so didn't working.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(startParsing:)
name: MPMoviePlayerPlaybackDidFinishNotification
object:videos];
- (void)startParsing:(NSNotification *)noti
{
ViewController * navigation=[[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil]autorelease];
[self.navigationController pushViewController:navigation animated:NO];
}

MPMoviePlayerController - Split view controller should have its children set before layout

What is the appropriate point to send the play message to a MPMoviePlayerController instance instantiated in a splitView detail View Controller?
My app is receiving the above console message (with a !) but not crashing...
The app is utilizing MPMoviePlayerController to play a movie from an asset URL
and the responsilble method is called as follows:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self startPlayingVideo:self];
}
It plays the video just fine but the console message is looming...
If I move the method call to viewWillAppear:animate:, the console message does not show up. The issue is now I can only hear audio and do not see the video.
For completeness, here is the called method...
- (void) startPlayingVideo:(id)sender
NSURL *movieURL = [NSURL URLWithString:self.movieURLString];
if (self.moviePlayer != nil){
[self stopPlayingVideo:nil];
}
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL ];
if (self.moviePlayer != nil){
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(videoHasFinishedPlaying:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
} else {
NSLog(#"Failed to instantiate the movie player.");
}
}
My original issue stemmed from having the MoviePlayerController as an entirely different viewController (embedded in a detail navigation controller). I redesigned the parent view to include a moviePlayer child view. This solved the issue.

sound only playing through headphones on certain devices with MPMoviePlayerController

I have a weird problem for you all.
MPMoviePlayerController is playing the video fine, and the audio ONLY plays through headphones.
The real drag is that this only happens on some iPads and iPhones, even the SAME EXACT MODELS
running the SAME EXACT SYSTEM!
I've created a simple failing example here:
http://www.porcaro.org/MPMoviePlayerController/TestMovie.zip
I've seen it run fine and fail on iPhone 4S, iPhone 4 and iPad 2.
Here is the most relevant code. Thanks for any insight, I'm going to submit a bug to Apple as well:
(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
moviePath = [NSString stringWithFormat:#"%#/intro.m4v", [[NSBundle mainBundle] bundlePath]];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
theMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
controlStyle = MPMovieControlStyleEmbedded;
movieView = [self view];
movieRect = [[self view] frame];
controlStyle = MPMovieControlStyleFullscreen;
theMoviePlayer.controlStyle = controlStyle;
theMoviePlayer.view.userInteractionEnabled = YES;
if (1) {
NSLog(#"Created theMoviePlayer: %#. Playing: %#", theMoviePlayer, moviePath);
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(checkForEndOfMovie:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:theMoviePlayer];
// this line doesn't fix the problem
//[theMoviePlayer prepareToPlay];
[[theMoviePlayer view] setFrame:movieRect];
[movieView addSubview: [theMoviePlayer view]];
[theMoviePlayer play];
}
This is an old question but maybe it'll help someone. I came across the same issue and found out it was happening when the phone is in silent mode only.
Solution is to set the player's useApplicationAudioSession property to false.
[theMoviePlayer setUseApplicationAudioSession:NO];
This problem was happen to me once playing video on iPad 2 using mpMoviePlayer. The video was playing perfectly but audio only comes when earphones connected.
Solution to solve the problem:
[theMoviePlayer setUseApplicationAudioSession:NO];

Resources