Forum Archive

Display photos and other media

gumbyman

Hi. Does anyone know a good way to display photos or video from the iPad Photo app in Pythonista? I have created a folder in Photos but am unsure how to point to it using the Image module. Alternatively, is there a way of storing JPEG’s etc. within Pythonista? It would also be nice to play some sound files. Does anyone have any ideas regarding either of these? Thanks.

dgelessus

For reading from and writing to the iOS Photos library, you can use Pythonista's photos module. For example you can use photos.pick_image() to select a single image using the standard image picker, which is returned as a PIL image. If you want to automatically get all images from an album, you can use photos.get_albums() to access the list of albums in your library. Each album has an assets attribute, which contains Asset objects for each photo/video in the album. To convert an Asset to a PIL image, you can use the get_image() method.

You can also manually import assets from the Photos library into Pythonista as files: in the file browser, tap on the "+", then "Import...", then "Photo Library".

For playing sound, Pythonista has a sound module. The interface is pretty straightforward, you use sound.play_effect("path/to/sound/file") to play a file.

Pythonista also comes with some built-in sound effects. To use them, tap the "+" button (on iPad it's in the editor toolbar, on iPhone it floats over the keyboard). This brings up Pythonista's media picker. On the "Sounds" tab, you get a list of built-in sound effects. When you select one, its name is inserted into your code as a string, which you can pass to play_effect to play that sound.

gumbyman

It worked. That was very useful. Thank you