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 21669b3..578a856 100644 --- a/demo/package.json +++ b/demo/package.json @@ -1,26 +1,26 @@ { - "nativescript": { - "id": "org.nativescript.audio", - "tns-ios": { - "version": "2.0.0" - }, - "tns-android": { - "version": "2.0.0" - } - }, - "dependencies": { - "nativescript-audio": "file:..", - "nativescript-snackbar": "^1.0.3", - "nativescript-statusbar": "^1.0.0", - "tns-core-modules": "2.0.0" - }, - "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" - } -} \ No newline at end of file + "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", + "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 4ea9831..463d549 --- a/package.json +++ b/package.json @@ -1,59 +1,61 @@ { - "name": "nativescript-audio", - "version": "2.0.1", - "description": "NativeScript plugin to record and play audio.", - "main": "audio.js", - "nativescript": { - "platforms": { - "android": "2.0.0", - "ios": "1.7.0" - } - }, - "scripts": { - "build": "tsc", + "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", + "ios": "2.1.1" + } + }, + "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.7" - } -} \ 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 ce9b1e6..91bea2f 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,10 +4,14 @@ "module": "commonjs", "removeComments": true, "experimentalDecorators": true, - "sourceMap": true + "sourceMap": true, + "declaration": true }, "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" ],