MPMoviePlayerViewController在进入YouTube后台后播放视频 [英] MPMoviePlayerViewController playback video after going to background for youtube

查看:123
本文介绍了MPMoviePlayerViewController在进入YouTube后台后播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在我的应用程序的info.plist中为必需"背景模式设置了应用程序播放音频",以使mpmovieplayerviewcontroller在进入背景后不会消失.它做得很好.但是,由于我设置了该属性,Apple最近拒绝了我的应用程序更新.

I have set App Plays Audio for Required background modes in my app's info.plist to keep the mpmovieplayerviewcontroller not dismissing after going to background. It did a great job. However, Apple has rejected my app's update recently, as I set that attribute.

然后,我一直在寻找解决方案来完成相同的工作,但是失败了.为了解决这个问题,我在视图控制器收到UIApplicationDidEnterBackgroundNotification时保存了当前的播放时间

Then I keep finding solutions for doing the same job but fail. To deal with it, I save the currentplaybacktime when the view controller receive UIApplicationDidEnterBackgroundNotification

-(void)willEnterBackground {
    NSLog(@"willEnterBackground");
    if (self.mp) {
        playbackTime = self.mp.moviePlayer.currentPlaybackTime;
        [self.mp dismissModalViewControllerAnimated:YES];
    }
}

并在收到UIApplicationWillEnterForegroundNotification后设置currentPlayBackTime:

And set the currentPlayBackTime after it receives UIApplicationWillEnterForegroundNotification:

- (void)willEnterForeground {
    NSLog(@"willEnterForeground");

    if (!self.mp)
        return;
    if(self.mp.moviePlayer.playbackState == MPMoviePlaybackStateInterrupted || self.mp.moviePlayer.playbackState == MPMoviePlaybackStateStopped || self.mp.moviePlayer.playbackState == MPMoviePlaybackStatePaused)
    {
        [self continuePlayback];
    }
}

- (void)continuePlayback {
    NSLog(@"%f", self.mp.moviePlayer.duration);
    NSLog(@"%f", playbackTime);
    [self.mp.moviePlayer stop];
    self.mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[self.videos objectForKey:@"medium"]]] ;
    [self.mp.moviePlayer setInitialPlaybackTime:playbackTime];
    [self.mp.moviePlayer play];
    [self presentModalViewController:self.mp animated:YES];
}

它可以工作,但需要权衡取舍: 当我重新初始化它时,它丢失了流视频部分.用户需要再次等待流式传输.

It works, but with some trade off: As I re-init it, it lost the streamed video part. Users need to wait for streaming again.

这是我的问题:

  1. 当应用程序处于运行状态时,是否有一种方法可以继续流式传输Youtube的视频 在后台?
  2. 或如何保留流式传输的部分?
  1. Is there a way that keep streaming Youtube's video when the app is in background?
  2. or how to keep the streamed part?

如果我跳过这一行,它将从视频的开头开始播放:

It would play from the beginning of the video if I skip the line:

self.mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[self.videos objectForKey:@"medium"]]] ;

在continuePlayBack方法中,或者我使用setCurrentPlayBackTime而不是setInitPlayBackTime.

in continuePlayBack method or I setCurrentPlayBackTime instead of setInitPlayBackTime.

推荐答案

您发现的内容完全正常-很奇怪,但是很正常. MPMoviePlayerController仅在用于新实例时才尊重initialPlaybackTime.实际上,我确实敦促您针对该问题提交错误报告,因为该问题早已存在(iOS3),但尚未修复.

What you have discovered there is perfectly normal - weird, but normal. MPMoviePlayerController does only respect the initialPlaybackTime when being used on a fresh instance. I do actually urge you to file a bug-report on that issue as it is known since ages (iOS3) but not fixed.

无法保持缓冲区状态,并且您草拟的解决方案与我在许多应用程序中使用的解决方案几乎相同.

There is no way to keep the buffer state and the solution you have drafted is pretty much the same that I am using in many apps.

现在直接回答您的问题;

Now directly answering your questions;

re 1)是和否.如您所知,Apple对UIBackgroundModes的使用确实非常苛刻.尽管他们明确建议使用它来实现不间断的AirPlay流(视频和音频内容),但是当他们播放视频时,他们仍然会拒绝应用程序.我还认为苹果的审核团队方面出现了史诗般的失败.您可能想尝试抗拒他们的拒绝,请引用他们自己的文档:

re 1) Yes and no. As you have discovered yourself, Apple did get very harsh on the UIBackgroundModes usage. Even though they clearly recommend using it for achieving uninterrupted AirPlay streaming (of video and audio content), they still reject apps when all they do is playing a video. That I also consider an epic failure on Apple's review team side. You might want to try to fight their rejection, quoting their own documentation:

重要:UIBackgroundModes音频键将允许应用流式播放 使用AirPlay在后台播放音频或视频内容.

Important: The UIBackgroundModes audio key will allow apps to stream audio or video content in the background using AirPlay.

来自: http://developer.apple.com/library /ios/#qa/qa1668/_index.html

关于2)否(请参阅介绍性回答文字)

re 2) No (see introductional answer text)

让我也从另一个角度解决这个问题...

Let me also tackle the issue from a different side...

如果您的问题实际上是在iOS5上通过AirPlay流式传输时设备进入睡眠模式的事实.然后,实际上有至少一种可行的解决方法-即使它像地狱一样令人讨厌...

If your problem actually is the fact that on iOS5 the device is going into sleep mode while streaming via AirPlay. Then, there is actually one possible workaround that at least works - even though it is nasty as hell...

您可以注册MPMoviePlayerIsAirPlayVideoActiveDidChangeNotification并检查挂钩方法中的airPlayVideoActive.一旦启用AirPlay,只需设置[UIApplication sharedApplication].idleTimerDisabled = YES;即可防止空转.请记住,一旦AirPlay变为非活动状态,请执行相反操作.所有这些仅应在iOS5上需要,因为iOS6修复了AirPlay处于活动状态时的空转问题.

You can register for MPMoviePlayerIsAirPlayVideoActiveDidChangeNotification and check the airPlayVideoActive within the hooked method. Once AirPlay is active, just prevent idling by setting [UIApplication sharedApplication].idleTimerDisabled = YES; Remember to do the reverse once AirPlay became inactive. All of this should only be needed on iOS5 as iOS6 fixed the idling issue while AirPlay is active.

这篇关于MPMoviePlayerViewController在进入YouTube后台后播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