如何在Pythonista中侦听MediaPlayer通知?我试过这个,但当媒体改变时,Python会崩溃。你知道吗
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()
目前没有回答
相关问题 更多 >
编程相关推荐