我想在启动默认黑色图像后在应用程序中播放4秒的视频我该怎么办?请帮帮我
我的代码在
之下-(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 :(得分: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按钮操作连接到
答案 1 :(得分:0)
而不是默认图像使用视图控制器作为启动并使用计时器推送“第一个视图控制器”。您可以在“启动视图控制器”上执行任何操作。