swift - MusicSequenceFileLoad 在 Playgrounds 中有效,但在 Project 中无效

标签 swift xcode audiotoolbox

我做错了什么?

我正在尝试打开一个 MIDI 文件并读取其内容。到目前为止,我可以在 Playground 中打开文件,但我的项目中出现“Open::fopen failed”

override func viewDidLoad() {
    super.viewDidLoad()

    let path = NSURL.fileURL(withPath: "/users/me/file.mid")
    var midfile: MusicSequence?
    NewMusicSequence(&midfile)

    MusicSequenceFileLoad(midfile!, path as CFURL, .midiType , .smf_ChannelsToTracks)
}

我确实导入了 AudioToolbox 和 CoreMIDI

编辑:一些进展 我可以使用 CFBundleCopyResourceURL 打开 bundle 中的 midi 文件,但我希望能够从 finder 中的任何位置打开文件

fileManager 也会失败,当在项目内部使用并在 Playground 中使用时它会返回 nil。

最佳答案

想通了。

代码失败,因为应用程序在沙盒中运行并且无法访问 NSURL

关于swift - MusicSequenceFileLoad 在 Playgrounds 中有效,但在 Project 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48729818/

相关文章:

objective-c - 使用ARC在IOS5中设置和播放系统声音

ios - 将 UIView 添加到 tableFooterView 时 UITableView 抛出异常

swift - 不将任何内容传递到 @binding 属性中

ios - 从纵向模式转为横向模式时,屏幕上的图像位置不佳?

swift - 将 ImageView 保持在 ScrollView 范围之外。 Xcode、 swift

iphone - 为什么此音频单元RemoteIO初始化可在iPhone上但不能在模拟器中使用?

macos - OSX CoreAudio 麦克风输入静音与将音量设置为 0.0f

ios - NSKeyedArchiver: key 返回 nil - Swift

ios - 如何将数据存储到 Firestore 中具有相同 ID 的多个集合?

swift - 如何使用 playerViewController 快速循环播放我的视频?