-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
TiMediaSystemAlertProxy.m
77 lines (61 loc) 路 2.05 KB
/
TiMediaSystemAlertProxy.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
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2016 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 "TiMediaSystemAlertProxy.h"
#import "TiUtils.h"
@implementation TiMediaSystemAlertProxy
#pragma mark Proxy Lifecycle
-(void)_destroy
{
AudioServicesDisposeSystemSoundID(sound);
RELEASE_TO_NIL(url);
[super _destroy];
}
#pragma mark Public APIs
-(id)url
{
return [url absoluteString];
}
-(void)setUrl:(id)url_
{
RELEASE_TO_NIL(url);
// Handle string url
if ([url_ isKindOfClass:[NSString class]]) {
url = [[TiUtils toURL:url_ proxy:self] retain];
if ([url isFileURL] == NO) {
// we need to download it and save it off into temp file
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *ext = [[[url path] lastPathComponent] pathExtension];
TiFile* tempFile = [[TiFile createTempFile:ext] retain]; // file auto-deleted on release
[data writeToFile:[tempFile path] atomically:YES];
RELEASE_TO_NIL(url);
url = [[NSURL fileURLWithPath:[tempFile path]] retain];
}
// Handle file blob
} else if ([url_ isKindOfClass:[TiBlob class]]) {
TiBlob *blob = (TiBlob*)url_;
if ([blob type] == TiBlobTypeFile){
url = [[NSURL fileURLWithPath:[blob path]] retain];
}
// Handle file object
} else if ([url_ isKindOfClass:[TiFile class]]) {
url = [[NSURL fileURLWithPath:[(TiFile*)url_ path]] retain];
}
// Dispose sound before re-referencing
AudioServicesDisposeSystemSoundID(sound);
AudioServicesCreateSystemSoundID((CFURLRef)url, &sound);
}
-(void)play:(id)unused
{
if (url == nil) {
NSLog(@"[ERROR] Trying to play a system alert without having specified the `url` property. Skipping playback.");
return;
}
AudioServicesPlayAlertSound(sound);
}
@end
#endif