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.


    Listen to MediaPlayer Change Notification in Pythonista

    Pythonista
    mediaplayer objcutil objc
    2
    2
    1485
    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.
    • cbanta
      cbanta last edited by

      How can I listen for MediaPlayer notifications in Pythonista? I've tried this, but Pythonista crashes when the media changes.

      import ui
      import time
      from objc_util import *
      
      NSBundle.bundleWithPath_('/System/Library/Frameworks/MediaPlayer.framework').load()
      MPMusicPlayerController = ObjCClass('MPMusicPlayerController')
      NSNotificationCenter = ObjCClass('NSNotificationCenter')
      
      def gotChange():
      	print('here')
      
      @ui.in_background
      def next():
      	time.sleep(2)
      	sysPlayer.play()
      	sysPlayer.skipToNextItem()
      
      sysPlayer = MPMusicPlayerController.systemMusicPlayer()
      sysPlayer.beginGeneratingPlaybackNotifications()
      center = NSNotificationCenter.defaultCenter()
      block = ObjCBlock(gotChange)
      center.addObserverForName_object_queue_usingBlock_('MPMusicPlayerControllerNowPlayingItemDidChangeNotification', None, None, block)
      next()
      
      mikael 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @cbanta last edited by

        @cbanta, what is the exception? Install the fault handler to find out.

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