如何在静音模式下开始播放音频&锁定在iOS 6? [英] How do I start playing audio when in silent mode & locked in iOS 6?

查看:97
本文介绍了如何在静音模式下开始播放音频&锁定在iOS 6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 打开应用

  2. 启用静音模式。

  3. 按'锁定按钮'

  4. 应用程序仍然可以在数小时后播放声音,而不是在过渡期间播放任何音频。

  1. Open app
  2. Switch on 'Silent Mode'.
  3. Press 'Lock-button'
  4. App can still START playing a sound after hours have passed, not playing any audio in the interim.



执行此操作的应用程序



许多警报应用已设法执行此操作& amp ;我不认为他们正在使用静音音频来保持应用程序运行,因为如果你真的退出家用应用程序它们不会发出声音。

Apps that do this

A lot of alarm apps have manage to do this & I dont think they are using silent audio to keep the app running as they do not sound if you actually exit the app with home.


  • 闹钟专业版

  • 我的时钟

  • Wave报警

  • 震惊

  • iHome

  • ...

  • Alarm Clock Pro
  • My Clock
  • Wave Alarm
  • Alarmed
  • iHome
  • ...

......他们是否在锁定了一些循环后如何通知(无法在静音中播放声音)启动应用程序备份以播放音频,或者某些其他方法?

...Are they keeping a loop running after being locked some how or it a notification(which cant play sound in silent) starting the app back up to play the audio, or some other method?

AVAudioPlayer使用:

AVAudioPlayer using:

AudioSessionInitialize(nil, nil, nil, nil);
AudioSessionSetActive(YES);

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&sessionCategory);

将Info.plist设置为:

And setting Info.plist to:

所需的背景模式(UIBackGroundModes) - 应用播放音频(音频)

Required background modes(UIBackGroundModes) - App plays audio (audio)

我可以播放音频即使在应用程序运行和屏幕上的静音时也是如此。如果音频已在运行,则可以使用主页按钮关闭应用程序并运行音频。但是,如果应用程序没有播放音频,并且屏幕被锁定,则所有线程都将被终止并且音频永远不会播放。这些应用程序如何解决这个问题?

I can play audio even in silent when the app is running and on screen. If the audio is already running the app can be closed with home button and audio will run. BUT if the app is not playing audio, and the screen is locked, all threads are killed and audio is never played. How do theses apps manage to work around this?

:一种。使用'beginBackgroundTaskWithExpirationHandler:',无限循环让应用程序无限期运行。

优点:


  • 看起来你可以在很多情况下使这项工作,即使用户按下回家。

缺点:


  • 据我所知,这违反苹果政策。

  • 将使用更多资源

评论:

我几乎已经开始工作了,可能会进行一些调整。这似乎不是所有这些其他警报正在做的事情,因为如果你按回家BTN它们不会继续运行。这表明他们使用了一些方法,允许他们在锁定时运行但不在BG中运行。 (这就是我需要的)

I've almost got this to work and might with some tweaking. This does not seem to be what all these other alarms are doing as they do not keep on running if you press home BTN. Which suggest that they use some method that gives them permission to run while locked but not in the BG. (Which is what I need)

另外,当你问你剩下多少时间跑步时,你得到大约10分钟。通过在那里放置一个无限循环,数字实际上会减少到0,然后在负数中结束几个小时。(测试)我不确定这在现实世界中或在应用程序接受方面会如何表现。

Also, When you ask how much time you have left running you get aprox 10 min. By dropping an infinite loop in there the numbers will actually run down to 0 and then go into the negatives for hours on end.(tested) Im not sure how this would behave in the real world or in terms of app acceptance.

B.使用静音音频循环构成连续音频播放媒体中心

优点:


  • 锁定时工作,并在大多数情况下继续运行。

缺点:


  • 如果被其他媒体中心和其他一些场合打断,可能会失败。

  • 还可以再次申请苹果政策。

评论:

这可以在很多情况下起作用,但到目前为止还不理想。而且就像我再次说的那样,必须有另一种没有记录的方法。

This can work I a lot of situations but is by far not ideal. And since Like I say again, there has to be another method that is not documented.

使用列出的APP进行测试表明他们没有使用这两种方法中的任何一种刚刚描述过。方法'A'似乎更接近,但如果实施则不会表现出这些应用程序的行为方式。

Testing with the listed APPs suggests that they are not using any of the two methods I just described. Method 'A' seems to be closer but if implemented would not behave how these apps behave.

我使用苹果开发者票来获取更多信息,我也将发布任何新的发现。

I used a apple developer ticket to get more info, I'll post any new findings along those means as well.

目前为止,我们非常感谢您的参与。

Any insight is appreciated, and for your participation thus far.

推荐答案

您需要在plist文件中进行一些更改。

You need to make couple of changes in plist file.

ie 1)将所需背景模式设置为应用程序播放音频

i.e. 1) Set Required background mode to App plays audio

2)设置应用程序不在后台运行到YES。

2) set Application does not run in background to YES.

 NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
    [[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

然后,您需要在AppDelege中编写这么多代码

Then, you need to write these much code in AppDelege

现在,您可以在手机屏幕锁定或后台轻松运行音频。

Now, you can easily run audio while phone screen locks or in background.

这篇关于如何在静音模式下开始播放音频&锁定在iOS 6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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