iPad 播放视频

| 4 Comments | No TrackBacks
MPMoviePlayerController 不能正常工作了,需要MPMoviePlayerViewController

写了几个测试方法,可以play了,哈哈,另外写了获取缩略图的代码

屏幕快照 2010-03-10 下午05.26.09.png

- (void)viewDidLoad {

    [super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self 

selector:@selector(moviePlayBackDidFinish:) 

name:MPMoviePlayerPlaybackDidFinishNotification 

  object:nil];

NSString *movpath =[[NSBundle mainBundle] pathForResource:@"test" ofType:@"m4v"];

mpviemController =[[MPMoviePlayerViewController allocinitWithContentURL:[NSURL fileURLWithPath:movpath]];

[self.view addSubview:mpviemController.view];

mpviemController.view.hidden=YES;

MPMoviePlayerController *mp=[mpviemController moviePlayer];

[mp prepareToPlay];

UIImage *thumbImage=[mp thumbnailImageAtTime:5.0 timeOptionMPMovieTimeOptionNearestKeyFrame];

NSData *imagedata =UIImagePNGRepresentation(thumbImage);

[imagedata writeToFile:@"1.png" atomically:YES];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivenotf:) name:MPMoviePlayerScalingModeDidChangeNotification object:mp];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivenotf:) name:MPMoviePlayerPlaybackDidFinishNotification object:mp];

}


- (void) receivenotf:(NSNotification*)notification

{

NSLog(@"111xxx%@ \n %@",notification,[notification userInfo]);

    

mpviemController.view.hidden =YES;

/*     

< add your code here >

 

MPMoviePlayerController* moviePlayerObj=[notification object];

etc.

*/

}

-(IBAction)play

{

CGRect frame = self.view.frame;

if (mpviemController.view.hidden ==YES) {

mpviemController.view.hidden =NO;

}

//[mpviemController moviePlayer].scalingMode = MPMovieScalingModeFill;

[[mpviemController moviePlayer] play];

}

No TrackBacks

TrackBack URL: http://iphone.ipsw.info/mt/mt-tb.cgi/295

4 Comments

感谢~
我也遇到了这个问题

我按照你的代码运行了一下,可是我只能看到视频,没有声音。这是为什么呢?(我的视频格式为.mov)

是视频文件的问题。我用mp4就好了。
还有个问题:视频播放完后为什么有一个白屏闪一下,能否去掉(我把北京设置为red)?

附上我的代码:
- (void)receivenotf:(NSNotification *)notification{

//视频隐藏,并删去视频
mpviemController.view.hidden =YES;
[mpviemController.view removeFromSuperview];

//添加你的代码,实现你的效果,例如:
self.view.backgroundColor=[UIColor redColor];

}

Leave a comment