iPad 中的 Mpmovieplayercontroller - 无视频,仅音频

发布于 2024-09-29 09:31:10 字数 1229 浏览 1 评论 0原文

我正在开发一个 iPad 应用程序,在其中播放应用程序本身存储的视频。我在表格视图中表示视频列表。当我选择一行时,视频 对应于该行播放。但在执行此操作时,有时屏幕会变黑,看不到视频,但只播放音频。

我知道使视频以全屏模式播放或使用 MPMoviePlayerViewController 可以消除此问题。但我的要求是我不想一开始就全屏播放电影。请指导我如何实现这一目标。

-(void)playMovie {
   MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc]     initWithContentURL:movieUrl];
   self.moviePalyer = movieController;
   [movieController release];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object: self.moviePalyer];

 self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313);
 self.moviePalyer.view.backgroundColor = [UIColor clearColor];
 [self.moviePalyer prepareToPlay];
 [self.view addSubview: self.moviePalyer.view];
 [self.moviePalyer play];

}
-(void)moviePalyerDidFinish:(NSNotification*)notification
{
 [moviePalyer.view removeFromSuperview];
 [moviePalyer stop];
 moviePalyer.initialPlaybackTime = -1.0;

 [[NSNotificationCenter defaultCenter] removeObserver:self
             name:MPMoviePlayerPlaybackDidFinishNotification
              object:moviePalyer];
 [moviePalyer release];
 moviePalyer = nil;
}

注意:这是在 ipad 模拟器上

I am developing an iPad app where I am playing the videos stored within the app itself. I am representing the list of videos in a table view. When I select a row, the video
corresponding to that row plays. But while performing this, sometimes screen goes black , no video is visible but only audio is playing.

I am aware that making the video play in fullscreen mode or using the MPMoviePlayerViewController eliminates this problem. But my requirement is that I don't want to play the movie in fullscreen initially. Please guide me on how this can be achieved.

-(void)playMovie {
   MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc]     initWithContentURL:movieUrl];
   self.moviePalyer = movieController;
   [movieController release];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object: self.moviePalyer];

 self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313);
 self.moviePalyer.view.backgroundColor = [UIColor clearColor];
 [self.moviePalyer prepareToPlay];
 [self.view addSubview: self.moviePalyer.view];
 [self.moviePalyer play];

}
-(void)moviePalyerDidFinish:(NSNotification*)notification
{
 [moviePalyer.view removeFromSuperview];
 [moviePalyer stop];
 moviePalyer.initialPlaybackTime = -1.0;

 [[NSNotificationCenter defaultCenter] removeObserver:self
             name:MPMoviePlayerPlaybackDidFinishNotification
              object:moviePalyer];
 [moviePalyer release];
 moviePalyer = nil;
}

NOTE: This is on ipad simulator

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

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

发布评论

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

评论(1

烟若柳尘 2024-10-06 09:31:10

我已经解决了这个问题。以前,我为每个行选择创建 MPMoviePlayerController,并在 moviedidfinish 通知方法中释放它。但是现在,我不再为每个行选择创建 movieplayercontroller,而是重用已创建的 MPMoviePlayerControler 对象。

以下是代码片段:

-(void)playMovie
{
   if(self.moviePalyer == nil)
   {

    MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
    self.moviePalyer = movieController;
    [movieController release];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePalyer];

    self.moviePalyer.repeatMode = MPMovieRepeatModeOne;
    self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313);
    self.moviePalyer.view.backgroundColor = [UIColor clearColor];
}
else 
{
    [self.moviePalyer setContentURL:url];
    [self stopMovie];
}
[self.view addSubview: self.moviePalyer.view];
[self.moviePalyer play];
   }
   -(void)stopMovie
   {
     [self.moviePalyer.view removeFromSuperview];
[self.moviePalyer stop];
self.moviePalyer.initialPlaybackTime = -1.0;
   }

我在 dealloc 方法中释放 moviePlayer 对象。

希望这对遇到同样问题的人有所帮助。

I have solved the issue. Previously I was creating the MPMoviePlayerController for each of the row selection, and releasing it in the moviedidfinish notification method .But now, instead of creating movieplayercontroller for every row selection, I am reusing the MPMoviePlayerControler object which has been already created.

Following is the Code snippet:

-(void)playMovie
{
   if(self.moviePalyer == nil)
   {

    MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
    self.moviePalyer = movieController;
    [movieController release];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePalyer];

    self.moviePalyer.repeatMode = MPMovieRepeatModeOne;
    self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313);
    self.moviePalyer.view.backgroundColor = [UIColor clearColor];
}
else 
{
    [self.moviePalyer setContentURL:url];
    [self stopMovie];
}
[self.view addSubview: self.moviePalyer.view];
[self.moviePalyer play];
   }
   -(void)stopMovie
   {
     [self.moviePalyer.view removeFromSuperview];
[self.moviePalyer stop];
self.moviePalyer.initialPlaybackTime = -1.0;
   }

I am releasing the moviePlayer object in the dealloc method.

Hope this helps who is having the same issue.

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