需要 MPMoviePlayerController 初始化方面的帮助

发布于 2024-11-15 04:10:58 字数 1906 浏览 8 评论 0原文

我有一个应用程序,允许用户使用向下钻取表视图模型从媒体项目列表移动到特定项目。

Main View

用户进入详细信息视图后,另一个表格视图存在允许用户选择特定媒体项目。

详细视图

我在创建要播放的模态媒体播放器时遇到问题.mp4 项目。下面的代码是我到目前为止所拥有的。

if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderEnclosure) {  
    if (item.enclosures) {  
        for (NSDictionary *dict in item.enclosures){ 

            NSString *url = [dict objectForKey:@"url"];  
            NSLog(@" url is : %@",url); 

            //EXPERIMENTAL
            MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];  

            // Register to receive a notification when the movie has finished playing.  
            [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];  

            if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
                // Use the 3.2 style API  
                moviePlayer.controlStyle = MPMovieControlStyleDefault;  
                moviePlayer.shouldAutoplay = YES;  
                [self.view addSubview:moviePlayer.view];  
                [moviePlayer setFullscreen:YES animated:YES];  
            } else {  
                // Use the 2.0 style API  
                moviePlayer.movieControlMode = MPMovieControlModeHidden;  
                [moviePlayer play];  
            }           
        }  
    }  
}

我需要这行的帮助: MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

它给了我一个 NSInvaild Argument Exception 。我需要有关创建视频播放器以及随后从视图中删除的帮助。

I have an app that allows the user to move from a list of media items to a specific item using the drill-down table view model.

Main View

Once the user is inside the detail view, another table view exists allowing the user to select a specific media item.

Detail View

I am having an issue creating a modal media player to play the .mp4 items. The code below is what I have so far.

if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderEnclosure) {  
    if (item.enclosures) {  
        for (NSDictionary *dict in item.enclosures){ 

            NSString *url = [dict objectForKey:@"url"];  
            NSLog(@" url is : %@",url); 

            //EXPERIMENTAL
            MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];  

            // Register to receive a notification when the movie has finished playing.  
            [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];  

            if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
                // Use the 3.2 style API  
                moviePlayer.controlStyle = MPMovieControlStyleDefault;  
                moviePlayer.shouldAutoplay = YES;  
                [self.view addSubview:moviePlayer.view];  
                [moviePlayer setFullscreen:YES animated:YES];  
            } else {  
                // Use the 2.0 style API  
                moviePlayer.movieControlMode = MPMovieControlModeHidden;  
                [moviePlayer play];  
            }           
        }  
    }  
}

I need help with this line:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

It is giving me an NSInvaild Argument Exception. I need help with the video player creation and subsequent deletion from the view.

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

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

发布评论

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

评论(1

不必了 2024-11-22 04:10:58

看起来您已将 URL 存储为纯 NSString,而播放器需要一个 NSURL。这个怎么样?

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] 
    initWithContentURL:[NSURL URLWithString:url]];

It looks like you have the URL stored as a plain NSString, whereas the player expects an NSURL. How about this?

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