Skip to content

Commit 662d2aa

Browse files
authored
1 parent 5a70251 commit 662d2aa

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

demo/app/main-view-model.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'file-system';
33
import * as app from 'application';
44
import * as color from 'color';
55
import * as platform from 'platform';
6+
import * as dialogs from 'ui/dialogs';
67
import { SnackBar } from 'nativescript-snackbar';
78
import {TNSRecorder, TNSPlayer, AudioPlayerOptions, AudioRecorderOptions} from 'nativescript-audio';
89

@@ -61,11 +62,11 @@ export class AudioDemo extends Observable {
6162
metering: true,
6263

6364
infoCallback: () => {
64-
console.log();
65+
6566
},
6667

6768
errorCallback: () => {
68-
console.log();
69+
6970
// snackbar.simple('Error recording.');
7071
}
7172
};
@@ -79,10 +80,10 @@ export class AudioDemo extends Observable {
7980
}, (err) => {
8081
this.set("isRecording", false);
8182
this.resetMeter();
82-
alert(err);
83+
dialogs.alert(err);
8384
});
8485
} else {
85-
alert("This device cannot record audio.");
86+
dialogs.alert("This device cannot record audio.");
8687
}
8788
}
8889

@@ -134,7 +135,7 @@ export class AudioDemo extends Observable {
134135

135136
var playerOptions: AudioPlayerOptions = {
136137
audioFile: `~/audio/recording.${this.platformExtension()}`,
137-
loop: true,
138+
loop: false,
138139
completeCallback: () => {
139140
this._SnackBar.simple("Audio file complete");
140141
this.set("isPlaying", false);
@@ -149,12 +150,12 @@ export class AudioDemo extends Observable {
149150
},
150151

151152
errorCallback: () => {
152-
alert('Error callback');
153+
dialogs.alert('Error callback');
153154
this.set("isPlaying", false);
154155
},
155156

156157
infoCallback: () => {
157-
alert('Info callback');
158+
dialogs.alert('Info callback');
158159
}
159160
};
160161

@@ -196,7 +197,7 @@ export class AudioDemo extends Observable {
196197
},
197198

198199
infoCallback: (info) => {
199-
alert('Info callback: ' + info.msg);
200+
dialogs.alert('Info callback: ' + info.msg);
200201
console.log("what: " + info);
201202
}
202203
};

demo/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
"nativescript-snackbar": "^1.0.3",
1414
"nativescript-statusbar": "^1.0.0",
1515
"nativescript-theme-core": "^0.1.2",
16-
"tns-core-modules": "next"
16+
"tns-core-modules": "^2.3.0"
1717
},
1818
"devDependencies": {
1919
"babel-traverse": "6.12.0",
2020
"babel-types": "6.11.1",
2121
"babylon": "6.8.4",
2222
"lazy": "1.0.11",
2323
"nativescript-dev-typescript": "^0.3.2",
24-
"tns-platform-declarations": "^2.0.0",
24+
"tns-platform-declarations": "^2.3.0",
2525
"typescript": "^1.8.10"
2626
}
27-
}
27+
}

package.json

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
"typings": "index.d.ts",
77
"nativescript": {
88
"platforms": {
9-
"android": "2.2.0",
10-
"ios": "2.2.1"
11-
},
12-
"tns-ios": {
13-
"version": "2.3.0"
9+
"android": "2.3.0",
10+
"ios": "2.3.0"
1411
}
1512
},
1613
"scripts": {
1714
"build": "tsc",
1815
"demo.ios": "npm run preparedemo; cd demo; tns emulate ios",
1916
"demo.android": "npm run preparedemo; cd demo; tns emulate android",
2017
"preparedemo": "npm run build; cd demo; tns plugin remove nativescript-audio; tns plugin add ..; tns install",
21-
"setup": "cd demo; npm install; cd ..; npm run build; cd demo; tns plugin add ..; cd .."
18+
"setup": "cd demo; npm i; cd ..; npm i; npm run build; cd demo; tns plugin add ..; cd .."
2219
},
2320
"repository": {
2421
"type": "git",
@@ -58,7 +55,7 @@
5855
"homepage": "https://github.com/bradmartin/nativescript-audio",
5956
"readmeFilename": "README.md",
6057
"devDependencies": {
61-
"tns-platform-declarations": "^2.0.0",
58+
"tns-platform-declarations": "^2.3.0",
6259
"typescript": "^1.8.10"
6360
}
6461
}

