如何在iPhone上播放MIDI?

发布于 2024-08-27 09:08:54 字数 73 浏览 6 评论 0原文

据我所知,没有本地或第三方库可用于在 iPhone 上播放 MIDI。但似乎有不少应用程序可以做到这一点。他们用什么?有什么线索吗?

As far as I know, there is not native or third party library available to play MIDI on the iPhone. But there seem to be quite a few apps that do exactly that. What are they using? Any clues?

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

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

发布评论

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

评论(3

孤云独去闲 2024-09-03 09:08:54

供那些走这条路的人参考:AVMIDIPlayer 是在 iOS 8 中引入的。似乎在设备上运行良好,但 sim 不太好。

FYI for those going down this road: AVMIDIPlayer was introduced in iOS 8. Seems to work well on device, sim not so much.

缪败 2024-09-03 09:08:54

这对我在 iPhone 上播放 midi 文件有用:

import AVFoundation

class MidiPlayer: NSObject {
    static let shared = MidiPlayer()
    var musicPlayer: MusicPlayer?
    var sequence: MusicSequence?

    func play(file: String) {
        guard let midiFile = Bundle.main.url(forResource: file, withExtension: "mid") else {
            return
        }

        NewMusicPlayer(&musicPlayer)
        NewMusicSequence(&sequence)

        if let musicPlayer = musicPlayer, let sequence = sequence {
            MusicSequenceFileLoad(sequence, midiFile as CFURL, .midiType, MusicSequenceLoadFlags())
            MusicPlayerSetSequence(musicPlayer, sequence)
            MusicPlayerStart(musicPlayer)
        }
    }

    func stop() {
        if let musicPlayer = musicPlayer {
            MusicPlayerStop(musicPlayer)
        }
    }
}

然后 MidiPlayer.shared.play(file: "midifile")

This worked for me for playing midi file on iPhone:

import AVFoundation

class MidiPlayer: NSObject {
    static let shared = MidiPlayer()
    var musicPlayer: MusicPlayer?
    var sequence: MusicSequence?

    func play(file: String) {
        guard let midiFile = Bundle.main.url(forResource: file, withExtension: "mid") else {
            return
        }

        NewMusicPlayer(&musicPlayer)
        NewMusicSequence(&sequence)

        if let musicPlayer = musicPlayer, let sequence = sequence {
            MusicSequenceFileLoad(sequence, midiFile as CFURL, .midiType, MusicSequenceLoadFlags())
            MusicPlayerSetSequence(musicPlayer, sequence)
            MusicPlayerStart(musicPlayer)
        }
    }

    func stop() {
        if let musicPlayer = musicPlayer {
            MusicPlayerStop(musicPlayer)
        }
    }
}

and then MidiPlayer.shared.play(file: "midifile")

看透却不说透 2024-09-03 09:08:54

查看 MusicPlayer 类。结合自 iOS 5.0 起可用的 AUSampler 音频单元,您可以非常轻松地构建 MIDI 播放器。 (该链接适用于 OS X,但也适用于 iOS)

https://developer.apple.com/library/mac/#documentation/MusicAudio/Conceptual/CoreAudioOverview/ARoadmaptoCommonTasks/ARoadmaptoCommonTasks.html#/ /apple_ref/doc/uid/TP40003577-CH6-SW13

关于采样器音频单元请参阅:
适用于 iOS 的简单嵌入式 MidiSynth?

Check out the MusicPlayer class. Combined with the AUSampler audio unit available since iOS 5.0 you can build a MIDI player quite easily. (The link is OS X, but it applies for iOS as well)

https://developer.apple.com/library/mac/#documentation/MusicAudio/Conceptual/CoreAudioOverview/ARoadmaptoCommonTasks/ARoadmaptoCommonTasks.html#//apple_ref/doc/uid/TP40003577-CH6-SW13

About the sampler audio unit see:
Simple embeddable MidiSynth for iOS?

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