将视频集成到 iPhone 应用程序中

发布于 2024-12-10 05:39:11 字数 1275 浏览 0 评论 0原文

我必须将视频集成到我的 iPhone 应用程序中。与网上所有代码的区别在于,我必须显示视频并给用户播放它的机会。而不是自动播放它。

这就是我所做的:

- (void) play
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mp4"];
    NSURL *fileUrl1 = [NSURL fileURLWithPath:path];
    videoPlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:fileUrl1];
    [videoPlayer1 setControlStyle:MPMovieControlStyleNone];
    [[videoPlayer1 view] setFrame:[self.view bounds]];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    //[videoPlayer1 play];
    [self.view addSubview:[videoPlayer1 view]];    
}
- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];

    [videoPlayer1.view removeFromSuperview];
    [videoPlayer1 stop];
    [videoPlayer1 release];
    videoPlayer1 = nil;
}

但是屏幕只是变黑,没有显示任何其他内容。

除非我执行 [videoPlayer1 play] 什么也不会发生。但我不想自动播放视频......它必须由用户播放。 那么,我应该如何操作才能显示视频(而不是黑屏)并在用户希望时播放它?谢谢

I have to integrate a video into my iphone app.The difference from all the code that there is on the net is that I have to show the video and give to the user the chance to play it.Not to play it automatically.

And here is what I have done:

- (void) play
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mp4"];
    NSURL *fileUrl1 = [NSURL fileURLWithPath:path];
    videoPlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:fileUrl1];
    [videoPlayer1 setControlStyle:MPMovieControlStyleNone];
    [[videoPlayer1 view] setFrame:[self.view bounds]];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    //[videoPlayer1 play];
    [self.view addSubview:[videoPlayer1 view]];    
}
- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];

    [videoPlayer1.view removeFromSuperview];
    [videoPlayer1 stop];
    [videoPlayer1 release];
    videoPlayer1 = nil;
}

But the screen just turn black and nothing else shown.

Unless I do [videoPlayer1 play] nothing happens.But I don't want to play the video automatically...it must be played by the user.
So, how should I act in order to show up the video(!not the black screen) and play it when the user wishes?Thanks

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹倦 2024-12-17 05:39:11

您犯了一个错误,这里是

Change this

[videoPlayer1 setControlStyle:MPMovieControlStyleNone];

[videoPlayer1 setControlStyle:MPMovieControlStyleDefault];

您正在使用您的那一行来隐藏控件。

干杯!!!

You are making an error and here it is

Change this

[videoPlayer1 setControlStyle:MPMovieControlStyleNone];

to

[videoPlayer1 setControlStyle:MPMovieControlStyleDefault];

You are hiding the controls by using that line of yours.

Cheers!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文