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.
ValueError: no Objective-C class named 'MPMusicPlayerController' found
-
I'm trying to access the MPMusicPlayerController using the objc_util and I get the error in the title- ValueError, no objective-c class MPMusicPlayerController found.
I did see a related post but the answer didn't help- dealing with loading the framework.
import webbrowser from objc_util import * def main(): webbrowser.open('music://') mp = ObjCClass('MPMusicPlayerController') player = mp.systemMusicPlayer() player.play() if __name__ == '__main__': main()
-
Does it work if you add this line?
NSBundle.bundleWithPath_('/System/Library/Frameworks/MediaPlayer.framework').load()
(before accessing the
MPMusicPlayerController
class) -
Yeah, I did try that... unfortunately does not work for me. I have iPhone5c and it is up-to-date OS-wise. Just downloaded Pythonista last Sunday and don't believe it requires updating.
I get this error with the above recommendation:
AttributeError: 'NoneType' object has no attribute 'load'
-
Hmm. I'm out of ideas right now, are you sure that there is no typo in the bundle path?
-
Dangit. I usually pride myself on not making those! Yes, there was a typo. Now it works!
In my defense, it IS an iPhone keyboard and an IDE that doesn't underline errors. :) -
Thanks BTW!!! Looks like you are some sort of Admin/creator? Awesome stuff. Now I need to... possibly extend this to be able to run a script on a schedule. Idea being to play music on a timer each morning. Any ideas?
-
@davidj1810 Yes, omz is the creator of Pythonista. (In the App Store I think the developer name is "omz:software", that might give you a hint.
;)
)As far as I know it's not easily possible to use Pythonista as an "alarm clock", because the app cannot run in the background forever. Background Apps are only "kept alive" if they play music or use the microphone and such, all other apps are at the mercy of iOS and will be stopped when the resources are needed elsewhere. The only reliable way to keep Pythonista running is to use
console.set_idle_timer_disabled(True)
to prevent the device from going into standby, which will drain the battery very quickly.(The beta versions of Pythonista had background audio playing enabled, which made it possible to keep Pythonista running by playing a sound file with no sound. Logically the Apple app review people didn't like that, because Pythonista is not a music app.)
-
you could use the Pythonista xCode template and give yourself whatever permissions you need including background audio and install it on your device.
-
Thanks for your support. I should look into this when I have time.
Improved code for project thus far:
import webbrowser from objc_util import * def main(): try: NSBundle.bundleWithPath_('/System/Library/Frameworks/MediaPlayer.framework').load() webbrowser.open('music://') mp = ObjCClass('MPMusicPlayerController') mq = ObjCClass('MPMediaQuery') query = mq.songsQuery() player = mp.systemMusicPlayer() player.setQueueWithQuery_(query) player.shuffleMode = 2 player.prepareToPlay() player.play() except Exception as e: print str(e) if __name__ == '__main__': main()```