AVAudioPlayer 和 AirPlay - 可能吗?
我试图确定是否可以使用 AVAudioPlayer
类切换 AirPlay 支持。
据我读到:
AirPlay 是一项技术,可让您的应用程序将音频流式传输到 Apple TV 以及第三方 AirPlay 扬声器和接收器。 AirPlay 支持内置于
AV Foundation
框架和Core Audio
系列框架中。您使用这些框架播放的任何音频内容都会自动符合 AirPlay 分发的条件。一旦用户选择使用 AirPlay 播放音频,系统就会自动路由音频。 [ 参考]
基于此信息;它应该与AVAudioPlayer一起工作,因为它是AVFoundation
框架的一部分;但我似乎找不到任何支持这一假设的文档。
我还发现一些文档说可以使用 MPMoviePlayerViewController 来完成:
MPMoviePlayerController 类中包含对使用 AirPlay 播放视频的支持。此支持允许您在支持 AirPlay 的硬件(例如 Apple TV)上播放基于视频的内容。当活动
MPMoviePlayerController
对象的allowsAirPlay
属性设置为YES
并且设备位于支持 AirPlay 的硬件范围内时,电影播放器会呈现用户可以控制将视频发送到该硬件。 [ 参考]
似乎这里有一些相互矛盾的信息。有谁知道是否可以使用 AVAudioPlayer
路由到 AirPlay 或者我们是否被迫使用 MPMoviePlayerController
类?
非常感谢。
I'm trying to ascertain whether it's possible to toggle AirPlay support using the AVAudioPlayer
class.
From what I have read:
AirPlay is a technology that lets your application stream audio to Apple TV and to third-party AirPlay speakers and receivers. AirPlay support is built in to the
AV Foundation
framework and theCore Audio
family of frameworks. Any audio content you play using these frameworks is automatically made eligible for AirPlay distribution. Once the user chooses to play your audio using AirPlay, it is routed automatically by the system. [ Ref ]
Based on this info; it should work with AVAudioPlayer as it is part of the AVFoundation
framework; but I can't seem to find any documentation supporting this assumption.
I have also found some documentation saying it can be done with MPMoviePlayerViewController
:
Support for playing video using AirPlay is included in the
MPMoviePlayerController
class. This support allows you to play video-based content on AirPlay–enabled hardware such as Apple TV. When theallowsAirPlay
property of an activeMPMoviePlayerController
object is set toYES
and the device is in range of AirPlay–enabled hardware, the movie player presents the user with a control for sending the video to that hardware. [ Ref ]
Seems like there is some conflicting information here. Does anyone know if its possible to use AVAudioPlayer
to route to AirPlay or are we forced to use the MPMoviePlayerController
class?
Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
回答我自己的问题。看起来简单的方法是添加自定义音量控制器,如下所示:[ ref ],它将与
MPAudioPlayer
完美配合。这只是定位的问题。In response to my own question. It looks like the simple way is to add the custom volume controller is mentioned here: [ ref ], and it will work perfectly with the
MPAudioPlayer
. Its just a matter of positioning it.使用 Interface Builder 非常简单,因此您可以轻松使用自动布局。将 UIView 对象放置在主视图上的任何位置,然后创建 MPVolumeView 的子类,并为您的 UIView 对象使用此自定义类
类 VolumeView 是 MPVolumeView 的子类
}
Its pretty easy with Interface Builder so you can easily utilize Auto Layout. Place anywhere you want an UIView object onto your main view then create a subclass of MPVolumeView and use this custom class for your UIView object
and the class VolumeView subclass of MPVolumeView
}
是的,AVAudioPlayer 可与 AirPlay 配合使用。然而,有一个怪癖,像audioPlayerDidFinishPlaying这样的事件是延迟校正的(即从你的应用程序的角度来看,它们发生了2秒“太晚了”),如果你依赖它们与其他机制以正确的顺序发生,这可能是一个问题在你的应用程序中。
Yes, AVAudioPlayer works with AirPlay. However, there's a quirk that events like audioPlayerDidFinishPlaying are latency-corrected (i.e. from the viewpoint of your app, they occur 2 seconds "too late"), which may be a problem if you rely on them happening in the correct order with other mechanics in your app.