1
- [ ![ npm] ( https://img.shields.io/npm/v/nativescript-audio.svg )] ( https://www.npmjs.com/package/nativescript-audio )
2
- [ ![ npm] ( https://img.shields.io/npm/dt/nativescript-audio.svg?label=npm%20downloads )] ( https://www.npmjs.com/package/nativescript-audio )
3
- [ ![ Build Status] ( https://travis-ci.org/bradmartin/nativescript-audio.svg?branch=master )] ( https://travis-ci.org/bradmartin/nativescript-audio )
4
- [ ![ GitHub forks] ( https://img.shields.io/github/forks/bradmartin/nativescript-audio.svg )] ( https://github.com/bradmartin/nativescript-audio/network )
5
- [ ![ GitHub stars] ( https://img.shields.io/github/stars/bradmartin/nativescript-audio.svg )] ( https://github.com/bradmartin/nativescript-audio/stargazers )
6
- [ ![ nStudio Plugin] ( https://img.shields.io/badge/nStudio-Plugin-blue.svg )] ( http://nstudio.io )
1
+ <a align =" center " href =" https://www.npmjs.com/package/nativescript-audio " >
2
+ <h3 align="center">NativeScript Audio</h3>
3
+ </a >
4
+ <h4 align =" center " >NativeScript plugin to play and record audio files for Android and iOS.</h4 >
5
+
6
+ <p align =" center " >
7
+ <a href="https://www.npmjs.com/package/nativescript-audio">
8
+ <img src="https://img.shields.io/npm/v/nativescript-audio.svg" alt="npm">
9
+ </a>
10
+ <a href="https://www.npmjs.com/package/nativescript-audio">
11
+ <img src="https://img.shields.io/npm/dt/nativescript-audio.svg?label=npm%20downloads" alt="npm">
12
+ </a>
13
+ <a href="https://github.com/nstudio/nativescript-audio/stargazers">
14
+ <img src="https://img.shields.io/github/stars/nstudio/nativescript-audio.svg" alt="stars">
15
+ </a>
16
+ <a href="https://github.com/nstudio/nativescript-audio/network">
17
+ <img src="https://img.shields.io/github/forks/nstudio/nativescript-audio.svg" alt="forks">
18
+ </a>
19
+ <a href="https://github.com/nstudio/nativescript-audio/blob/master/src/LICENSE.md">
20
+ <img src="https://img.shields.io/github/license/nstudio/nativescript-audio.svg" alt="license">
21
+ </a>
22
+ <a href="https://paypal.me/bradwayne88">
23
+ <img src="https://img.shields.io/badge/Donate-PayPal-green.svg" alt="donate">
24
+ </a>
25
+ <a href="http://nstudio.io">
26
+ <img src="./screens/nstudio-banner.png" alt="nStudio banner">
27
+ </a>
28
+ <h5 align="center">Do you need assistance on your project or plugin? Contact the nStudio team anytime at <a href="mailto:[email protected] ">[email protected] </a> to get up to speed with the best practices in mobile and web app development.
29
+ </h5>
30
+ </p >
7
31
8
-
9
-
10
- # NativeScript-Audio
11
-
12
- NativeScript plugin to play and record audio files for Android and iOS.
32
+ ---
13
33
14
34
## Installation
15
35
16
- The plugin is compatible with both Nativescript 3.x and 2.x versions. Install with:
17
-
18
36
` tns plugin add nativescript-audio `
19
37
20
38
---
@@ -24,7 +42,7 @@ The plugin is compatible with both Nativescript 3.x and 2.x versions. Install wi
24
42
* [ Player - android.media.MediaPlayer] ( http://developer.android.com/reference/android/media/MediaPlayer.html )
25
43
* [ Recorder - android.media.MediaRecorder] ( http://developer.android.com/reference/android/media/MediaRecorder.html )
26
44
27
- #### iOS Native Classes
45
+ ### iOS Native Classes
28
46
29
47
* [ Player - AVAudioPlayer] ( https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/ )
30
48
* [ Recorder - AVAudioRecorder] ( https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioRecorder_ClassReference/ )
@@ -41,7 +59,7 @@ Note: You will need to grant permissions on iOS to allow the device to access th
41
59
### TypeScript Example
42
60
43
61
``` typescript
44
- import { TNSPlayer } from " nativescript-audio" ;
62
+ import { TNSPlayer } from ' nativescript-audio' ;
45
63
46
64
export class YourClass {
47
65
private _player: TNSPlayer ;
@@ -51,7 +69,7 @@ export class YourClass {
51
69
this ._player .debug = true ; // set true to enable TNSPlayer console logs for debugging.
52
70
this ._player
53
71
.initFromFile ({
54
- audioFile: " ~/audio/song.mp3" , // ~ = app directory
72
+ audioFile: ' ~/audio/song.mp3' , // ~ = app directory
55
73
loop: false ,
56
74
completeCallback: this ._trackComplete .bind (this ),
57
75
errorCallback: this ._trackError .bind (this )
@@ -74,31 +92,31 @@ export class YourClass {
74
92
}
75
93
76
94
private _trackComplete(args : any ) {
77
- console .log (" reference back to player:" , args .player );
95
+ console .log (' reference back to player:' , args .player );
78
96
// iOS only: flag indicating if completed succesfully
79
- console .log (" whether song play completed successfully:" , args .flag );
97
+ console .log (' whether song play completed successfully:' , args .flag );
80
98
}
81
99
82
100
private _trackError(args : any ) {
83
- console .log (" reference back to player:" , args .player );
84
- console .log (" the error:" , args .error );
101
+ console .log (' reference back to player:' , args .player );
102
+ console .log (' the error:' , args .error );
85
103
// Android only: extra detail on error
86
- console .log (" extra info on the error:" , args .extra );
104
+ console .log (' extra info on the error:' , args .extra );
87
105
}
88
106
}
89
107
```
90
108
91
109
### Javascript Example:
92
110
93
111
``` javascript
94
- const audio = require (" nativescript-audio" );
112
+ const audio = require (' nativescript-audio' );
95
113
96
114
const player = new audio.TNSPlayer ();
97
115
const playerOptions = {
98
- audioFile: " http://some/audio/file.mp3" ,
116
+ audioFile: ' http://some/audio/file.mp3' ,
99
117
loop: false ,
100
118
completeCallback : function () {
101
- console .log (" finished playing" );
119
+ console .log (' finished playing' );
102
120
},
103
121
errorCallback : function (errorObject ) {
104
122
console .log (JSON .stringify (errorObject));
@@ -114,7 +132,7 @@ player
114
132
console .log (res);
115
133
})
116
134
.catch (function (err ) {
117
- console .log (" something went wrong..." , err);
135
+ console .log (' something went wrong...' , err);
118
136
});
119
137
```
120
138
@@ -124,18 +142,18 @@ player
124
142
125
143
#### TNSRecorder Methods
126
144
127
- | Method | Description |
128
- | ----------------------------------------------------------- | --------------------------------------------------------- |
129
- | _ TNSRecorder.CAN_RECORD()_ : ` boolean ` - ** _ static method_ ** | Determine if ready to record. |
130
- | _ start(options: AudioRecorderOptions)_ : ` Promise<void> ` | Start recording to file. |
131
- | _ stop()_ : ` Promise<void> ` | Stop recording. |
132
- | _ pause()_ : ` Promise<void> ` | Pause recording. |
133
- | _ resume()_ : ` Promise<void> ` | Resume recording. |
134
- | _ dispose()_ : ` Promise<void> ` | Free up system resources when done with recorder. |
135
- | _ getMeters(channel?: number)_ : ` number ` | Returns the amplitude of the input. |
136
- | _ isRecording()_ : ` boolean ` - ** _ iOS Only_ ** | Returns true if recorder is actively recording. |
137
- | _ requestRecordPermission()_ : ` Promise<void> ` | * Android Only * Resolves the promise is user grants the permission. |
138
- | _ hasRecordPermission()_ : ` boolean ` | * Android Only * Returns true if RECORD_AUDIO permission has been granted. |
145
+ | Method | Description |
146
+ | ----------------------------------------------------------- | ------------------------------------------------------------------------ |
147
+ | _ TNSRecorder.CAN_RECORD()_ : ` boolean ` - ** _ static method_ ** | Determine if ready to record. |
148
+ | _ start(options: AudioRecorderOptions)_ : ` Promise<void> ` | Start recording to file. |
149
+ | _ stop()_ : ` Promise<void> ` | Stop recording. |
150
+ | _ pause()_ : ` Promise<void> ` | Pause recording. |
151
+ | _ resume()_ : ` Promise<void> ` | Resume recording. |
152
+ | _ dispose()_ : ` Promise<void> ` | Free up system resources when done with recorder. |
153
+ | _ getMeters(channel?: number)_ : ` number ` | Returns the amplitude of the input. |
154
+ | _ isRecording()_ : ` boolean ` - ** _ iOS Only_ ** | Returns true if recorder is actively recording. |
155
+ | _ requestRecordPermission()_ : ` Promise<void> ` | _ Android Only _ Resolves the promise is user grants the permission. |
156
+ | _ hasRecordPermission()_ : ` boolean ` | _ Android Only _ Returns true if RECORD_AUDIO permission has been granted. |
139
157
140
158
#### TNSRecorder Instance Properties
141
159
@@ -174,6 +192,6 @@ player
174
192
| _ currentTime_ : ` number ` | Get the current time in the media file's duration. |
175
193
| _ volume_ : ` number ` | Get/Set the player volume. Value range from 0 to 1. |
176
194
177
- ## License
195
+ ### License
178
196
179
197
[ MIT] ( /LICENSE )
0 commit comments