Calling AVMIDIPlayer from pyobjus

11 views
Skip to first unread message

Ricardo Ospina

unread,
Jul 22, 2020, 5:49:23 AM7/22/20
to Kivy development
I'm trying to play some MIDI files in iOS. I checked out the pyobjus INCLUDE, but this doesn't have any for that, since their MIDI options (CoreAudioKit, CoreMIDI and CoreMIDIServer) are for connectivity between devices.

Apparently AVMIDIPlayer is the way to achieve it.


My first attempt was:

from pyobjus import autoclass

mPlayer = autoclass('AVMIDIPlayer')
mPlayer.init(contentsOf='sequence.mid', soundBankURL='sgpn.sf2')
mPlayer.prepareToPlay()
mPlayer.play()

But I got this error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[AVMIDIPlayer<0x1135835b8> init]: cannot init a class object.'

*** First throw call stack:

(

0   CoreFoundation                      0x0000000109d361bb __exceptionPreprocess + 331

1   libobjc.A.dylib                     0x00000001092d4735 objc_exception_throw + 48

2   CoreFoundation                      0x0000000109d555cf +[NSObject(NSObject) init] + 127

3   riedfull                            0x0000000104ae7034 ffi_call_unix64 + 76

4   ???                                 0x00006000025dba00 0x0 + 105553155963392

)

libc++abi.dylib: terminating with uncaught exception of type NSException



Then, I reduced the code to:


from pyobjus import autoclass

mPlayer = autoclass('AVMIDIPlayer', contentsOf='sequence.mid', soundBankURL='sgpn.sf2')
mPlayer.prepareToPlay()
mPlayer.play()

But I got this new error, which confused me because that is described in the link above.

AttributeError: 'AVMIDIPlayer' object has no attribute 'prepareToPlay'


And surely you can image what happened when I removed the line with prepareToPlay. If not, the error was


AttributeError: 'AVMIDIPlayer' object has no attribute 'play'


Any idea about how can I do this?

Reply all
Reply to author
Forward
0 new messages