gpt4 book ai didi

iphone - 在 iOS 6.0 中,视频从应用程序后台播放到前台需要 2 秒从暂停到播放滞后

转载 作者:搜寻专家 更新时间:2023-10-30 20:20:25 24 4
gpt4 key购买 nike

我有播放视频的 VideoController。现在 VideoController 被推送到 navigationController 中。

 VideoController *ObjVideoController = [[VideoController alloc] init];
ObjVideoController.strVideoURL = [AnimationArr objectAtIndex:SequenceCount];
[self.navigationController pushViewController:ObjVideoController animated:NO];
[ObjVideoController play:[AnimationArr objectAtIndex:SequenceCount]];
VideoController中的

Play方法是这样的:

 - (void)play:(NSString*)videoFile {
playbaktime = 0.0;

NSBundle *main = [NSBundle mainBundle];
NSURL *url = [NSURL fileURLWithPath:[[main resourcePath] stringByAppendingPathComponent:videoFile]];

if (!self.ctl)
{
self.ctl = nil;
self.ctl = [[MPMoviePlayerController alloc]init];
[self.view addSubview:self.ctl.view];
}
[self.ctl prepareToPlay];
self.ctl.contentURL = url;
self.ctl.controlStyle = 0;
//self.ctl.useApplicationAudioSession = NO;
[self.ctl.view setUserInteractionEnabled:NO];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
[self.ctl.view setFrame:CGRectMake(0,0,480,320)];
else
[self.ctl.view setFrame:CGRectMake(0,0,1024,768)];

self.ctl.backgroundView.backgroundColor = [UIColor whiteColor];
[self.ctl play];
}

现在 observer 已添加到 UIApplicationWillResignActiveUIApplicationDidBecomeActive。它的选择器如下:

 -(void)Pause_Video:(NSNotification*)notification {
Pausevideo = 1;
playbaktime = self.ctl.currentPlaybackTime;
[self.ctl pause];
}

-(void)Play_Video:(NSNotification*)notification {

if(self.ctl.loadState == MPMovieLoadStateUnknown)
{
[self play:self.strVideoURL];
Pausevideo = 0;
}
else{
if (self.ctl.playbackState == MPMoviePlaybackStatePaused) {
[self.ctl play];
Pausevideo = 0;
}
else
{
[self.ctl setInitialPlaybackTime:playbaktime];
[self.ctl play];
Pausevideo = 0;
}
}
}

希望您能理解问题并提供帮助。

最佳答案

你好像每次播放前都在调用prepareToPlay,这个不是必须的,加载文件的时候调用一次就好了。暂停后无需调用。

此外,您会遇到延迟,因为通知不会立即触发。具体来说,UIApplicationDidBecomeActive 仅在应用程序进入前台后才会触发。相反,您想要的是观察 UIApplicationWillEnterForegroundNotification,它会在应用进入前台时触发,并允许您显着减少延迟。

关于iphone - 在 iOS 6.0 中,视频从应用程序后台播放到前台需要 2 秒从暂停到播放滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13065680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com