how to play video on splash after loding default image in iphone? - iphone

i want to play video of 4 second in app after default black image is launched what can i do? please help me
my code is below
-(void)viewWillAppear:(BOOL)animated
{
NSString* moviePath = [[NSBundle mainBundle] pathForResource:#"intro_anim" ofType:#"mov"];
NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
NSLog(#"%#",movieURL );
playerCtrl = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[playerCtrl prepareToPlay];
playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);
[playerCtrl.view setCenter:CGPointMake(240, 160)];
[playerCtrl.view setFrame:CGRectMake(0, 0, 480, 320)];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[playerCtrl play];
[self presentMoviePlayerViewControllerAnimated:playerCtrl.view];
[self.view addSubview:playerCtrl.view];
}

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController
{
NSString *url;
UIButton *btnvideo;
UIButton *btnaudio;
MPMoviePlayerController *player;
MPMoviePlayerController *Player;
NSArray *arr;
}
#property(nonatomic,retain)IBOutlet UIButton *btnvideo;
#property(nonatomic,retain)IBOutlet UIButton *btnaudio;
-(void) moviefinished:(NSNotification *)anotification;
-(void) Audiofinished:(NSNotification *)bnotification;
-(IBAction)PlayAudio:(id)sender;
-(IBAction)PlayVideo:(id)sender;
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
-(IBAction)PlayVideo:(id)sender
{
url=[[NSBundle mainBundle]pathForResource:#"nfc" ofType:#"mp4"];
player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:url]];
player.view.frame=CGRectMake(0, 0, 320, 300);
[self.view addSubview:player.view];
[player play];
}
-(IBAction)PlayAudio:(id)sender
{
[player release];
url=[[NSBundle mainBundle]pathForResource:#"bgm" ofType:#"mp3"];
Player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:url]];
Player.view.frame=CGRectMake(0, 0, 320, 300);
[self.view addSubview:Player.view];
[Player play];
}
-(void) moviefinished:(NSNotification *)anotification
{
player=[anotification object];
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player autorelease];
}
-(void) Audiofinished:(NSNotification *)bnotification
{
player=[bnotification object];
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:Player];
[Player autorelease];
}
-(void)presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)moviePlayerViewController
{
[player setControlStyle:MPMovieScalingModeAspectFit];
}
Note- please mind it to connect playaudio button action to

Insted of a default image use a view controller as splash and push the "first viewcontroller" using timer. You can do whatever you want on your "splash view controller."

Related

MPMoviePlayerController doesn't play video frame ios7

