使用MusicSequence初始化AVMIDIPlayer [英] AVMIDIPlayer init with MusicSequence

查看:194
本文介绍了使用MusicSequence初始化AVMIDIPlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AVMIDIPlayer具有此初始化程序:

AVMIDIPlayer has this initializer:

initWithData:soundBankURL:error:

这是用于从标准MIDI文件读取的初始化程序的补充.

This is in addition to an initializer for reading from a standard MIDI file.

数据是NSData,我假设它是标准MIDI文件格式.那么,如何获取这些数据?好吧,当前创建MIDI序列的方法是AudioToolbox MusicSequence. (AVAudioEngine甚至有这种类型的成员.)

The data is NSData, which I assumed is in a standard MIDI file format. So, how to get that data? Well, the current way to create a MIDI sequence is the AudioToolbox MusicSequence. (AVAudioEngine even has a member of this type).

MusicSequence具有此转换器:

MusicSequence has this converter:

MusicSequenceFileCreateData (
        MusicSequence            inSequence,
        MusicSequenceFileTypeID  inFileType,
        MusicSequenceFileFlags   inFlags,
        SInt16                   inResolution,
        CFDataRef                *outData
    );

所以我们尝试一下.

var status = OSStatus(noErr)
var data:Unmanaged<CFData>?
status = MusicSequenceFileCreateData (musicSequence,
        MusicSequenceFileTypeID(kMusicSequenceFile_MIDIType),
        MusicSequenceFileFlags(kMusicSequenceFileFlags_EraseFile),
        480, &data)

var ns:NSData = data!.takeRetainedValue()
var error:NSError?
self.mp = AVMIDIPlayer(data: ns, soundBankURL: soundbank, error: &error)

(我之前已经加载了音库). 好消息:确实可以播放MIDI数据. 坏消息:到达序列末尾时,它会崩溃.

(I've loaded the soundbank previously). Good news: That does play the MIDI data. Bad news: Upon reaching the end of the sequence, it crashes.

queue = 'CallbackQueue', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)

两个猜测.平台代码中有一个错误,或者(很可能是)我的代码中有错误.

Two guesses. There is a bug in the platform code, or (more likely) my code.

tl; dr我获取的数据不正确吗?

tl;dr Am I getting the data incorrectly?

推荐答案

为此,我收到了风滚草徽章!

I received the Tumbleweed badge for this!

无论如何,问题在于AVMIDIPlayer的播放功能.如果给它一个nil补全处理程序,它将很高兴并且不会崩溃.如果您确实给它提供了完成处理程序,那么blammo-崩溃.我已经为完成处理程序尝试了关闭和花园变化函数.

Anyway, the problem is the AVMIDIPlayer's play function. If you give it a nil completion handler, it is happy and it won't crash. If you do give it a completion handler, then blammo - crash. I've tried both a closure and a garden variety function for the completion handler.

var completion:AVMIDIPlayerCompletionHandler = {
     println("done")
 }

tl;博士

执行此操作:

midiPlayer.play(nil)

不是这个:

midiPlayer.play(completion)

这篇关于使用MusicSequence初始化AVMIDIPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