Created
July 6, 2015 21:40
-
-
Save kived/9e37002da7994329fb10 to your computer and use it in GitHub Desktop.
Kivy: Flash example fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.switch import Switch | |
from jnius import autoclass | |
Camera = autoclass('android.hardware.Camera') | |
Parameters = autoclass('android.hardware.Camera$Parameters') | |
__version__ = '0.1' | |
class FlashApp(App): | |
def build(self): | |
self.root = Switch(text='enlightenme') | |
self.root.bind(active=self.toggle_flash) | |
self.camera = None | |
return self.root | |
def toggle_flash(self, *args): | |
if self.camera == None: | |
self.camera = Camera.open() | |
p = self.camera.getParameters() | |
if self.root.active: | |
p.setFlashMode(Parameters.FLASH_MODE_TORCH) | |
self.camera.setParameters(p) | |
self.camera.startPreview() | |
else: | |
p.setFlashMode(Parameters.FLASH_MODE_OFF) | |
self.camera.stopPreview() | |
self.camera.setParameters(p) | |
self.camera.release() | |
self.camera = None | |
if __name__ == '__main__': | |
FlashApp().run() |
thanks for this
Thanks too much 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OMG THANK YOU SO MUCH. I new to Kivy and Pyjnius and i've been trying to access flash for the whole day and none of the code works. I can't tell you how happy i'm to found this code. THANK YOU!