omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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"

    Pythonista
    ios12 pythonista 3
    3
    7
    3973
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • weda82
      weda82 last edited by

      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 cvp 2 Replies Last reply Reply Quote 0
      • mikael
        mikael @weda82 last edited by

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

        item = player.nowPlayingItem()
        

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

        1 Reply Last reply Reply Quote 0
        • cvp
          cvp last edited by cvp

          this is ok

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

          Édit: crossed with @mikael answer

          mikael 1 Reply Last reply Reply Quote 0
          • mikael
            mikael @cvp last edited by

            @cvp, first!

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @mikael last edited by

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

              1 Reply Last reply Reply Quote 0
              • cvp
                cvp @weda82 last edited by

                @weda82 this line is not needed

                    #MPMediaItem = ObjCClass('MPMediaItem')
                
                1 Reply Last reply Reply Quote 0
                • weda82
                  weda82 last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors