Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to get values from "ObjCInstanceMethodProxy"
-
Hi
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
title()
as well. -
-
@cvp, first!
-
@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.