在 iPhoneSDK 中的 UINavigationController 上播放从 Javascript 调用的视频

发布于 2024-10-19 14:38:28 字数 421 浏览 1 评论 0原文

我有一个应用程序,单击按钮后,我想动态创建一个 UINavigationControllernavigationController 上的当前视图将是一个 UIWebView,呈现其中嵌入视频的 JavaScript。当我单击视频的播放按钮时,视频开始播放,但我无法在前台看到视频。仅当我完全关闭 UINavigationController 时,我才能看到视频。

如何确保当我单击 UINavigationController 内的 UIWebView 中的“播放”按钮时,在前台的本机播放器中呈现视频,并且单击时在本机播放器中“完成”,我返回到“UINavigationController”?

I have an application and on clicking a button, I want to create a UINavigationController on the fly. The current view on the navigationController would be a UIWebView rendering a JavaScript with an embedded video in it. When I click on the play button of the video, the video starts playing, but I'm not able to see the video on the foreground. I'm able to see the video only if I completely dismiss the UINavigationController.

How do I make sure that when I click on the "Play" button in the UIWebView inside the UINavigationController, renders the video in the native player in the foreground and when clicked on "Done" in the native player, I go back to the "UINavigationController" ?

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

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

发布评论

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

评论(2

回忆那么伤 2024-10-26 14:38:28

您如何显示初始化视频视图控制器?

您是否正在创建一个实例并将其呈现为模态视图?

这也取决于您使用的 iOS 版本:

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];

if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
    NSLog(@"> 3.2");

    MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

    self.playerController = player;

    [player release]; player = nil;

    [self presentMoviePlayerViewControllerAnimated: self.playerController];
    self.playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:self.playerController.moviePlayer];


    [self.playerController.moviePlayer play];

} 
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
    NSLog(@"< 3.2");

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: videoURL];

    player.scalingMode = MPMovieScalingModeAspectFill;

    // Register for the playback finished notification
    [[NSNotificationCenter defaultCenter]
     addObserver: self
     selector: @selector(playbackFinished:)
     name: MPMoviePlayerPlaybackDidFinishNotification
     object: player];

    // Movie playback is asynchronous, so this method returns immediately.
    [player play];

How are you displaying initalizing the video view controller?

Are you creating an instance and presenting it as a modal view?

This also diffs depending on which version of iOS you are using:

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];

if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
    NSLog(@"> 3.2");

    MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

    self.playerController = player;

    [player release]; player = nil;

    [self presentMoviePlayerViewControllerAnimated: self.playerController];
    self.playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:self.playerController.moviePlayer];


    [self.playerController.moviePlayer play];

} 
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
    NSLog(@"< 3.2");

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: videoURL];

    player.scalingMode = MPMovieScalingModeAspectFill;

    // Register for the playback finished notification
    [[NSNotificationCenter defaultCenter]
     addObserver: self
     selector: @selector(playbackFinished:)
     name: MPMoviePlayerPlaybackDidFinishNotification
     object: player];

    // Movie playback is asynchronous, so this method returns immediately.
    [player play];
ㄟ。诗瑗 2024-10-26 14:38:28

下面是我如何创建需要渲染视频的 UIViewController 的代码片段:

UIViewController *adViewController = [[UIViewController alloc] init];
UIWebView *adView = [[UIWebView alloc] initWithFrame:r];
[adView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:adHTML]]];
adViewController.view = adView;

“adHTML”是包含嵌入了视频的 JavaScript 的 URL。

Below is the code snippet of how I create my UIViewController which needs to render the video:

UIViewController *adViewController = [[UIViewController alloc] init];
UIWebView *adView = [[UIWebView alloc] initWithFrame:r];
[adView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:adHTML]]];
adViewController.view = adView;

"adHTML" is the URL which contains the javascript which has the video embedded in it.

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