brownemint / Ti-Android-CameraView

MIT License
23 stars 15 forks source link

addEventListener("picture_taken") not being called anymore since 0.6 #5

Closed orangemechanic closed 9 years ago

orangemechanic commented 9 years ago

function refreshPictureSuccess(e){ alert("Image "+e.path); } camera_view.addEventListener("picture_taken", refreshPictureSuccess);

the Alert is never called when camera_view.snapPicture(); is fired.

in the console, it return this:

[INFO] : CameraViewProxy: (main) [2817,21127] Front Camera Property exists! [INFO] : CameraViewProxy: (main) [62,21189] Opening Camera [INFO] : Camera: sendBroadcast intent.stop.app-in-app [INFO] : CameraViewProxy: (main) [168,21357] Setting Preview Display [INFO] : CameraViewProxy: (main) [14,21371] Starting Preview [INFO] : CameraViewProxy: (main) [7705,29076] Picture Orientation is 1 [INFO] : CameraViewProxy: (main) [1,29077] Device Orientation is 0 [INFO] : I/dalvikvm-heap: Grow heap (frag case) to 37.699MB for 1228816-byte allocation [INFO] : I/dalvikvm-heap: Grow heap (frag case) to 38.833MB for 1228816-byte allocation [INFO] : CameraViewProxy: (main) [680,29757] Sending path back to Titanium. Image Path > file:///storage/sdcard0/Pictures/topit/IMG_20150413_142146.jpg

The file is correctly stored... but not returned to Titanium/App

orangemechanic commented 9 years ago

Test done on a Galaxy SII

orangemechanic commented 9 years ago

After narrowing down a bit, the Event is not triggered when you create then remove and re-create an instance of CameraView.

1 At Creation > it works

var camera_view = APP.CAM.createCameraView({ save_location: "topit", width:APP.CORE.width, height:APP.CORE.width * camera_ratio, useFrontCamera: true }); $.vwCameraLayer.add(camera_view);

function actionTakePicture(){ camera_view.snapPicture(); }

2 After taking a picture (successful) i remove the CameraView within the picture_taken event

function refreshPictureSuccess(e){ alert("Image "+e.path); $.vwCameraLayer.remove(camera_view); } camera_view.addEventListener("picture_taken", refreshPictureSuccess);

3 Then i click on a button RETAKE to recreate a new CameraView and from there, the event is not more fired as per normal

function actionRetakePicture(){ camera_view = APP.CAM.createCameraView({ save_location: "topit", width:APP.CORE.width, height:APP.CORE.width * camera_ratio, useFrontCamera: true }); $.vwCameraLayer.add(camera_view); }

orangemechanic commented 9 years ago

FALSE ALERT. I've found the stupid but logic parade to fix it.

When you re-create a new CameraView instance, you have to rebind the addEventListener.

brownemint commented 9 years ago

That makes sense. When the camera_view is removed, it is deallocated from memory (or flagged for garbage collection), meaning the old event listener binding is also deallocated.