src/ios/player.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {knownFolders, path} from 'file-system';
44
import {TNSPlayerI} from '../common';
55
import {AudioPlayerOptions} from '../options';
66

7-
declare var NSURLSession, AVAudioPlayer, NSURL, AVAudioPlayerDelegate, NSObject: any;
7+
declare var NSURLSession, AVAudioPlayer, NSURL, AVAudioPlayerDelegate;
88

99
export class TNSPlayer extends NSObject implements TNSPlayerI {
1010
public static ObjCProtocols = [AVAudioPlayerDelegate];

src/ios/recorder.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {knownFolders, path} from 'file-system';
44
import {TNSRecordI} from '../common';
55
import {AudioRecorderOptions} from '../options';
66

7-
declare var interop;
7+
declare var interop, kAudioFormatMPEG4AAC, AVAudioQuality;
88

99
export class TNSRecorder extends NSObject implements TNSRecordI {
1010
public static ObjCProtocols = [AVAudioRecorderDelegate];
@@ -29,8 +29,14 @@ export class TNSRecorder extends NSObject implements TNSRecordI {
2929
this._recordingSession.requestRecordPermission((allowed: boolean) => {
3030
if (allowed) {
3131

32-
var recordSetting = new NSMutableDictionary((<any>[NSNumber.numberWithInt(kAudioFormatMPEG4AAC), NSNumber.numberWithInt((<any>AVAudioQuality).Medium.rawValue), NSNumber.numberWithFloat(16000.0), NSNumber.numberWithInt(1)]),
33-
(<any>["AVFormatIDKey", "AVEncoderAudioQualityKey", "AVSampleRateKey", "AVNumberOfChannelsKey"]));
32+
// var recordSetting = new NSMutableDictionary((<any>[NSNumber.numberWithInt(kAudioFormatMPEG4AAC), NSNumber.numberWithInt((<any>AVAudioQuality).Medium.rawValue), NSNumber.numberWithFloat(16000.0), NSNumber.numberWithInt(1)]),
33+
// (<any>["AVFormatIDKey", "AVEncoderAudioQualityKey", "AVSampleRateKey", "AVNumberOfChannelsKey"]));
34+
35+
let recordSetting = NSMutableDictionary.alloc().init();
36+
recordSetting.setValueForKey(NSNumber.numberWithInt(kAudioFormatMPEG4AAC), 'AVFormatIDKey');
37+
recordSetting.setValueForKey(NSNumber.numberWithInt((<any>AVAudioQuality).Medium.rawValue), 'AVEncoderAudioQualityKey');
38+
recordSetting.setValueForKey(NSNumber.numberWithFloat(16000.0), 'AVSampleRateKey');
39+
recordSetting.setValueForKey(NSNumber.numberWithInt(1), 'AVNumberOfChannelsKey');
3440

3541
errorRef = new interop.Reference();
3642

tsconfig.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
"declaration": true,
99
"noEmitOnError": false,
1010
"noEmitHelpers": true,
11-
"noImplicitUseStrict": true
11+
"noImplicitUseStrict": true,
12+
"noLib": true
1213
},
1314
"files": [
15+
"manual_typings/base.d.ts",
16+
"node_modules/typescript/lib/lib.core.d.ts",
17+
"node_modules/tns-platform-declarations/tns-core-modules/android17.d.ts",
18+
"node_modules/tns-platform-declarations/tns-core-modules/ios/ios.d.ts",
19+
"node_modules/tns-platform-declarations/tns-core-modules/org.nativescript.widgets.d.ts",
1420
"demo/node_modules/tns-core-modules/tns-core-modules.d.ts",
15-
"node_modules/tns-platform-declarations/android17.d.ts",
16-
"node_modules/tns-platform-declarations/ios.d.ts",
17-
"node_modules/tns-platform-declarations/org.nativescript.widgets.d.ts",
1821
"audio.android.ts",
1922
"audio.ios.ts"
2023
],

0 commit comments

Comments
 (0)