Skip to content

Commit

Permalink
Merge pull request #120 from pspchucky/master
Browse files Browse the repository at this point in the history
add video recoding to Camera facade and camera.py
  • Loading branch information
tito committed Mar 10, 2015
2 parents 50cd83f + c23eb9d commit 5ff6621
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plyer/facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,29 @@ def take_picture(self, filename, on_complete):
:type on_complete: callable
'''
self._take_picture(filename=filename, on_complete=on_complete)
def take_video(self, filename, on_complete):
'''Ask the OS to capture a video, and store it at filename.
When the capture is done, on_complete will be called with the filename
as an argument. If the callback returns True, the filename will be
unlinked.
:param filename: Name of the video file
:param on_complete: Callback that will be called when the operation is
done
:type filename: str
:type on_complete: callable
'''
self._take_video(filename=filename, on_complete=on_complete)

# private

def _take_picture(self, **kwargs):
raise NotImplementedError()

def _take_video(self, **kwargs):
raise NotImplementedError()


class Notification(object):
Expand Down
14 changes: 14 additions & 0 deletions plyer/platforms/android/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ def _take_picture(self, on_complete, filename=None):
parcelable = cast('android.os.Parcelable', uri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
activity.startActivityForResult(intent, 0x123)

def _take_video(self, on_complete, filename=None):
assert(on_complete is not None)
self.on_complete = on_complete
self.filename = filename
android.activity.unbind(on_activity_result=self._on_activity_result)
android.activity.bind(on_activity_result=self._on_activity_result)
intent = Intent(MediaStore.ACTION_VIDEO_CAPTURE)
uri = Uri.parse('file://' + filename)
parcelable = cast('android.os.Parcelable', uri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1) #0 = low quality, suitable for MMS messages, 1 = high quality
#intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, X) #Optional, allows limiting record time to X seconds.
activity.startActivityForResult(intent, 0x123)

def _on_activity_result(self, requestCode, resultCode, intent):
if requestCode != 0x123:
Expand Down

0 comments on commit 5ff6621

Please sign in to comment.