Search code examples
iphoneiosobjective-cios6xcode4.5

how to play video on splash after loding default image in 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];

}

Solution

  • #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