Skip to content

Instantly share code, notes, and snippets.

@lukaskollmer
Created May 12, 2016 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaskollmer/3a04ea02a410e26c9b2f6a74c2f214a8 to your computer and use it in GitHub Desktop.
Save lukaskollmer/3a04ea02a410e26c9b2f6a74c2f214a8 to your computer and use it in GitHub Desktop.
Pythonista media picker example
# coding: utf-8
import console
from objc_util import *
console.clear()
importFramework('MediaPlayer')
MPMediaPickerController = ObjCClass('MPMediaPickerController')
def mediaPicker_didPickMediaItems_(_self, _cmd, _picker, _items):
ObjCInstance(_picker).dismissViewControllerAnimated_completion_(True, None)
print(ObjCInstance(_items))
def mediaPickerDidCancel_(_self, _cmd, _picker):
ObjCInstance(_picker).dismissViewControllerAnimated_completion_(True, None)
@on_main_thread
def main():
rootVC = UIApplication.sharedApplication().keyWindow().rootViewController()
tabVC = rootVC.detailViewController()
MediaPickerDelegate = create_objc_class('MediaPickerDelegate', methods=[mediaPicker_didPickMediaItems_, mediaPickerDidCancel_], protocols=['MPMediaPickerControllerDelegate'])
mediaPicker = MPMediaPickerController.new()
mediaPicker.setDelegate_(MediaPickerDelegate.new())
tabVC.presentViewController_animated_completion_(mediaPicker, True, None)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment