forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMediaModule.m
1605 lines (1389 loc) · 57.4 KB
/
MediaModule.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#ifdef USE_TI_MEDIA
#import "MediaModule.h"
#import "TiUtils.h"
#import "TiBlob.h"
#import "TiFile.h"
#import "TiApp.h"
#import "Mimetypes.h"
#import "TiViewProxy.h"
#import "Ti2DMatrix.h"
#import "SCListener.h"
#import "TiMediaAudioSession.h"
#import "TiMediaMusicPlayer.h"
#import "TiMediaItem.h"
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <AVFoundation/AVAudioSession.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIPopoverController.h>
// by default, we want to make the camera fullscreen and
// these transform values will scale it when we have our own overlay
#define CAMERA_TRANSFORM_Y 1.23
#define CAMERA_TRANSFORM_Y_ALT 1.67
#define CAMERA_TRANSFORM_X 1
enum
{
MediaModuleErrorUnknown,
MediaModuleErrorBusy,
MediaModuleErrorNoCamera,
MediaModuleErrorNoVideo,
MediaModuleErrorNoMusicPlayer
};
// Have to distinguish between filterable and nonfilterable properties
static NSDictionary* TI_itemProperties;
static NSDictionary* TI_filterableItemProperties;
@implementation MediaModule
@synthesize popoverView;
#pragma mark Internal
+(NSDictionary*)filterableItemProperties
{
if (TI_filterableItemProperties == nil) {
TI_filterableItemProperties = [[NSDictionary alloc] initWithObjectsAndKeys:MPMediaItemPropertyMediaType, @"mediaType", // Filterable
MPMediaItemPropertyTitle, @"title", // Filterable
MPMediaItemPropertyAlbumTitle, @"albumTitle", // Filterable
MPMediaItemPropertyArtist, @"artist", // Filterable
MPMediaItemPropertyAlbumArtist, @"albumArtist", //Filterable
MPMediaItemPropertyGenre, @"genre", // Filterable
MPMediaItemPropertyComposer, @"composer", // Filterable
MPMediaItemPropertyIsCompilation, @"isCompilation", // Filterable
nil];
}
return TI_filterableItemProperties;
}
+(NSDictionary*)itemProperties
{
if (TI_itemProperties == nil) {
TI_itemProperties = [[NSDictionary alloc] initWithObjectsAndKeys:MPMediaItemPropertyPlaybackDuration, @"playbackDuration",
MPMediaItemPropertyAlbumTrackNumber, @"albumTrackNumber",
MPMediaItemPropertyAlbumTrackCount, @"albumTrackCount",
MPMediaItemPropertyDiscNumber, @"discNumber",
MPMediaItemPropertyDiscCount, @"discCount",
MPMediaItemPropertyLyrics, @"lyrics",
MPMediaItemPropertyPodcastTitle, @"podcastTitle",
MPMediaItemPropertyPlayCount, @"playCount",
MPMediaItemPropertySkipCount, @"skipCount",
MPMediaItemPropertyRating, @"rating",
nil ];
}
return TI_itemProperties;
}
-(void)destroyPickerCallbacks
{
RELEASE_TO_NIL(editorSuccessCallback);
RELEASE_TO_NIL(editorErrorCallback);
RELEASE_TO_NIL(editorCancelCallback);
RELEASE_TO_NIL(pickerSuccessCallback);
RELEASE_TO_NIL(pickerErrorCallback);
RELEASE_TO_NIL(pickerCancelCallback);
}
-(void)destroyPicker
{
RELEASE_TO_NIL(popover);
[self forgetProxy:cameraView];
RELEASE_TO_NIL(cameraView);
RELEASE_TO_NIL(editor);
RELEASE_TO_NIL(editorSuccessCallback);
RELEASE_TO_NIL(editorErrorCallback);
RELEASE_TO_NIL(editorCancelCallback);
RELEASE_TO_NIL(musicPicker);
RELEASE_TO_NIL(picker);
RELEASE_TO_NIL(pickerSuccessCallback);
RELEASE_TO_NIL(pickerErrorCallback);
RELEASE_TO_NIL(pickerCancelCallback);
}
-(void)dealloc
{
[self destroyPicker];
RELEASE_TO_NIL(systemMusicPlayer);
RELEASE_TO_NIL(appMusicPlayer);
RELEASE_TO_NIL(popoverView);
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
-(void)dispatchCallback:(NSArray*)args
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *type = [args objectAtIndex:0];
id object = [args objectAtIndex:1];
id listener = [args objectAtIndex:2];
// we have to give our modal picker view time to
// dismiss with animation or if you do anything in a callback that
// attempt to also touch a modal controller, you'll get into deep doodoo
// wait for the picker to dismiss with animation
[NSThread sleepForTimeInterval:0.5];
[self _fireEventToListener:type withObject:object listener:listener thisObject:nil];
[pool release];
}
-(void)sendPickerError:(int)code
{
id listener = [[pickerErrorCallback retain] autorelease];
[self destroyPicker];
if (listener!=nil)
{
NSDictionary *event = [TiUtils dictionaryWithCode:code message:nil];
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"error",event,listener,nil]];
}
}
-(void)sendPickerCancel
{
id listener = [[pickerCancelCallback retain] autorelease];
[self destroyPicker];
if (listener!=nil)
{
NSMutableDictionary * event = [TiUtils dictionaryWithCode:-1 message:@"The user cancelled the picker"];
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"cancel",event,listener,nil]];
}
}
-(void)sendPickerSuccess:(id)event
{
id listener = [[pickerSuccessCallback retain] autorelease];
if (autoHidePicker)
{
[self destroyPicker];
}
if (listener!=nil)
{
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"success",event,listener,nil]];
}
}
-(void)commonPickerSetup:(NSDictionary*)args
{
if (args!=nil) {
pickerSuccessCallback = [args objectForKey:@"success"];
ENSURE_TYPE_OR_NIL(pickerSuccessCallback,KrollCallback);
[pickerSuccessCallback retain];
pickerErrorCallback = [args objectForKey:@"error"];
ENSURE_TYPE_OR_NIL(pickerErrorCallback,KrollCallback);
[pickerErrorCallback retain];
pickerCancelCallback = [args objectForKey:@"cancel"];
ENSURE_TYPE_OR_NIL(pickerCancelCallback,KrollCallback);
[pickerCancelCallback retain];
// we use this to determine if we should hide the camera after taking
// a picture/video -- you can programmatically take multiple pictures
// and use your own controls so this allows you to control that
// (similarly for ipod library picking)
autoHidePicker = [TiUtils boolValue:@"autohide" properties:args def:YES];
animatedPicker = [TiUtils boolValue:@"animated" properties:args def:YES];
}
}
-(void)displayCamera:(UIViewController*)picker_
{
TiApp * tiApp = [TiApp app];
if ([TiUtils isIPad]==NO)
{
[[tiApp controller] manuallyRotateToOrientation:UIInterfaceOrientationPortrait duration:[[tiApp controller] suggestedRotationDuration]];
}
[tiApp showModalController:picker_ animated:animatedPicker];
}
-(void)displayModalPicker:(UIViewController*)picker_ settings:(NSDictionary*)args
{
TiApp * tiApp = [TiApp app];
if ([TiUtils isIPad]==NO)
{
[[tiApp controller] manuallyRotateToOrientation:UIInterfaceOrientationPortrait duration:[[tiApp controller] suggestedRotationDuration]];
[tiApp showModalController:picker_ animated:animatedPicker];
}
else
{
RELEASE_TO_NIL(popover);
UIView *poView = [[[tiApp controller] topWindow] view];
CGRect poFrame;
TiViewProxy* popoverViewProxy = [args objectForKey:@"popoverView"];
UIPopoverArrowDirection arrow = [TiUtils intValue:@"arrowDirection" properties:args def:UIPopoverArrowDirectionAny];
if (popoverViewProxy!=nil)
{
poView = [popoverViewProxy view];
poFrame = [poView bounds];
}
else
{
arrow = UIPopoverArrowDirectionAny;
poFrame = [poView bounds];
poFrame.size.height = 50;
}
if ([poView window] == nil) {
// No window, so we can't display the popover...
DebugLog(@"[WARN] Unable to display picker; view is not attached to the current window");
return;
}
//FROM APPLE DOCS
//If you presented the popover from a target rectangle in a view, the popover controller does not attempt to reposition the popover.
//In thosecases, you must manually hide the popover or present it again from an appropriate new position.
//We will register for interface change notification for this purpose
//This registration tells us when the rotation begins.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(manageRotation:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
//This registration lets us sync with the TiRootViewController's orientation notification (didOrientNotify method)
//No need to begin generating these events since the TiRootViewController already does that
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePopover:) name:UIDeviceOrientationDidChangeNotification object:nil];
arrowDirection = arrow;
popoverView = poView;
popover = [[UIPopoverController alloc] initWithContentViewController:picker_];
[popover setDelegate:self];
[popover presentPopoverFromRect:poFrame inView:poView permittedArrowDirections:arrow animated:animatedPicker];
}
}
-(void)manageRotation:(NSNotification *)notification
{
//Capture the old orientation
oldOrientation = [[UIApplication sharedApplication]statusBarOrientation];
//Capture the new orientation
newOrientation = [[notification.userInfo valueForKey:UIApplicationStatusBarOrientationUserInfoKey] integerValue];
}
-(void)updatePopover:(NSNotification *)notification
{
if (isPresenting) {
return;
}
//Set up the right delay
NSTimeInterval delay = [[UIApplication sharedApplication] statusBarOrientationAnimationDuration];
if ( (oldOrientation == UIInterfaceOrientationPortrait) && (newOrientation == UIInterfaceOrientationPortraitUpsideDown) ){
delay*=2.0;
}
else if ( (oldOrientation == UIInterfaceOrientationLandscapeLeft) && (newOrientation == UIInterfaceOrientationLandscapeRight) ){
delay *=2.0;
}
//Allow the root view controller to relayout all child view controllers so that we get the correct frame size when we re-present
[self performSelector:@selector(updatePopoverNow) withObject:nil afterDelay:delay inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
}
-(void)updatePopoverNow
{
isPresenting = YES;
if (popover) {
//GO AHEAD AND RE-PRESENT THE POPOVER NOW
CGRect popOverRect = [popoverView bounds];
if (popoverView == [[[[TiApp app] controller] topWindow] view]) {
popOverRect.size.height = 50;
}
if ([popoverView window] == nil) {
// No window, so we can't display the popover...
DebugLog(@"[WARN] Unable to display picker; view is not attached to the current window");
}
else {
[popover presentPopoverFromRect:popOverRect inView:popoverView permittedArrowDirections:arrowDirection animated:NO];
}
}
isPresenting = NO;
}
-(void)closeModalPicker:(UIViewController*)picker_
{
if (cameraView != nil) {
[cameraView windowWillClose];
}
if (popover)
{
[(UIPopoverController*)popover dismissPopoverAnimated:animatedPicker];
RELEASE_TO_NIL(popover);
}
else
{
[[TiApp app] hideModalController:picker_ animated:animatedPicker];
[[TiApp controller] repositionSubviews];
}
if (cameraView != nil) {
[cameraView windowDidClose];
[self forgetProxy:cameraView];
RELEASE_TO_NIL(cameraView);
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
if([popoverController contentViewController] == musicPicker) {
RELEASE_TO_NIL(musicPicker);
}
RELEASE_TO_NIL(popover);
[self sendPickerCancel];
//Unregister for interface change notification
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)showPicker:(NSDictionary*)args isCamera:(BOOL)isCamera
{
if (picker!=nil)
{
[self sendPickerError:MediaModuleErrorBusy];
return;
}
picker = [[UIImagePickerController alloc] init];
[picker setDelegate:self];
animatedPicker = YES;
saveToRoll = NO;
BOOL editable = NO;
UIImagePickerControllerSourceType ourSource = (isCamera ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary);
if (args!=nil)
{
[self commonPickerSetup:args];
NSNumber * imageEditingObject = [args objectForKey:@"allowImageEditing"]; //backwards compatible
saveToRoll = [TiUtils boolValue:@"saveToPhotoGallery" properties:args def:NO];
if (imageEditingObject==nil)
{
imageEditingObject = [args objectForKey:@"allowEditing"];
editable = [TiUtils boolValue:imageEditingObject];
}
// introduced in 3.1
[picker setAllowsEditing:editable];
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:ourSource];
id types = [args objectForKey:@"mediaTypes"];
BOOL movieRequired = NO;
BOOL imageRequired = NO;
if ([types isKindOfClass:[NSArray class]])
{
for (int c=0;c<[types count];c++)
{
if ([[types objectAtIndex:c] isEqualToString:(NSString*)kUTTypeMovie])
{
movieRequired = YES;
}
else if ([[types objectAtIndex:c] isEqualToString:(NSString*)kUTTypeImage])
{
imageRequired = YES;
}
}
picker.mediaTypes = [NSArray arrayWithArray:types];
}
else if ([types isKindOfClass:[NSString class]])
{
if ([types isEqualToString:(NSString*)kUTTypeMovie] && ![sourceTypes containsObject:(NSString *)kUTTypeMovie])
{
// no movie type supported...
[self sendPickerError:MediaModuleErrorNoVideo];
return;
}
picker.mediaTypes = [NSArray arrayWithObject:types];
}
// if we require movie but not image and we don't support movie, bail...
if (movieRequired == YES && imageRequired == NO && ![sourceTypes containsObject:(NSString *)kUTTypeMovie])
{
// no movie type supported...
[self sendPickerError:MediaModuleErrorNoCamera];
return ;
}
// introduced in 3.1
id videoMaximumDuration = [args objectForKey:@"videoMaximumDuration"];
if ([videoMaximumDuration respondsToSelector:@selector(doubleValue)] && [picker respondsToSelector:@selector(setVideoMaximumDuration:)])
{
[picker setVideoMaximumDuration:[videoMaximumDuration doubleValue]/1000];
}
id videoQuality = [args objectForKey:@"videoQuality"];
if ([videoQuality respondsToSelector:@selector(doubleValue)] && [picker respondsToSelector:@selector(setVideoQuality:)])
{
[picker setVideoQuality:[videoQuality doubleValue]];
}
}
// do this afterwards above so we can first check for video support
if (![UIImagePickerController isSourceTypeAvailable:ourSource])
{
[self sendPickerError:MediaModuleErrorNoCamera];
return;
}
[picker setSourceType:ourSource];
// this must be done after we set the source type or you'll get an exception
if (isCamera && ourSource == UIImagePickerControllerSourceTypeCamera)
{
// turn on/off camera controls - nice to turn off when you want to have your own UI
[picker setShowsCameraControls:[TiUtils boolValue:@"showControls" properties:args def:YES]];
// allow an overlay view
TiViewProxy *cameraViewProxy = [args objectForKey:@"overlay"];
if (cameraViewProxy!=nil)
{
ENSURE_TYPE(cameraViewProxy,TiViewProxy);
cameraView = [cameraViewProxy retain];
UIView *view = [cameraView view];
if (editable)
{
// turn off touch enablement if image editing is enabled since it will
// interfere with editing
[view performSelector:@selector(setTouchEnabled_:) withObject:NUMBOOL(NO)];
}
[TiUtils setView:view positionRect:[picker view].bounds];
[cameraView windowWillOpen];
[picker setCameraOverlayView:view];
[cameraView windowDidOpen];
[cameraView layoutChildren:NO];
[picker setWantsFullScreenLayout:YES];
}
// allow a transform on the preview image
id transform = [args objectForKey:@"transform"];
if (transform!=nil)
{
ENSURE_TYPE(transform,Ti2DMatrix);
[picker setCameraViewTransform:[transform matrix]];
}
else if (cameraView!=nil)
{
// we use our own fullscreen transform if the developer didn't supply one
if ([TiUtils isRetinaFourInch]) {
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y_ALT);
}
else {
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
}
}
}
if (isCamera) {
BOOL inPopOver = [TiUtils boolValue:@"inPopOver" properties:args def:NO];
if (inPopOver) {
[self displayModalPicker:picker settings:args];
}
else {
[self displayCamera:picker];
}
} else {
[self displayModalPicker:picker settings:args];
}
}
-(void)saveCompletedForImage:(UIImage*)image error:(NSError*)error contextInfo:(void*)contextInfo
{
NSDictionary* saveCallbacks = (NSDictionary*)contextInfo;
TiBlob* blob = [[[TiBlob alloc] initWithImage:image] autorelease];
if (error != nil) {
KrollCallback* errorCallback = [saveCallbacks objectForKey:@"error"];
if (errorCallback != nil) {
NSMutableDictionary * event = [TiUtils dictionaryWithCode:[error code] message:[TiUtils messageFromError:error]];
[event setObject:blob forKey:@"image"];
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"error",event,errorCallback,nil]];
}
return;
}
KrollCallback* successCallback = [saveCallbacks objectForKey:@"success"];
if (successCallback != nil) {
NSMutableDictionary * event = [TiUtils dictionaryWithCode:0 message:nil];
[event setObject:blob forKey:@"image"];
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"success",event,successCallback,nil]];
}
}
-(void)saveCompletedForVideo:(NSString*)path error:(NSError*)error contextInfo:(void*)contextInfo
{
NSDictionary* saveCallbacks = (NSDictionary*)contextInfo;
if (error != nil) {
KrollCallback* errorCallback = [saveCallbacks objectForKey:@"error"];
if (errorCallback != nil) {
NSMutableDictionary * event = [TiUtils dictionaryWithCode:[error code] message:[TiUtils messageFromError:error]];
[event setObject:path forKey:@"path"];
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"error",event,errorCallback,nil]];
}
return;
}
KrollCallback* successCallback = [saveCallbacks objectForKey:@"success"];
if (successCallback != nil) {
NSMutableDictionary * event = [TiUtils dictionaryWithCode:0 message:nil];
[event setObject:path forKey:@"path"];
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"success",event,successCallback,nil]];
}
// This object was retained for use in this callback; release it.
[saveCallbacks release];
}
#pragma mark Public APIs
MAKE_SYSTEM_PROP(UNKNOWN_ERROR,MediaModuleErrorUnknown);
MAKE_SYSTEM_PROP(DEVICE_BUSY,MediaModuleErrorBusy);
MAKE_SYSTEM_PROP(NO_CAMERA,MediaModuleErrorNoCamera);
MAKE_SYSTEM_PROP(NO_VIDEO,MediaModuleErrorNoVideo);
MAKE_SYSTEM_PROP(NO_MUSIC_PLAYER,MediaModuleErrorNoMusicPlayer);
// >=3.2 dependent value; this one isn't deprecated
MAKE_SYSTEM_PROP(VIDEO_CONTROL_DEFAULT, MPMovieControlStyleDefault);
// Deprecated old-school video control modes, mapped to the new values
-(NSNumber*)VIDEO_CONTROL_VOLUME_ONLY
{
DEPRECATED_REPLACED(@"Media.VIDEO_CONTROL_VOLUME_ONLY", @"1.8.0", @"Ti.Media.VIDEO_CONTROL_EMBEDDED");
return [self VIDEO_CONTROL_EMBEDDED];
}
-(NSNumber*)VIDEO_CONTROL_HIDDEN
{
// This constant is still available in a non-deprecated manner in Android for 1.8; we should keep it around
// until there's a parity discussion.
// TODO: Does this need to be deprecated? For now, return the right value.
return [self VIDEO_CONTROL_NONE];
}
MAKE_SYSTEM_PROP(VIDEO_SCALING_NONE,MPMovieScalingModeNone);
MAKE_SYSTEM_PROP(VIDEO_SCALING_ASPECT_FIT,MPMovieScalingModeAspectFit);
MAKE_SYSTEM_PROP(VIDEO_SCALING_ASPECT_FILL,MPMovieScalingModeAspectFill);
MAKE_SYSTEM_PROP(VIDEO_SCALING_MODE_FILL,MPMovieScalingModeFill);
MAKE_SYSTEM_STR(MEDIA_TYPE_VIDEO,kUTTypeMovie);
MAKE_SYSTEM_STR(MEDIA_TYPE_PHOTO,kUTTypeImage);
MAKE_SYSTEM_PROP(QUALITY_HIGH,UIImagePickerControllerQualityTypeHigh);
MAKE_SYSTEM_PROP(QUALITY_MEDIUM,UIImagePickerControllerQualityTypeMedium);
MAKE_SYSTEM_PROP(QUALITY_LOW,UIImagePickerControllerQualityTypeLow);
MAKE_SYSTEM_PROP(QUALITY_640x480,UIImagePickerControllerQualityType640x480);
MAKE_SYSTEM_PROP(CAMERA_FRONT,UIImagePickerControllerCameraDeviceFront);
MAKE_SYSTEM_PROP(CAMERA_REAR,UIImagePickerControllerCameraDeviceRear);
MAKE_SYSTEM_PROP(CAMERA_FLASH_OFF,UIImagePickerControllerCameraFlashModeOff);
MAKE_SYSTEM_PROP(CAMERA_FLASH_AUTO,UIImagePickerControllerCameraFlashModeAuto);
MAKE_SYSTEM_PROP(CAMERA_FLASH_ON,UIImagePickerControllerCameraFlashModeOn);
MAKE_SYSTEM_PROP(AUDIO_HEADPHONES,TiMediaAudioSessionInputHeadphones);
MAKE_SYSTEM_PROP(AUDIO_HEADSET_INOUT,TiMediaAudioSessionInputHeadsetInOut);
MAKE_SYSTEM_PROP(AUDIO_RECEIVER_AND_MIC,TiMediaAudioSessionInputReceiverAndMicrophone);
MAKE_SYSTEM_PROP(AUDIO_HEADPHONES_AND_MIC,TiMediaAudioSessionInputHeadphonesAndMicrophone);
MAKE_SYSTEM_PROP(AUDIO_LINEOUT,TiMediaAudioSessionInputLineOut);
MAKE_SYSTEM_PROP(AUDIO_SPEAKER,TiMediaAudioSessionInputSpeaker);
MAKE_SYSTEM_PROP(AUDIO_MICROPHONE,TiMediaAudioSessionInputMicrophoneBuiltin);
MAKE_SYSTEM_PROP(AUDIO_MUTED,TiMediaAudioSessionInputMuted);
MAKE_SYSTEM_PROP(AUDIO_UNAVAILABLE,TiMediaAudioSessionInputUnavailable);
MAKE_SYSTEM_PROP(AUDIO_UNKNOWN,TiMediaAudioSessionInputUnknown);
MAKE_SYSTEM_UINT(AUDIO_FORMAT_LINEAR_PCM,kAudioFormatLinearPCM);
MAKE_SYSTEM_UINT(AUDIO_FORMAT_ULAW,kAudioFormatULaw);
MAKE_SYSTEM_UINT(AUDIO_FORMAT_ALAW,kAudioFormatALaw);
MAKE_SYSTEM_UINT(AUDIO_FORMAT_IMA4,kAudioFormatAppleIMA4);
MAKE_SYSTEM_UINT(AUDIO_FORMAT_ILBC,kAudioFormatiLBC);
MAKE_SYSTEM_UINT(AUDIO_FORMAT_APPLE_LOSSLESS,kAudioFormatAppleLossless);
MAKE_SYSTEM_UINT(AUDIO_FORMAT_AAC,kAudioFormatMPEG4AAC);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_WAVE,kAudioFileWAVEType);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_AIFF,kAudioFileAIFFType);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_MP3,kAudioFileMP3Type);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_MP4,kAudioFileMPEG4Type);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_MP4A,kAudioFileM4AType);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_CAF,kAudioFileCAFType);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_3GPP,kAudioFile3GPType);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_3GP2,kAudioFile3GP2Type);
MAKE_SYSTEM_UINT(AUDIO_FILEFORMAT_AMR,kAudioFileAMRType);
MAKE_SYSTEM_UINT(AUDIO_SESSION_MODE_AMBIENT, kAudioSessionCategory_AmbientSound);
MAKE_SYSTEM_UINT(AUDIO_SESSION_MODE_SOLO_AMBIENT, kAudioSessionCategory_SoloAmbientSound);
MAKE_SYSTEM_UINT(AUDIO_SESSION_MODE_PLAYBACK, kAudioSessionCategory_MediaPlayback);
MAKE_SYSTEM_UINT(AUDIO_SESSION_MODE_RECORD, kAudioSessionCategory_RecordAudio);
MAKE_SYSTEM_UINT(AUDIO_SESSION_MODE_PLAY_AND_RECORD, kAudioSessionCategory_PlayAndRecord);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_TYPE_MUSIC, MPMediaTypeMusic);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_TYPE_PODCAST, MPMediaTypePodcast);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_TYPE_AUDIOBOOK, MPMediaTypeAudioBook);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_TYPE_ANY_AUDIO, MPMediaTypeAnyAudio);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_TYPE_ALL, MPMediaTypeAny);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_TITLE, MPMediaGroupingTitle);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_ALBUM, MPMediaGroupingAlbum);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_ARTIST, MPMediaGroupingArtist);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_ALBUM_ARTIST, MPMediaGroupingAlbumArtist);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_COMPOSER, MPMediaGroupingComposer);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_GENRE, MPMediaGroupingGenre);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_PLAYLIST, MPMediaGroupingPlaylist);
MAKE_SYSTEM_PROP(MUSIC_MEDIA_GROUP_PODCAST_TITLE, MPMediaGroupingPodcastTitle);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_STOPPED, MPMusicPlaybackStateStopped);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_PLAYING, MPMusicPlaybackStatePlaying);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_PAUSED, MPMusicPlaybackStatePaused);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_INTERRUPTED, MPMusicPlaybackStateInterrupted);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_SKEEK_FORWARD, MPMusicPlaybackStateSeekingForward);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_SEEK_BACKWARD, MPMusicPlaybackStateSeekingBackward);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_REPEAT_DEFAULT, MPMusicRepeatModeDefault);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_REPEAT_NONE, MPMusicRepeatModeNone);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_REPEAT_ONE, MPMusicRepeatModeOne);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_REPEAT_ALL, MPMusicRepeatModeAll);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_SHUFFLE_DEFAULT, MPMusicShuffleModeDefault);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_SHUFFLE_NONE, MPMusicShuffleModeOff);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_SHUFFLE_SONGS, MPMusicShuffleModeSongs);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_SHUFFLE_ALBUMS, MPMusicShuffleModeAlbums);
// these are new in 3.2
MAKE_SYSTEM_PROP(VIDEO_CONTROL_NONE,MPMovieControlStyleNone);
MAKE_SYSTEM_PROP(VIDEO_CONTROL_EMBEDDED,MPMovieControlStyleEmbedded);
MAKE_SYSTEM_PROP(VIDEO_CONTROL_FULLSCREEN,MPMovieControlStyleFullscreen);
MAKE_SYSTEM_PROP(VIDEO_MEDIA_TYPE_NONE,MPMovieMediaTypeMaskNone);
MAKE_SYSTEM_PROP(VIDEO_MEDIA_TYPE_VIDEO,MPMovieMediaTypeMaskVideo);
MAKE_SYSTEM_PROP(VIDEO_MEDIA_TYPE_AUDIO,MPMovieMediaTypeMaskAudio);
MAKE_SYSTEM_PROP(VIDEO_SOURCE_TYPE_UNKNOWN,MPMovieSourceTypeUnknown);
MAKE_SYSTEM_PROP(VIDEO_SOURCE_TYPE_FILE,MPMovieSourceTypeFile);
MAKE_SYSTEM_PROP(VIDEO_SOURCE_TYPE_STREAMING,MPMovieSourceTypeStreaming);
MAKE_SYSTEM_PROP(VIDEO_PLAYBACK_STATE_STOPPED,MPMoviePlaybackStateStopped);
MAKE_SYSTEM_PROP(VIDEO_PLAYBACK_STATE_PLAYING,MPMoviePlaybackStatePlaying);
MAKE_SYSTEM_PROP(VIDEO_PLAYBACK_STATE_PAUSED,MPMoviePlaybackStatePaused);
MAKE_SYSTEM_PROP(VIDEO_PLAYBACK_STATE_INTERRUPTED,MPMoviePlaybackStateInterrupted);
MAKE_SYSTEM_PROP(VIDEO_PLAYBACK_STATE_SEEKING_FORWARD,MPMoviePlaybackStateSeekingForward);
MAKE_SYSTEM_PROP(VIDEO_PLAYBACK_STATE_SEEKING_BACKWARD,MPMoviePlaybackStateSeekingBackward);
MAKE_SYSTEM_PROP(VIDEO_LOAD_STATE_UNKNOWN,MPMovieLoadStateUnknown);
MAKE_SYSTEM_PROP(VIDEO_LOAD_STATE_PLAYABLE,MPMovieLoadStatePlayable);
MAKE_SYSTEM_PROP(VIDEO_LOAD_STATE_PLAYTHROUGH_OK,MPMovieLoadStatePlaythroughOK);
MAKE_SYSTEM_PROP(VIDEO_LOAD_STATE_STALLED,MPMovieLoadStateStalled);
MAKE_SYSTEM_PROP(VIDEO_REPEAT_MODE_NONE,MPMovieRepeatModeNone);
MAKE_SYSTEM_PROP(VIDEO_REPEAT_MODE_ONE,MPMovieRepeatModeOne);
MAKE_SYSTEM_PROP(VIDEO_TIME_OPTION_NEAREST_KEYFRAME,MPMovieTimeOptionNearestKeyFrame);
MAKE_SYSTEM_PROP(VIDEO_TIME_OPTION_EXACT,MPMovieTimeOptionExact);
MAKE_SYSTEM_PROP(VIDEO_FINISH_REASON_PLAYBACK_ENDED,MPMovieFinishReasonPlaybackEnded);
MAKE_SYSTEM_PROP(VIDEO_FINISH_REASON_PLAYBACK_ERROR,MPMovieFinishReasonPlaybackError);
MAKE_SYSTEM_PROP(VIDEO_FINISH_REASON_USER_EXITED,MPMovieFinishReasonUserExited);
-(CGFloat)volume
{
return [[TiMediaAudioSession sharedSession] volume];
}
-(NSNumber*)canRecord
{
return NUMBOOL([[TiMediaAudioSession sharedSession] hasInput]);
}
-(BOOL)audioPlaying
{
return [[TiMediaAudioSession sharedSession] isAudioPlaying];
}
-(NSInteger)audioLineType
{
return [[TiMediaAudioSession sharedSession] inputType];
}
-(NSArray*)availableCameraMediaTypes
{
NSArray* mediaSourceTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
return mediaSourceTypes==nil ? [NSArray arrayWithObject:(NSString*)kUTTypeImage] : mediaSourceTypes;
}
-(NSArray*)availablePhotoMediaTypes
{
NSArray* photoSourceTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
return photoSourceTypes==nil ? [NSArray arrayWithObject:(NSString*)kUTTypeImage] : photoSourceTypes;
}
-(NSArray*)availablePhotoGalleryMediaTypes
{
NSArray* albumSourceTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeSavedPhotosAlbum];
return albumSourceTypes==nil ? [NSArray arrayWithObject:(NSString*)kUTTypeImage] : albumSourceTypes;
}
-(NSArray*)availableCameras
{
NSMutableArray* types = [NSMutableArray arrayWithCapacity:2];
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
[types addObject:NUMINT(UIImagePickerControllerCameraDeviceFront)];
}
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
{
[types addObject:NUMINT(UIImagePickerControllerCameraDeviceRear)];
}
return types;
}
-(id)camera
{
if (picker!=nil)
{
return NUMINT([picker cameraDevice]);
}
return NUMINT(UIImagePickerControllerCameraDeviceRear);
}
-(id)cameraFlashMode
{
if (picker!=nil)
{
return NUMINT([picker cameraFlashMode]);
}
return NUMINT(UIImagePickerControllerCameraFlashModeAuto);
}
-(void)setCameraFlashMode:(id)args
{
// Return nothing
ENSURE_SINGLE_ARG(args,NSNumber);
ENSURE_UI_THREAD(setCameraFlashMode,args);
if (picker!=nil)
{
[picker setCameraFlashMode:[TiUtils intValue:args]];
}
}
-(void)switchCamera:(id)args
{
ENSURE_SINGLE_ARG(args,NSNumber);
ENSURE_UI_THREAD(switchCamera,args);
// must have a picker, doh
if (picker==nil)
{
[self throwException:@"invalid state" subreason:nil location:CODELOCATION];
}
[picker setCameraDevice:[TiUtils intValue:args]];
}
-(void)startVideoCapture:(id)args
{
// Return nothing
ENSURE_UI_THREAD(startVideoCapture,args);
// must have a picker, doh
if (picker==nil)
{
[self throwException:@"invalid state" subreason:nil location:CODELOCATION];
}
[picker startVideoCapture];
}
-(void)stopVideoCapture:(id)args
{
ENSURE_UI_THREAD(stopVideoCapture,args);
// must have a picker, doh
if (picker!=nil)
{
[picker stopVideoCapture];
}
}
-(void)startVideoEditing:(id)args
{
ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);
ENSURE_UI_THREAD(startVideoEditing,args);
RELEASE_TO_NIL(editor);
BOOL animated = [TiUtils boolValue:@"animated" properties:args def:YES];
id media = [args objectForKey:@"media"];
editorSuccessCallback = [args objectForKey:@"success"];
ENSURE_TYPE_OR_NIL(editorSuccessCallback,KrollCallback);
[editorSuccessCallback retain];
editorErrorCallback = [args objectForKey:@"error"];
ENSURE_TYPE_OR_NIL(editorErrorCallback,KrollCallback);
[editorErrorCallback retain];
editorCancelCallback = [args objectForKey:@"cancel"];
ENSURE_TYPE_OR_NIL(pickerCancelCallback,KrollCallback);
[editorCancelCallback retain];
//TODO: check canEditVideoAtPath
UIViewController *root = [[TiApp app] controller];
editor = [[UIVideoEditorController alloc] init];
editor.delegate = self;
editor.videoQuality = [TiUtils intValue:@"videoQuality" properties:args def:UIImagePickerControllerQualityTypeMedium];
editor.videoMaximumDuration = [TiUtils doubleValue:@"videoMaximumDuration" properties:args def:600];
if ([media isKindOfClass:[NSString class]])
{
NSURL *url = [TiUtils toURL:media proxy:self];
editor.videoPath = [url path];
}
else if ([media isKindOfClass:[TiBlob class]])
{
TiBlob *blob = (TiBlob*)media;
editor.videoPath = [blob path];
}
else if ([media isKindOfClass:[TiFile class]])
{
TiFile *file = (TiFile*)media;
editor.videoPath = [file path];
}
else
{
RELEASE_TO_NIL(editor);
NSLog(@"[ERROR] Unsupported video media: %@",[media class]);
return;
}
TiApp * tiApp = [TiApp app];
[[tiApp controller] manuallyRotateToOrientation:UIInterfaceOrientationPortrait duration:[[tiApp controller] suggestedRotationDuration]];
[tiApp showModalController:editor animated:animated];
}
-(void)stopVideoEditing:(id)args
{
ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);
ENSURE_UI_THREAD(stopVideoEditing,args);
if (editor!=nil)
{
BOOL animated = [TiUtils boolValue:@"animated" properties:args def:YES];
[[TiApp app] hideModalController:editor animated:animated];
RELEASE_TO_NIL(editor);
}
}
-(id)isMediaTypeSupported:(id)args
{
ENSURE_ARG_COUNT(args,2);
NSString *media = [[TiUtils stringValue:[args objectAtIndex:0]] lowercaseString];
NSString *type = [[TiUtils stringValue:[args objectAtIndex:1]] lowercaseString];
NSArray *array = nil;
if ([media isEqualToString:@"camera"])
{
array = [self availableCameraMediaTypes];
}
else if ([media isEqualToString:@"photo"])
{
array = [self availablePhotoMediaTypes];
}
else if ([media isEqualToString:@"photogallery"])
{
array = [self availablePhotoGalleryMediaTypes];
}
if (array!=nil)
{
for (NSString* atype in array)
{
if ([[atype lowercaseString] isEqualToString:type])
{
return NUMBOOL(YES);
}
}
}
return NUMBOOL(NO);
}
-(BOOL)isCameraSupported;
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}
-(void)showCamera:(id)args
{
ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);
if (![NSThread isMainThread]) {
[self rememberProxy:[args objectForKey:@"overlay"]];
TiThreadPerformOnMainThread(^{[self showCamera:args];},NO);
return;
}
[self showPicker:args isCamera:YES];
}
-(void)openPhotoGallery:(id)args
{
ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);
ENSURE_UI_THREAD(openPhotoGallery,args);
[self showPicker:args isCamera:NO];
}
-(void)takeScreenshot:(id)arg
{
ENSURE_SINGLE_ARG(arg,KrollCallback);
ENSURE_UI_THREAD(takeScreenshot,arg);
// Create a graphics context with the target size
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
{
// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the window's anchor point
CGContextTranslateCTM(context, [window center].x, [window center].y);
// Apply the window's transform about the anchor point
CGContextConcatCTM(context, [window transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[window bounds].size.width * [[window layer] anchorPoint].x,
-[window bounds].size.height * [[window layer] anchorPoint].y);
// Render the layer hierarchy to the current context
[[window layer] renderInContext:context];
// Restore the context
CGContextRestoreGState(context);
}
}
// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIInterfaceOrientation windowOrientation = [[TiApp controller] windowOrientation];
switch (windowOrientation) {
case UIInterfaceOrientationPortraitUpsideDown:
image = [UIImage imageWithCGImage:[image CGImage] scale:[image scale] orientation:UIImageOrientationDown];
break;
case UIInterfaceOrientationLandscapeLeft:
image = [UIImage imageWithCGImage:[image CGImage] scale:[image scale] orientation:UIImageOrientationRight];
break;
case UIInterfaceOrientationLandscapeRight:
image = [UIImage imageWithCGImage:[image CGImage] scale:[image scale] orientation:UIImageOrientationLeft];
break;
default:
break;
}
TiBlob *blob = [[[TiBlob alloc] initWithImage:image] autorelease];
NSDictionary *event = [NSDictionary dictionaryWithObject:blob forKey:@"media"];
[self _fireEventToListener:@"screenshot" withObject:event listener:arg thisObject:nil];
}
-(void)saveToPhotoGallery:(id)arg