Forum Archive

How to get values from "ObjCInstanceMethodProxy"

weda82

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.

mikael

@weda82, they are method proxies, so you need to call them:

item = player.nowPlayingItem()

You might need to call the title() as well.

cvp

this is ok

    item = player.nowPlayingItem()
    print(item.title())

Édit: crossed with @mikael answer

mikael

@cvp, first!

cvp

@mikael 2nd.........and last 😢

cvp

@weda82 this line is not needed

    #MPMediaItem = ObjCClass('MPMediaItem')
weda82

@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.