访问 iPod 库以与 AVAudioPlayer 一起使用或使用 AVPlayer 进行远程控制事件

发布于 2025-01-08 06:52:36 字数 1104 浏览 0 评论 0原文

我在这里读过很多帖子,但还没有找到合适的。 解释得很好 AVAudioPlayer 无法播放 iPod 库中的文件,但这是否意味着完全没有办法呢?

AVPlayer 允许您执行此操作,但我的问题是您无法在后台接收远程控制事件。这是我到目前为止所读到的内容,但奇怪的是:我在 App Store 中遇到了几个应用程序,它们允许您访问 iPod 库并在应用程序中和后台播放音乐。它不使用 MPMusicPlayerController,因为它不使用音乐应用来播放歌曲,也不会在进入后台时停止(该应用的图标也出现在多任务栏中)。此外,您可以在应用程序进入后台后对其进行控制(播放/暂停/下一个/上一个/卷等)。此应用的音量以某种方式与 iPod 音乐播放器的音量“同步”,我只能假设它已使用 MPMusicPlayerControllerVolumeDidChangeNotification 注册了音量更改通知。

我的问题是: 1. 他们是如何做的以及他们使用什么类?如果他们正在访问 iPod 库,那么它必须是 AVPlayer。但是您无法使用 AVPlayer 接收远程控制事件(playerItemDidReachEnd 除外),因此它必须是 AVAudioPlayer。但您无法使用 AVAudioPlayer 播放 iPod 库 2. 他们如何能够使用 iPod 库中的音量设置,以及如何保持其“同步”。

此帖子答案声称可以访问 iPod具有 AVPlayer 的库并且仍然接收外部事件/通知。这是怎么样?他是否只是注册您通常使用 AVAudioPlayer 类执行的事件?

对此非常困惑。希望得到一些指导。

I've read many threads on here and haven't yet come across the right one. It's been explained very well that AVAudioPlayer cannot play files from the iPod Library, but does this mean that there's no way at all?

AVPlayer allows you to do this but my issue with it is that you cannot receive remote control events in the background. This is from what I've read so far, but here's the odd thing: I've come across a couple of apps in the App Store that allow you to access your iPod library and play your music in the app, and in the background. It does not use MPMusicPlayerController as it doesn't use the Music app to play songs nor does it stop when entering the background (the app's icon also appears in the multitasking bar). Furthermore you are able to control the app once it's in the background (play/pause/next/prev/vol etc.). This app's volume is somehow 'synched' with the iPod music player volume and I can only assume that it has registered notifications for volume change with MPMusicPlayerControllerVolumeDidChangeNotification.

My questions are:
1. How are they doing it and what class are they using? If they are accessing the iPod library, then it must be AVPlayer. But you cannot receive remote control events with AVPlayer (apart from playerItemDidReachEnd) and so it must be AVAudioPlayer. But you cannot play your iPod library with AVAudioPlayer
2. How are they able to use the volume setting in the iPod library, and how are they keeping it 'synched'.

This thread answer claims that it is possible to access the iPod library with AVPlayer and still receive external events/notifications. How is this? Is he just registering events that you would normally do so with the AVAudioPlayer class?

Very confused about this. Would appreciate some guidance.

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

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

发布评论

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

评论(2

赏烟花じ飞满天 2025-01-15 06:52:36

对于任何寻找答案的人,我找到了一个很棒的教程就在这里这几乎让你走上了正确的道路。您必须使用 AVPlayer,但创建音频会话的方式与使用 AVAudioPlayer 的方式相同。此外,您需要启用远程事件并将主视图控制器设置为第一响应者。教程中对此进行了很好的解释。

For anyone looking for an answer, I found a great tutorial right here that pretty much sets you on the right path. You have to use AVPlayer but create an Audio Session the same way you would with AVAudioPlayer. Furthermore you need to enable remote events and set your main view controller as the first responder. It's very well explained in the tutorial.

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