AVAudioPlayer 和 AirPlay - 可能吗?

发布于 2024-11-05 07:38:05 字数 1264 浏览 0 评论 0原文

我试图确定是否可以使用 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 the Core 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 the allowsAirPlay property of an active MPMoviePlayerController object is set to YES 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 技术交流群。

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

发布评论

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

评论(3

ま柒月 2024-11-12 07:38:05

回答我自己的问题。看起来简单的方法是添加自定义音量控制器,如下所示:[ 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.

兔小萌 2024-11-12 07:38:05

使用 Interface Builder 非常简单,因此您可以轻松使用自动布局。将 UIView 对象放置在主视图上的任何位置,然后创建 MPVolumeView 的子类,并为您的 UIView 对象使用此自定义类

在此处输入图像描述

类 VolumeView 是 MPVolumeView 的子类

import UIKit
import MediaPlayer
class VolumeView: MPVolumeView {
   convenience init() {
       self.init()
}

override func drawRect(rect: CGRect) {
    self.showsVolumeSlider = false
    self.layer.cornerRadius = 10.0
    self.clipsToBounds = true

}

}

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

enter image description here

and the class VolumeView subclass of MPVolumeView

import UIKit
import MediaPlayer
class VolumeView: MPVolumeView {
   convenience init() {
       self.init()
}

override func drawRect(rect: CGRect) {
    self.showsVolumeSlider = false
    self.layer.cornerRadius = 10.0
    self.clipsToBounds = true

}

}

淡淡離愁欲言轉身 2024-11-12 07:38:05

是的,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.

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