如何让AudioKit从远程URL流式传输音频文件?

问题描述 投票:2回答:2

我正在尝试从iOS应用程序(Swift 4)中的URL播放音频文件。我希望他们在下载时缓冲和播放。我非常喜欢AudioKit,但对于我的生活,我无法弄清楚如何让它读取远程文件。

有什么建议?

ios swift audio-streaming audiokit
2个回答
2
投票

你找不到它,因为它不在那里。我们从未实现过任何流媒体功能。虽然可以添加,但像你这样的一些人会非常高兴。如果您设法解决问题,请考虑提供一些代码。如果您愿意,我们可以在开发期间为您提供AudioKit Slack小组的会员资格。


2
投票

如果您只需要流式传输和播放音频文件,您可以使用AVFoundation.AVPlayer。如果你想将它集成到AudioKit中,那么目前需要更多。

您可以在本地缓存远程文件的URL,然后将该缓存的文件加载到AKPlayer中。显然不是流媒体 - 但它会起作用:

guard let remote = URL(string: "https://www.sample-videos.com/audio/mp3/crowd-cheering.mp3"),
    let data = NSData(contentsOf: remote) else {
    AKLog("Remote failed to load.")
    return
}

let cachedFile = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(remote.lastPathComponent)
try? data.write(to: cachedFile)
let player = AKPlayer(url: cachedFile)

请注意,这只是一个快速的macOS示例 - 您可能希望写入临时目录或其他位置。

© www.soinside.com 2019 - 2024. All rights reserved.