From 725ecd5b6bd8dd2aec96fc61f0c028053c53c95d Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sat, 6 Aug 2016 20:42:43 -0700 Subject: [PATCH 1/3] chore: update deps --- demo/package.json | 21 ++++++++++----------- package.json | 6 +++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/demo/package.json b/demo/package.json index 21669b3..ca55d3e 100644 --- a/demo/package.json +++ b/demo/package.json @@ -2,25 +2,24 @@ "nativescript": { "id": "org.nativescript.audio", "tns-ios": { - "version": "2.0.0" + "version": "2.1.1" }, "tns-android": { - "version": "2.0.0" + "version": "2.1.1" } }, "dependencies": { "nativescript-audio": "file:..", "nativescript-snackbar": "^1.0.3", "nativescript-statusbar": "^1.0.0", - "tns-core-modules": "2.0.0" + "tns-core-modules": "next" }, "devDependencies": { - "babel-traverse": "6.7.6", - "babel-types": "6.7.7", - "babylon": "6.7.0", - "filewalker": "0.1.2", - "lazy": "1.0.11", - "nativescript-dev-typescript": "^0.3.1", - "typescript": "^1.8.7" + "babel-traverse": "6.12.0", + "babel-types": "6.11.1", + "babylon": "6.8.4", + "lazy": "1.0.11", + "nativescript-dev-typescript": "^0.3.2", + "typescript": "^1.8.10" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 4ea9831..8b8df51 100755 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "audio.js", "nativescript": { "platforms": { - "android": "2.0.0", - "ios": "1.7.0" + "android": "2.1.1", + "ios": "2.1.1" } }, "scripts": { @@ -54,6 +54,6 @@ "homepage": "https://github.com/bradmartin/nativescript-audio", "readmeFilename": "README.md", "devDependencies": { - "typescript": "^1.8.7" + "typescript": "^1.8.10" } } \ No newline at end of file From 95fcca0eb9e0e969c4a8b91eb7325b0346a6aa61 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sat, 6 Aug 2016 20:43:35 -0700 Subject: [PATCH 2/3] chore: fix typings issue --- package.json | 1 + tsconfig.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b8df51..2aa5c95 100755 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.1", "description": "NativeScript plugin to record and play audio.", "main": "audio.js", + "typings": "index.d.ts", "nativescript": { "platforms": { "android": "2.1.1", diff --git a/tsconfig.json b/tsconfig.json index ce9b1e6..2e81ab7 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,8 @@ "module": "commonjs", "removeComments": true, "experimentalDecorators": true, - "sourceMap": true + "sourceMap": true, + "declaration": true }, "files": [ "demo/node_modules/tns-core-modules/tns-core-modules.d.ts", From 397faed9e2473cea88572d5cdf45e9a009959a12 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sat, 6 Aug 2016 20:58:08 -0700 Subject: [PATCH 3/3] chore: fix typings issues --- .gitignore | 3 ++ .npmignore | 4 +- demo/package.json | 41 +++++++++--------- index.d.ts | 57 +++++++++++++++++++++++++ package.json | 101 ++++++++++++++++++++++---------------------- src/ios/player.ts | 2 +- src/ios/recorder.ts | 10 +++-- tsconfig.json | 3 ++ 8 files changed, 145 insertions(+), 76 deletions(-) create mode 100644 index.d.ts mode change 100755 => 100644 package.json diff --git a/.gitignore b/.gitignore index 390fbef..c7f3e2e 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ *.js *.js.map *.log +*.d.ts +!index.d.ts +demo/lib demo/app/*.js demo/*.d.ts demo/platforms diff --git a/.npmignore b/.npmignore index 59a81b1..92e4444 100755 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,6 @@ demo/ screens/ *.png -*.log \ No newline at end of file +*.log +*.ts +!index.d.ts \ No newline at end of file diff --git a/demo/package.json b/demo/package.json index ca55d3e..578a856 100644 --- a/demo/package.json +++ b/demo/package.json @@ -1,25 +1,26 @@ { - "nativescript": { - "id": "org.nativescript.audio", - "tns-ios": { - "version": "2.1.1" - }, - "tns-android": { - "version": "2.1.1" - } - }, - "dependencies": { - "nativescript-audio": "file:..", - "nativescript-snackbar": "^1.0.3", - "nativescript-statusbar": "^1.0.0", - "tns-core-modules": "next" - }, - "devDependencies": { - "babel-traverse": "6.12.0", + "nativescript": { + "id": "org.nativescript.audio", + "tns-ios": { + "version": "2.1.1" + }, + "tns-android": { + "version": "2.1.1" + } + }, + "dependencies": { + "nativescript-audio": "file:..", + "nativescript-snackbar": "^1.0.3", + "nativescript-statusbar": "^1.0.0", + "tns-core-modules": "next" + }, + "devDependencies": { + "babel-traverse": "6.12.0", "babel-types": "6.11.1", "babylon": "6.8.4", "lazy": "1.0.11", - "nativescript-dev-typescript": "^0.3.2", - "typescript": "^1.8.10" - } + "nativescript-dev-typescript": "^0.3.2", + "tns-platform-declarations": "^2.0.0", + "typescript": "^1.8.10" + } } diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..70e492c --- /dev/null +++ b/index.d.ts @@ -0,0 +1,57 @@ +export interface AudioPlayerOptions { + audioFile: string; + completeCallback?: Function; + errorCallback?: Function; + infoCallback?: Function; +} +export interface AudioRecorderOptions { + filename: string; + maxDuration?: number; + errorCallback?: Function; + infoCallback?: Function; +} +export interface TNSPlayerI { + playFromFile(options: AudioPlayerOptions): Promise; + playFromUrl(options: AudioPlayerOptions): Promise; + play(): Promise; + pause(): Promise; + dispose(): Promise; + isAudioPlaying(): boolean; + getAudioTrackDuration(): Promise; +} +export interface TNSRecordI { + start(options: AudioRecorderOptions): Promise; + stop(): Promise; + dispose(): Promise; +} +export declare class TNSPlayer { + static ObjCProtocols: any[]; + private _player; + private _task; + private _completeCallback; + private _errorCallback; + private _infoCallback; + playFromFile(options: AudioPlayerOptions): Promise; + playFromUrl(options: AudioPlayerOptions): Promise; + pause(): Promise; + play(): Promise; + dispose(): Promise; + isAudioPlaying(): boolean; + getAudioTrackDuration(): Promise; + audioPlayerDidFinishPlayingSuccessfully(player?: any, flag?: boolean): void; + private reset(); +} +export declare class TNSRecorder { + static ObjCProtocols: any[]; + private _recorder; + private _recordingSession; + static CAN_RECORD(): boolean; + start(options: AudioRecorderOptions): Promise; + stop(): Promise; + dispose(): Promise; + isRecording(): any; + getMeters(channel: number): any; + audioRecorderDidFinishRecording(recorder: any, success: boolean): void; +} + + diff --git a/package.json b/package.json old mode 100755 new mode 100644 index 2aa5c95..463d549 --- a/package.json +++ b/package.json @@ -1,60 +1,61 @@ { - "name": "nativescript-audio", - "version": "2.0.1", - "description": "NativeScript plugin to record and play audio.", - "main": "audio.js", + "name": "nativescript-audio", + "version": "2.0.1", + "description": "NativeScript plugin to record and play audio.", + "main": "audio.js", "typings": "index.d.ts", - "nativescript": { - "platforms": { - "android": "2.1.1", + "nativescript": { + "platforms": { + "android": "2.1.1", "ios": "2.1.1" - } - }, - "scripts": { - "build": "tsc", + } + }, + "scripts": { + "build": "tsc", "demo.ios": "npm run preparedemo; cd demo; tns emulate ios", - "demo.android": "npm run preparedemo; cd demo; tns emulate android", - "preparedemo": "npm run build; cd demo; tns plugin remove nativescript-audio; tns plugin add ..; tns install", - "setup": "cd demo; npm install; cd ..; npm run build; cd demo; tns plugin add ..; cd .." - }, - "repository": { - "type": "git", - "url": "https://github.com/bradmartin/nativescript-audio.git" - }, - "keywords": [ - "NativeScript", - "JavaScript", - "TypeScript", - "Android", - "iOS", - "music", - "microphone", - "recorder", - "audio", - "bradmartin", - "nathanwalker" - ], - "author": { - "name": "Brad Martin", - "email": "bradwaynemartin@gmail.com" - }, - "contributors": [ + "demo.android": "npm run preparedemo; cd demo; tns emulate android", + "preparedemo": "npm run build; cd demo; tns plugin remove nativescript-audio; tns plugin add ..; tns install", + "setup": "cd demo; npm install; cd ..; npm run build; cd demo; tns plugin add ..; cd .." + }, + "repository": { + "type": "git", + "url": "https://github.com/bradmartin/nativescript-audio.git" + }, + "keywords": [ + "NativeScript", + "JavaScript", + "TypeScript", + "Android", + "iOS", + "music", + "microphone", + "recorder", + "audio", + "bradmartin", + "nathanwalker" + ], + "author": { + "name": "Brad Martin", + "email": "bradwaynemartin@gmail.com" + }, + "contributors": [ { "name": "Nathanael Walker", "email": " walkerrunpdx@gmail.com", "url": "https://github.com/NathanWalker" } ], - "bugs": { - "url": "https://github.com/bradmartin/nativescript-audio/issues" - }, - "license": { - "type": "MIT", - "url": "https://github.com/bradmartin/nativescript-audio/blob/master/LICENSE" - }, - "homepage": "https://github.com/bradmartin/nativescript-audio", - "readmeFilename": "README.md", - "devDependencies": { - "typescript": "^1.8.10" - } -} \ No newline at end of file + "bugs": { + "url": "https://github.com/bradmartin/nativescript-audio/issues" + }, + "license": { + "type": "MIT", + "url": "https://github.com/bradmartin/nativescript-audio/blob/master/LICENSE" + }, + "homepage": "https://github.com/bradmartin/nativescript-audio", + "readmeFilename": "README.md", + "devDependencies": { + "tns-platform-declarations": "^2.0.0", + "typescript": "^1.8.10" + } +} diff --git a/src/ios/player.ts b/src/ios/player.ts index 438a5c1..bcb9e1c 100644 --- a/src/ios/player.ts +++ b/src/ios/player.ts @@ -56,7 +56,7 @@ export class TNSPlayer extends NSObject implements TNSPlayerI { this._errorCallback=options.errorCallback; this._infoCallback=options.infoCallback; - this._player = AVAudioPlayer.alloc().initWithDataError(data, null); + this._player = (AVAudioPlayer.alloc()).initWithDataError(data, null); this._player.delegate = this; this._player.numberOfLoops = 0; this._player.play(); diff --git a/src/ios/recorder.ts b/src/ios/recorder.ts index 68345b3..d531b4c 100644 --- a/src/ios/recorder.ts +++ b/src/ios/recorder.ts @@ -4,6 +4,8 @@ import {knownFolders, path} from 'file-system'; import {TNSRecordI} from '../common'; import {AudioRecorderOptions} from '../options'; +declare var interop; + export class TNSRecorder extends NSObject implements TNSRecordI { public static ObjCProtocols = [AVAudioRecorderDelegate]; private _recorder: any; @@ -27,14 +29,14 @@ export class TNSRecorder extends NSObject implements TNSRecordI { this._recordingSession.requestRecordPermission((allowed: boolean) => { if (allowed) { - var recordSetting = new NSMutableDictionary([NSNumber.numberWithInt(kAudioFormatMPEG4AAC), NSNumber.numberWithInt(AVAudioQuality.Medium.rawValue), NSNumber.numberWithFloat(16000.0), NSNumber.numberWithInt(1)], - ["AVFormatIDKey", "AVEncoderAudioQualityKey", "AVSampleRateKey", "AVNumberOfChannelsKey"]); + var recordSetting = new NSMutableDictionary(([NSNumber.numberWithInt(kAudioFormatMPEG4AAC), NSNumber.numberWithInt((AVAudioQuality).Medium.rawValue), NSNumber.numberWithFloat(16000.0), NSNumber.numberWithInt(1)]), + (["AVFormatIDKey", "AVEncoderAudioQualityKey", "AVSampleRateKey", "AVNumberOfChannelsKey"])); errorRef = new interop.Reference(); let url = NSURL.fileURLWithPath(options.filename); - this._recorder = AVAudioRecorder.alloc().initWithURLSettingsError(url, recordSetting, errorRef); + this._recorder = (AVAudioRecorder.alloc()).initWithURLSettingsError(url, recordSetting, errorRef); if (errorRef && errorRef.value) { console.log(errorRef.value); } else { @@ -58,7 +60,7 @@ export class TNSRecorder extends NSObject implements TNSRecordI { this._recorder.stop(); // may need this in future // this._recordingSession.setActiveError(false, null); - _this._recorder.meteringEnabled = false; + this._recorder.meteringEnabled = false; resolve(); } catch (ex) { reject(ex); diff --git a/tsconfig.json b/tsconfig.json index 2e81ab7..91bea2f 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,9 @@ }, "files": [ "demo/node_modules/tns-core-modules/tns-core-modules.d.ts", + "node_modules/tns-platform-declarations/android17.d.ts", + "node_modules/tns-platform-declarations/ios.d.ts", + "node_modules/tns-platform-declarations/org.nativescript.widgets.d.ts", "audio.android.ts", "audio.ios.ts" ],