视频剪辑无法正确播放

发布于 2024-10-17 06:31:39 字数 1379 浏览 0 评论 0原文

我正在尝试在我的一个屏幕上播放视频。它似乎可以运行,但是当文件打开时,全屏会加载并立即关闭。该视频时长几秒,为 m4v 格式。我添加了框架并导入了类。我怎样才能使视频正常播放?

我的标题:

-(IBAction)playMedia:(id)sender {

NSString *movieFile;
MPMoviePlayerController *moviePlayer;

movieFile = [[NSBundle mainBundle]
             pathForResource:@"movie" ofType:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc]
               initWithContentURL: [NSURL fileURLWithPath: movieFile]];

[moviePlayer.view setFrame:CGRectMake(145.0, 20.0, 155.0 , 100.0)];
[self.view addSubview:moviePlayer.view ];

[[NSNotificationCenter defaultCenter] addObserver:self
                                selector:@selector(playMediaFinished:)
                                name:MPMoviePlayerPlaybackDidFinishNotification
                                object:moviePlayer];
[moviePlayer play];

if ([toggleFullscreen isOn]) {
    [moviePlayer setFullscreen:YES animated:YES];
}
}

我的实现文件是:

-(void)playMediaFinished: (NSNotification*)theNotfication {

MPMoviePlayerController *moviePlayer=[theNotfication object];

[[NSNotificationCenter defaultCenter] removeObserver:self
                            name:MPMoviePlayerPlaybackDidFinishNotification
                            object:moviePlayer];

[moviePlayer.view removeFromSuperview];
[moviePlayer release];

}

谢谢

I am trying to play a video in one of my screens. It seems to run but when the file opens, the fullscreen loads up and closes right after. The video is a few seconds long, and is m4v format. I added the framework and imported the class. How can I make it so that the video plays properly?

My header:

-(IBAction)playMedia:(id)sender {

NSString *movieFile;
MPMoviePlayerController *moviePlayer;

movieFile = [[NSBundle mainBundle]
             pathForResource:@"movie" ofType:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc]
               initWithContentURL: [NSURL fileURLWithPath: movieFile]];

[moviePlayer.view setFrame:CGRectMake(145.0, 20.0, 155.0 , 100.0)];
[self.view addSubview:moviePlayer.view ];

[[NSNotificationCenter defaultCenter] addObserver:self
                                selector:@selector(playMediaFinished:)
                                name:MPMoviePlayerPlaybackDidFinishNotification
                                object:moviePlayer];
[moviePlayer play];

if ([toggleFullscreen isOn]) {
    [moviePlayer setFullscreen:YES animated:YES];
}
}

My implementation file is:

-(void)playMediaFinished: (NSNotification*)theNotfication {

MPMoviePlayerController *moviePlayer=[theNotfication object];

[[NSNotificationCenter defaultCenter] removeObserver:self
                            name:MPMoviePlayerPlaybackDidFinishNotification
                            object:moviePlayer];

[moviePlayer.view removeFromSuperview];
[moviePlayer release];

}

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文