我正在使用一个需要在单击视频文件时打开“MPMoviePlayerViewController”的应用程序。
我们的应用程序中有一个 tabbarController,它有四个导航控制器用于四个选项卡。
我的应用只支持纵向,但视频应该同时支持横向和纵向。所以,我创建了“MPMoviePlayerViewController”的子类。
该类的代码..
@interface MyMovieViewController : MPMoviePlayerViewController
@end
@implementation MyMovieViewController
-(void)viewDidLoad{
[self setWantsFullScreenLayout:NO];
}
-(void)viewWillDisappear:(BOOL)animated{
[self resignFirstResponder];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
-(BOOL)shouldAutorotate{
return YES;
}
@end
在第一个选项卡中,我显示图库。有一个打开视频文件的代码。
UIGraphicsBeginImageContext(CGSizeMake(1,1));
MPMoviePlayerViewController * vc = [[MyMovieViewController alloc] initWithContentURL:[[[elcAsset asset] valueForProperty:ALAssetPropertyURLs] valueForKey:[[[[elcAsset asset] valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]]];
UIGraphicsEndImageContext();
// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:vc
name:MPMoviePlayerPlaybackDidFinishNotification
object:vc.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(doneButtonClick:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: vc.moviePlayer];
[self presentMoviePlayerViewControllerAnimated:vc];
[vc.moviePlayer prepareToPlay];
[vc.moviePlayer play];
视频是工作文件。它还支持两个方向。但是当我切换到另一个选项卡时,单击它时没有文本字段显示键盘。
请帮忙。谢谢是提前。