gpt4 book ai didi

iphone - MPMoviePlayerController View 未添加到 View Controller

转载 作者:行者123 更新时间:2023-12-03 19:59:09 27 4
gpt4 key购买 nike

我正在编写代码,以这样的方法在 ownservices.m 类中播放视频文件。

-(void)playVediofile:(NSString *)vedioFileName {

NSLog(@"playing vedio file ");
NSURL *movieUrl = [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:vedioFileName ofType:@"mp4"]];

MPMoviePlayerController* myMovie=[[MPMoviePlayerController alloc]
initWithContentURL:movieUrl];

myMovie.scalingMode = MPMovieScalingModeNone;

myMovie.initialPlaybackTime = 2.0;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:myMovie];

[self.viewcontroller addSubview:myMovie.view];

[myMovie play];

}

我从 ownservicesviewcontroller.m 类中调用此方法,如下所示在按钮单击事件中。

ownServices *obj = [[ownServices alloc]init];
[obj playVediofile:@"Movie"];

我正在获取视频剪辑的音频,但它没有显示视频。

但我将 MPMoviePlayerController View 添加到 View Controller 中。

我不明白为什么它不显示。

为什么我在单独的类中进行操作是因为我的要求是这样的,需要维护 ownservices 类中的所有方法并从 ownservicesviewcontroller.m 调用它们

谁能帮帮我吗?

谢谢。

最佳答案

您需要设置myMovie.view的frame属性:例如您可以将其设置为父边界:

myMovie.view.frame = self.viewcontroller.bounds;

除此之外,请检查您的实例变量命名。看来,您将 View 实例命名为“viewcontroller”,这很奇怪。如果 viewcontroller 确实是 UIViewController 类型,则需要将 myMovie.view 添加到 viewcontroller 的 view 属性,而不是直接添加到 viewcontroller...

关于iphone - MPMoviePlayerController View 未添加到 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6410159/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com