xcode 在目标 c 中播放视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8519993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:45:00  来源:igfitidea点击:

playing video in objective c

objective-cxcodevideo

提问by Hacer sengul Akac

I try this but not work I can hear the sound but I can't see the image..How can I solve this??

我尝试了这个但不起作用我可以听到声音但我看不到图像..我该如何解决这个问题?

in app delegate class:

在应用程序委托类中:

- (IBAction)tanitimVideo:(id)sender {
// create our UnifeyeMobileViewController and present it
video* unifeyeMobileViewController = [[video alloc] initWithNibName:@"video" bundle:nil];
unifeyeMobileViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController presentModalViewController:unifeyeMobileViewController animated:YES];
[unifeyeMobileViewController release];

}

in video.m class:

在 video.m 类中:

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view from its nib.

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];
NSURL  *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}

回答by jerrylroberts

Try using MPMoviePlayerViewControllerinstead, very little code to get it working and you can do it all from your app delegate ;)

尝试使用MPMoviePlayerViewController代替,只需很少的代码即可使其工作,您可以从应用程序委托中完成所有操作;)

- (IBAction)tanitimVideo:(id)sender {
    NSBundle *bundle = [NSBundle mainBundle];

    NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];

    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];

    mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;

    [self presentMoviePlayerViewControllerAnimated:mp];

    [mp release];
}

回答by Amir Foghel

Look at your .m file-

看看你的 .m 文件-

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view from its nib.

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];
NSURL  *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];

////////// <<<<<>>>>>>>>>> //////////

MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] 
initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];

}

why do you make 2 controllers (theMovie , moviePlayer) and you setting all in theMovie but running the moviePlayer.

为什么要制作 2 个控制器(theMovie、moviePlayer)并在 theMovie 中设置所有内容但运行 moviePlayer。

it's should be like this: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.

它应该是这样的: - (void)viewDidLoad { [super viewDidLoad]; // 从其笔尖加载视图后进行任何其他设置。

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];
NSURL  *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie setShouldAutoplay:YES];
[self presentMoviePlayerViewControllerAnimated:theMovie];

}

hope it's help.

希望有帮助。