Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*.js
*.js.map
*.log
*.d.ts
!index.d.ts
demo/lib
demo/app/*.js
demo/*.d.ts
demo/platforms
Expand Down
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
demo/
screens/
*.png
*.log
*.log
*.ts
!index.d.ts
50 changes: 25 additions & 25 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
"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"
}
}
57 changes: 57 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<any>;
playFromUrl(options: AudioPlayerOptions): Promise<any>;
play(): Promise<boolean>;
pause(): Promise<boolean>;
dispose(): Promise<boolean>;
isAudioPlaying(): boolean;
getAudioTrackDuration(): Promise<string>;
}
export interface TNSRecordI {
start(options: AudioRecorderOptions): Promise<any>;
stop(): Promise<any>;
dispose(): Promise<any>;
}
export declare class TNSPlayer {
static ObjCProtocols: any[];
private _player;
private _task;
private _completeCallback;
private _errorCallback;
private _infoCallback;
playFromFile(options: AudioPlayerOptions): Promise<any>;
playFromUrl(options: AudioPlayerOptions): Promise<any>;
pause(): Promise<any>;
play(): Promise<any>;
dispose(): Promise<any>;
isAudioPlaying(): boolean;
getAudioTrackDuration(): Promise<string>;
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<any>;
stop(): Promise<any>;
dispose(): Promise<any>;
isRecording(): any;
getMeters(channel: number): any;
audioRecorderDidFinishRecording(recorder: any, success: boolean): void;
}


104 changes: 53 additions & 51 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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"
}
}
"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"
}
}
2 changes: 1 addition & 1 deletion src/ios/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (<any>AVAudioPlayer.alloc()).initWithDataError(data, null);
this._player.delegate = this;
this._player.numberOfLoops = 0;
this._player.play();
Expand Down
10 changes: 6 additions & 4 deletions src/ios/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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((<any>[NSNumber.numberWithInt(kAudioFormatMPEG4AAC), NSNumber.numberWithInt((<any>AVAudioQuality).Medium.rawValue), NSNumber.numberWithFloat(16000.0), NSNumber.numberWithInt(1)]),
(<any>["AVFormatIDKey", "AVEncoderAudioQualityKey", "AVSampleRateKey", "AVNumberOfChannelsKey"]));

errorRef = new interop.Reference();

let url = NSURL.fileURLWithPath(options.filename);

this._recorder = AVAudioRecorder.alloc().initWithURLSettingsError(url, recordSetting, errorRef);
this._recorder = (<any>AVAudioRecorder.alloc()).initWithURLSettingsError(url, recordSetting, errorRef);
if (errorRef && errorRef.value) {
console.log(errorRef.value);
} else {
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down