Skip to content

Commit 240e1c3

Browse files
committed
fix the android mute setter
1 parent 26b2a65 commit 240e1c3

File tree

8 files changed

+39
-26
lines changed

8 files changed

+39
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
!references.d.ts
66
!index.d.ts
77
!manual_typings/base.d.ts
8+
demo/e2e/
89
demo/lib
910
demo/app/*.js
1011
demo/*.d.ts

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939

4040
### Android Native Classes
4141

42-
* [Player - android.media.MediaPlayer](http://developer.android.com/reference/android/media/MediaPlayer.html)
43-
* [Recorder - android.media.MediaRecorder](http://developer.android.com/reference/android/media/MediaRecorder.html)
42+
- [Player - android.media.MediaPlayer](http://developer.android.com/reference/android/media/MediaPlayer.html)
43+
- [Recorder - android.media.MediaRecorder](http://developer.android.com/reference/android/media/MediaRecorder.html)
4444

4545
### iOS Native Classes
4646

47-
* [Player - AVAudioPlayer](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/)
48-
* [Recorder - AVAudioRecorder](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioRecorder_ClassReference/)
47+
- [Player - AVAudioPlayer](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/)
48+
- [Recorder - AVAudioRecorder](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioRecorder_ClassReference/)
4949

5050
Note: You will need to grant permissions on iOS to allow the device to access the microphone if you are using the recording function. If you don't, your app may crash on device and/or your app might be rejected during Apple's review routine. To do this, add this key to your `app/App_Resources/iOS/Info.plist` file:
5151

@@ -195,3 +195,9 @@ player
195195
### License
196196

197197
[MIT](/LICENSE)
198+
199+
### Demo App
200+
201+
- fork/clone the repository
202+
- cd into the `src` directory
203+
- execute `npm run demo.android` or `npm run demo.ios` (scripts are located in the `scripts` of the package.json in the `src` directory if you are curious)

demo/app/main-page.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<TabViewItem title="Player">
2424
<TabViewItem.view>
2525
<ScrollView>
26-
<GridLayout rows="auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto" columns="*, *, *" class="p-10">
26+
<GridLayout rows="auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto" columns="*, *, *" class="p-10">
2727
<label row="0" colSpan="3" class="center text-primary h3" text="Welcome To Fight Club!" textWrap="true" />
2828
<button row="1" colSpan="3" class="btn btn-primary" text="Play Remote Audio" tap="{{ playRemoteFile }}" />
2929
<label row="2" colSpan="3" text="Note: Remote files can have a lag before playing due to processing and network speeds." class="h4" textWrap="true" />
@@ -42,6 +42,8 @@
4242
<Label row="10" col="0" text="Volume Slider: " textWrap="true" class="m-t-20" />
4343
<Slider row="10" col="1" colSpan="2" id="volumeSlider" minValue="0" maxValue="100" value="100" class="m-t-20" />
4444
<Label text="{{ 'Current Volume for Player ' + currentVolume }}" textWrap="true" />
45+
<Button row="11" col="0" text="Mute" class="btn btn-primary" tap="{{ muteTap }}" />
46+
<Button row="11" col="1" text="Unmute" class="btn btn-primary" tap="{{ unmuteTap }}" />
4547
</GridLayout>
4648
</ScrollView>
4749
</TabViewItem.view>

demo/app/main-view-model.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ export class AudioDemo extends Observable {
285285
this._player.play();
286286
}
287287

288+
public muteTap() {
289+
this._player.volume = 0;
290+
}
291+
292+
public unmuteTap() {
293+
this._player.volume = 1;
294+
}
295+
288296
public playSpeed1() {
289297
this._player.changePlayerSpeed(1);
290298
}

demo/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"id": "org.nativescript.audio",
44
"tns-ios": {
55
"version": "4.1.0"
6+
},
7+
"tns-android": {
8+
"version": "4.1.3"
69
}
710
},
811
"dependencies": {

src/android/player.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class TNSPlayer implements TNSPlayerI {
4343
}
4444

4545
set volume(value: number) {
46-
if (this._player && value) {
46+
if (this._player && value >= 0) {
4747
this._player.setVolume(value, value);
4848
}
4949
}
@@ -365,7 +365,7 @@ export class TNSPlayer implements TNSPlayerI {
365365
}
366366

367367
private _getAndroidContext() {
368-
const ctx = app.android.context
368+
const ctx = app.android.context;
369369
if (ctx === null) {
370370
setTimeout(() => {
371371
this._getAndroidContext();

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"demo.reset": "cd ../demo && rimraf platforms",
1818
"demo.ios": "npm run preparedemo && cd ../demo && tns run ios --syncAllFiles",
1919
"demo.ios.device": "npm run preparedemo && cd ../demo && tns platform remove ios && tns run ios",
20-
"demo.android": "npm i && npm run tsc && cd ../demo && tns run android --syncAllFiles",
20+
"demo.android": "npm run preparedemo && cd ../demo && tns run android --syncAllFiles",
2121
"test": "npm run tslint && npm run tslint.demo && cd ../demo && tns build ios && tns build android",
2222
"test.ios": "cd ../demo && tns platform remove ios && tns test ios --emulator",
2323
"test.ios.device": "cd ../demo && tns platform remove ios && tns test ios",

src/tsconfig.json

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
4-
"module": "commonjs",
5-
"declaration": false,
3+
"noEmitOnError": false,
4+
"noEmitHelpers": true,
5+
"sourceMap": false,
66
"removeComments": true,
7+
"declaration": false,
8+
"experimentalDecorators": true,
79
"noLib": false,
810
"emitDecoratorMetadata": true,
9-
"experimentalDecorators": true,
11+
"target": "es5",
12+
"module": "commonjs",
1013
"lib": ["es6", "dom"],
14+
"skipLibCheck": true,
15+
"rootDir": ".",
1116
"baseUrl": ".",
1217
"paths": {
1318
"*": ["./node_modules/tns-core-modules/*", "./node_modules/*"]
14-
},
15-
"skipLibCheck": true,
16-
"sourceMap": true,
17-
"pretty": true,
18-
"allowUnreachableCode": false,
19-
"allowUnusedLabels": false,
20-
"noEmitHelpers": true,
21-
"noEmitOnError": false,
22-
"noImplicitAny": false,
23-
"noImplicitReturns": true,
24-
"noImplicitUseStrict": false,
25-
"noFallthroughCasesInSwitch": true
19+
}
2620
},
27-
"exclude": ["node_modules"],
28-
"compileOnSave": false
21+
"exclude": ["node_modules"]
2922
}

0 commit comments

Comments
 (0)