How to get values from "ObjCInstanceMethodProxy"
I am trying to get the currently played item from Apples Music App. My code looks like this:
from objc_util import * def main(): NSBundle.bundleWithPath_( '/System/Library/Frameworks/MediaPlayer.framework').load() MPMusicPlayerController = ObjCClass('MPMusicPlayerController') MPMediaItem = ObjCClass('MPMediaItem') player = MPMusicPlayerController.systemMusicPlayer() item = player.nowPlayingItem print(item) print(item.title) main()
My problem is, that I do not know how to get values from "nowPlayingItem". I get this exception:
print(item.title) AttributeError: 'ObjCInstanceMethodProxy' object has no attribute 'title'
I am thankful for any hints.
@weda82, they are method proxies, so you need to call them:
item = player.nowPlayingItem()
You might need to call the
this is ok
item = player.nowPlayingItem() print(item.title())
Édit: crossed with @mikael answer
@mikael 2nd.........and last 😢
@weda82 this line is not needed
#MPMediaItem = ObjCClass('MPMediaItem')
@mikael Thanks for your reply.
You are right. I was missing the brackets at "nowPlayingItem". I already had them for title, but you need both.