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
-
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()
-
@cbanta, what is the exception? Install the fault handler to find out.