This plugin allows you to programmatically control the volume in a NativeScript application. This is compatible with both iOS and Android.
Run the following command from the root of your project:
tns plugin add nativescript-volume
This command automatically installs the necessary files, as well as stores nativescript-volume as a dependency in your project's package.json file.
This plugin can be used with any flavor of NativeScript (Core, Angular, Vue, TypeScript, and/or JavaScript).
import { Volume } from 'nativescript-volume';
export SomeClass {
private volume: Volume;
constructor() {
this.volume = new Volume();
}
mute() {
this.volume.mute();
}
unmute() {
this.volume.unmute();
}
volumeUp() {
this.volume.volumeUp();
}
volumeHalf() {
if (app.ios) {
// iOS Volume goes from 0 to 1. With its increments being 1/16.
this.volume.setVolume(0.5);
} else if (app.android) {
// Android Volume I'm unsure of the range, but believe it to be 0 to 15 at least for the music stream.
this.volume.setVolume(7);
}
}
volumeDown() {
this.volume.volumeDown();
}
getVolume() {
// Please see Android TODO in the Api Section
alert('Volume is' + this.volume.getVolume());
}
}
Method: ReturnType | Description | Notes |
---|---|---|
mute(): void |
Mutes the volume of the Device | |
unmute(): void |
Unmutes the volume of the Device | |
volumeDown(): void |
Decreases the volume of the Device. | Android The device picks the active sound stream. |
volumeUp(): void |
Increases the volume of the Device. | Android The device picks the active sound stream. |
getVolume(): number |
Gets the current volume of the Device. | Android This currently only gets the music stream's volume. |
setVolume(value: number): void |
Sets the current volume of the Device. | Android This currently only sets the music stream's volume. |
The MIT License
1. 前言 Android提供了很多的多媒体接口,通常在java层,我们常用的就是AudioTrack和MediaPlayer进行音频播放。MediaPlayer不光可以播放音频,也可以播放视频,并支持少部分的解码。 而由于音视频通常计算量都很大,所以很多音视频方面的工作都会放在native层进行。Android在native层同样提供了一些组件来进行音频的播放和录制: OpenSL ES:这是A
NativeScript 可以使用 Javascript,CSS, XML 创建真正的 Native 跨平台应用,支持 iOS Android,NativeScript 将您的跨平台代码翻译成目标平台的代码。 UI 使用 XML 描述,CSS 样式,在编译时将 UI 转化成本地原生代码,最终得到正在的 Native 原生应用。 Telerik 公开了用于创建安卓、iOS和Windows Unive
NativeScript Command-Line Interface The NativeScript CLI lets you create, build, and deploy NativeScript-based apps on iOS and Android devices. Get it using: npm install -g nativescript What is Native
NativeScript-Snackbar �� �� �� NativeScript plugin for Material Design SnackBar component. Installation: NativeScript 7+:tns plugin add @nstudio/nativescript-snackbar NativeScript version prior to 7:t
Nativescript-Ripple This plugin aims to bring a native (or close to native) ripple implementation on Android and iOS. The android version uses a RippleDrawable and conserves the previous background, a
NativeScript-FloatingActionButton NativeScript plugin for Material Design Floating Action Button UI component. Installation Nativescript 7+: ns plugin add @nstudio/nativescript-floatingactionbutton Na
NativeScript CardView A NativeScript plugin to provide an XML widget to implement the Material Design CardView component. Installation NativeScript 7+: ns plugin add @nstudio/nativescript-cardview Nat