Skip to content

Commit d708473

Browse files
committed
feat: added ability to enable metering for Player on iOS
1 parent 1958f9c commit d708473

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
demo/
22
screens/
3+
node_modules/
4+
tsconfig.json
35
*.png
46
*.log
57
*.ts

index.d.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ export interface AudioPlayerOptions {
1111
loop: boolean;
1212

1313
/**
14-
* Instead of auto-playing, just init the player instance
14+
* Prevent autoplay if desired as player autoplays be default
1515
*/
16-
initOnly?: boolean;
16+
autoPlay?: boolean;
17+
18+
/**
19+
* Set true to enable audio metering.
20+
*/
21+
metering?: boolean;
1722

1823
/**
1924
* Callback to execute when playback has completed.
@@ -79,7 +84,11 @@ export interface AudioRecorderOptions {
7984
infoCallback?: Function;
8085
}
8186
export interface TNSPlayerI {
87+
readonly ios?: any;
88+
readonly android?: any;
89+
initFromFile(options: AudioPlayerOptions): Promise<any>;
8290
playFromFile(options: AudioPlayerOptions): Promise<any>;
91+
initFromUrl(options: AudioPlayerOptions): Promise<any>;
8392
playFromUrl(options: AudioPlayerOptions): Promise<any>;
8493
play(): Promise<boolean>;
8594
pause(): Promise<boolean>;
@@ -101,7 +110,11 @@ export declare class TNSPlayer {
101110
private _completeCallback;
102111
private _errorCallback;
103112
private _infoCallback;
113+
readonly ios: any;
114+
readonly android: any;
115+
initFromFile(options: AudioPlayerOptions): Promise<any>;
104116
playFromFile(options: AudioPlayerOptions): Promise<any>;
117+
initFromUrl(options: AudioPlayerOptions): Promise<any>;
105118
playFromUrl(options: AudioPlayerOptions): Promise<any>;
106119
pause(): Promise<any>;
107120
resume(): void;
@@ -111,6 +124,7 @@ export declare class TNSPlayer {
111124
isAudioPlaying(): boolean;
112125
getAudioTrackDuration(): Promise<string>;
113126
audioPlayerDidFinishPlayingSuccessfully(player?: any, flag?: boolean): void;
127+
readonly currentTime: number;
114128
private reset();
115129
}
116130
export declare class TNSRecorder {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-audio",
3-
"version": "3.1.0",
3+
"version": "3.1.5",
44
"description": "NativeScript plugin to record and play audio.",
55
"main": "audio",
66
"typings": "index.d.ts",

src/common.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import {AudioPlayerOptions, AudioRecorderOptions} from './options';
22

33
export interface TNSPlayerI {
4+
/**
5+
* native instance getters
6+
*/
7+
readonly ios?: any;
8+
readonly android?: any;
9+
410
/**
511
* Starts playing audio file from local app files.
612
*/
@@ -40,6 +46,11 @@ export interface TNSPlayerI {
4046
* Get the duration of the audio file playing.
4147
*/
4248
getAudioTrackDuration(): Promise<string>;
49+
50+
/**
51+
* current time
52+
*/
53+
readonly currentTime: number;
4354
}
4455

4556
export interface TNSRecordI {

src/ios/player.ts

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export class TNSPlayer extends NSObject implements TNSPlayerI {
4747
this._player = AVAudioPlayer.alloc().initWithContentsOfURLError(NSURL.fileURLWithPath(fileName));
4848
this._player.delegate = this;
4949

50+
if (options.metering) {
51+
this._player.meteringEnabled = true;
52+
}
53+
5054
if (options.loop) {
5155
this._player.numberOfLoops = -1;
5256
}
@@ -97,6 +101,10 @@ export class TNSPlayer extends NSObject implements TNSPlayerI {
97101
this._player = (<any>AVAudioPlayer.alloc()).initWithDataError(data, null);
98102
this._player.delegate = this;
99103
this._player.numberOfLoops = options.loop ? -1 : 0;
104+
105+
if (options.metering) {
106+
this._player.meteringEnabled = true;
107+
}
100108

101109
if (options.autoPlay) this._player.play();
102110

src/options.ts

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export interface AudioPlayerOptions {
2323
*/
2424
autoPlay?: boolean;
2525

26+
/**
27+
* Enable metering. Off by default.
28+
*/
29+
metering?: boolean;
30+
2631
/**
2732
* Gets or sets the callback when an error occurs with the audio player.
2833
* @returns {Object} An object containing the native values for the error callback.

0 commit comments

Comments
 (0)