I am porting app from iOS6 to iOS7. There is a weird problem that makes the screen go black after the call from a button is being done. I have tried out this, this and this.
There is no apt answer and I don't feel theoretically there should be any problem in using the previous methods.
Kindly provide me some thread to why this problem is occuring.
Thanks
This can help
Import MediaPlayer in your .h file
#import <MediaPlayer/MediaPlayer.h>
Make a property
#property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
After that you can play video by this
-(void)playMovie:(id)sender
{
NSURL *url = [NSURL URLWithString:
#"http://www.xyz.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}
After that for removing the video view add this
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:#selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
Add your movie player controller view on main windows like:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:#"map.mp4"]];
[player prepareToPlay];
[player.view setFrame: self.view.bounds];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview: player.view];
[player play];
Hope so it will work for you!
Try this way..
ViewController.m
MPMoviePlayerViewController *mp=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[arr_videos objectAtIndex:indexPath.row]valueForKey:#"Video_path"]]];
MPMoviePlayerController *pc=[mp moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self presentViewController:mp animated:YES completion:nil];
[pc prepareToPlay];
[pc play];

About MpMoviePlayerViewController

Hi Everyone Gud Evening
I have taken a view on which i had to play the video, the video is being played Perfectly, but very rarely i the video is not being appeared on the view, at that time i got a warning in the console like
WARNING: under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: should not be re-entered.
Could some one help me to sort out this problem
Thank You Everyone
I have 2 UIView's in being displayed on the same view, In one view when i start drawing the movieplayer gets started in the bottomProgressView , in the viewcontroller in viewdidload the code is like this
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *url = [[NSBundle mainBundle] pathForResource:#"progres" ofType:#"mp4"];
timeCompletedCnlr = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]] ;
[timeCompletedCnlr.view setFrame:CGRectMake(0,468, 600, 50)];
[timeCompletedCnlr setControlStyle:MPMovieControlStyleNone];
[bottomProgressView addSubview:timeCompletedCnlr.view];
}
When i touch the view that is being to drawn then the below method is called.
- (void)removeGivenWord
{
[bottomToolBar removeFromSuperview];
[self.view addSubview:bottomProgressView];
[timeCompletedCnlr play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(helpVideoFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:timeCompletedCnlr];
UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
doneBtn.frame = CGRectMake(601, 940, 167, 43);
[doneBtn setBackgroundImage:[UIImage imageNamed:#"done.png"] forState:UIControlStateNormal];
[doneBtn addTarget:self action:#selector(doneButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:doneBtn];
}
the view on which the video is placed also contains the done button too..
- (void)doneButtonClicked {
[timeCompletedCnlr stop];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(helpVideoFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:timeCompletedCnlr];
}
- (void) helpVideoFinished:(NSNotification*) aNotification {
MPMoviePlayerController *player1 = [aNotification object];
[[NSNotificationCenter defaultCenter]removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player1];
[smoothLineView completed5Sec];
NSLog(#"5sec called");
NSError *error = [[aNotification userInfo] objectForKey:#"error"];
if (error) {
NSLog(#"Did finish with error: %#", error);
}
}
My Problem is the video sometimes it appears and sometime it doesn't come,

MPMoviePlayerController with UIPopoverController

I am using the MPMoviePlayerController to play a video on UIPopoverController.
When UIPopoverController dismiss video keeps on playing in background. Is there any way to stop and release MPMoviePlayer.
In my code There is FirstViewController and ViewVideoController which has function:
#implementation FirstViewController
- (void)popOverViewDisplay:(id)sender {
//if(![popoverController isPopoverVisible]){
NSLog(#"my popover....");
ViewVideoController *videoController = [[[ViewVideoController alloc] initWithNibName:nil bundle:nil] autorelease];
videoController.contentSizeForViewInPopover =CGSizeMake(550, 460);
popoverController = [[UIPopoverController alloc]
initWithContentViewController:videoController];
popoverController.delegate = self;
[videoController release];
popViewBtnFrame = CGRectMake(299, 357, 63, 42);
[popoverController presentPopoverFromRect:popViewBtnFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
if (self.popoverController != nil) {
[self.popoverController dismissPopoverAnimated:YES];
//[self.popoverController release];
NSLog(#" if loop popover dismissed");
ViewVideoController *videoController = [[ViewVideoController alloc] initWithNibName:#"ViewVideoController" bundle:nil];
[videoController unloading];
}
NSLog(#"popover dismissed");
}
on button press player start playing in popoverController.
#implementation ViewVideoController
- (void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:#"AlphabetTrain" ofType:#"mov"];
NSURL *url = [NSURL fileURLWithPath:path];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
//player.movieControlMode = MPMovieControlModeHidden;
player.controlStyle = MPMovieControlStyleDefault;
player.view.frame = CGRectMake(75.0f, 80.0f, 400.0f, 300.0f);
[[self view] setCenter:CGPointMake( [[self view] bounds].size.width / 2, [[self view] bounds].size.height / 2)];
[self.view addSubview:player.view];
[player play];
//[player release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[super viewDidLoad];
}
- (void)myMovieFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerController* player1 = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player1];
NSLog(#"stop player");
[player stop];
}
- (void)unloading { //this function called in firstviewcontroller to stop player on dismiss
NSLog(#"unloading player");
//[player endSeeking];
[self.player stop];
}
When I dismiss ViewVideoController player keeps on playing. Is there any way to stop/release player on dismiss of ViewVideoController
You can use delegate method
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[moviePlayer stop];
}

MPMoviePlayerViewController can not work on iOS 4.3 on iPhone or iPad

I now have a strange problem when I try to play movie through MPMoviePlayerViewController on iOS 4.3.
It appears just a white screen and nothing happens. My code works well on iOS 4.2. So I created a new
OpenGLES project and just use my movie code, but it can not work either. So can anybody give some tips?
Thanks in advance.
My code is below:
//-------------------------------------TestViewController.h---------------------------------------
#import <MediaPlayer/MediaPlayer.h>
#interface TestViewController : UIViewController
{
bool _isMovieEnded;
MPMoviePlayerViewController* _theMovie;
}
- (void)playMovie:(NSString*)filename;
- (void)movieFinishedCallback:(NSNotification*)aNotification;
- (bool)isMovieEnd;
//-------------------------------------TestViewController.m---------------------------------------
- (void)playMovie:(NSString*)filename
{
NSURL* theURL = [NSURL fileURLWithPath:filename];
_theMovie = [[MPMoviePlayerViewController alloc] init];// initWithContentURL:theURL];
[_theMovie.moviePlayer setContentURL:theURL];
_theMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[_theMovie.moviePlayer setControlStyle:MPMovieControlStyleNone];
[_theMovie.moviePlayer setFullscreen:YES];
// register notification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_theMovie];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[_theMovie.moviePlayer play];
[self.view addSubview:_theMovie.view];
}
- (void)movieFinishedCallback:(NSNotification*)aNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:_theMovie];
// release movie
[_theMovie.view removeFromSuperview];
[_theMovie release];
_isMovieEnded = true;
[self startAnimation];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
- (bool)isMovieEnd
{
return _isMovieEnded;
}
//-------------------------------------TestAppDelegate.m---------------------------------------
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
[self.window addSubview:self.viewController.view];
NSString* movieFile = [[NSBundle mainBundle] pathForResource:#"logo" ofType:#"mp4"];
[viewController playMovie:movieFile];
[viewController stopAnimation];
return YES;
}
// Determines if the movie is presented in the entire screen (obscuring all other application content). Default is NO.
// Setting this property to YES before the movie player's view is visible will have no effect.
#property(nonatomic, getter=isFullscreen) BOOL fullscreen;
- (void)setFullscreen:(BOOL)fullscreen animated:(BOOL)animated;
From MPMoviePlayerController.h
so here you are the code:
- (void)playVideoFromUrl:(NSString*)url {
MPMoviePlayerViewController *moviePlayer = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]] autorelease];
[((UIWindow*)[[UIApplication sharedApplication].windows objectAtIndex:0]).rootViewController presentMoviePlayerViewControllerAnimated:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer.moviePlayer setFullscreen:YES animated:YES];
[moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
}
- (void)moviePlaybackComplete:(NSNotification *)notification {
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[((UIWindow*)[[UIApplication sharedApplication].windows objectAtIndex:0]).rootViewController dismissMoviePlayerViewControllerAnimated];
}

MPMoviePlayer Bad-Access error after playing video

I´ve created an new ViewController (only with the .h and .m file) and added that code to play a video. After the video has finished, i get a "Exe_bad_access" error.
Error message when adding "NSZombieEnabled=true" to the excecutable as a argument:
"TestPlayingVideo[654:207]
-[MPMoviePlayerController stop]: message sent to deallocated instance
0x63042d0"
Whats wrong with that? How can i do correct memory management when playing video?
#import "TestPlayingVideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#implementation TestPlayingVideoViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor darkGrayColor]];
UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(50 , 50, 200, 25)];
[btn setTitle:#"press me" forState:UIControlStateNormal];
[btn addTarget:self action:#selector(action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn release];
}
- (void)action:(id)sender
{
NSLog(#"UIButton was clicked");
NSString *url = [[NSBundle mainBundle] pathForResource:#"mymovie" ofType:#"m4v"];
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];
[moviePlayerController.moviePlayer play];
//[self.view addSubview:moviePlayerController.view];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
}
- (void) moviePlayBackComplete:(NSNotification*) notification {
MPMoviePlayerController* player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[self dismissMoviePlayerViewControllerAnimated];
[player stop];
//[self.view removeFromSuperView];
[player release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
There's a lot of confusion here over what you're releasing: for example, here's your main alloc of your movie player:
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
But what you are releasing isn't this moviePlayerController - you're only releasing the .moviePlayer property of your MPMoviePlayerController. Notice when you create your NSNotification you're passing moviePlayerController.moviePlayer, not simply moviePlayerController.
So you're not releasing your moviePlayerController, you're in fact attempting to release a property of that object. Which you shouldn't do - you should release the object, and let it worry about releasing its properties.