当应用程序进入后台时,AvPlayer暂停并播放问题 [英] AvPlayer Pause and play issues when app goes background

查看:107
本文介绍了当应用程序进入后台时,AvPlayer暂停并播放问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果应用程序变为非活动/活动状态(当出现某些警报或双击主页按钮时),它的工作正常

Its working correctly if the app just become inactive/active(when some alert came or by double clicking on home button)

AVPlayer * player;

AVPlayer *player;

- (void)applicationWillResignActive:(UIApplication *)application
{
[player pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
[player play];
}

如果应用程序转到后台(通过单击主页按钮)并返回,它不是从暂停位置开始而不是从不同点(有时从开始,有时从中间)开始。可能是什么问题?

If the app goes to background(by clicking home button) and comes back, its not playing from paused position instead of that it is playing from different point(sometimes from start, sometimes from middle). What might be the problem?

推荐答案

按照以下步骤操作:

1)首先添加 float * time appDelegate.h 文件中。

1) Firstly add float *time in appDelegate.h file.

2)在 applicationWillResignActive 中获取当前时间

3)添加以下方法

ApplicationWillResignActive method 暂停播放器和保存 当前 时间播放器

ApplicationWillResignActive method pause player and save current time of player

- (void)applicationWillResignActive:(UIApplication *)application
{
   [player pause];
   time = player.currentTime
}

现在 applicationDidBecomeActive add seekToTime

- (void)applicationDidBecomeActive:(UIApplication *)application
{
  [player seekToTime:time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
  [player play];
}

这篇关于当应用程序进入后台时,AvPlayer暂停并播放问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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