AppleScriptObjC:无法创建AVMIDIPlayer对象

时间:2018-03-27 14:47:53

标签: applescript applescript-objc

我在使用一些AppleScript ObjC代码时遇到了一些麻烦。问题行似乎是在我初始化AVMIDIPlayer对象时(重复的第3行)。它返回-1错误,(AVAudioEngineManualRenderingStatusError)。然后下一行失败,因为Nil对象没有任何方法。

以下是相关位:

property NSURL : a reference to current application's NSURL
property AVMIDIPlayer : a reference to current application's AVMIDIPlayer
on open (filelist)
    repeat with each_item in filelist
        set myfile to quoted form of POSIX path of each_item as string
        set myMIDIFile to (NSURL's fileURLWithPath:myfile)
        set {myMIDIPlayer, theError} to (AVMIDIPlayer's alloc()'s initWithContentsOfURL:myMIDIFile soundBankURL:none |error|:(reference))
        myMIDIPlayer's prepareToPlay()
        myMIDIPlayer's play(myHandler)

1 个答案:

答案 0 :(得分:0)

问题的原因是quoted form of

do shell script行中仅使用 来转义包含空格和特殊字符的字符串,而不是其他地方。

set myfile to POSIX path of each_item -- no coercion: POSIX path is string

并处理theError