2013-06-18 97 views
1

我想默認的黑色圖像啓動我能做些什麼之後在應用播放4秒的視頻?請幫我後iphone裝載儀默認圖像如何播放視頻飛濺?

我的代碼如下

默認圖像的
-(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]; 

} 
+0

這一個:'[自presentMoviePlayerViewControllerAnimated:playerCtrl.view]' 是行不通的,因爲它不是MPMoviePlayerViewController –

回答

3
#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]; 

} 

注意 -請介意它playaudio按鈕動作連接到

+0

我認爲這履行了你的答案 –

0

insted的使用視圖控制器作爲飛濺和推動「第一視圖 - 控制」使用定時器。你可以在你的「飛濺視圖控制器」上做任何你想做的事情。

相關問題