ThispluginallowsyoutoprogrammaticallycontrolthevolumeinaNativeScriptapplication.ThisiscompatiblewithbothiOSandAndroid.
InstallationRunthefollowingcommandfromtherootofyourproject:
tnspluginaddnativescript-volumeThiscommandautomaticallyinstallsthenecessaryfiles,aswellasstoresnativescript-volumeasadependencyinyourproject'spackage.jsonfile.
UsageThisplugincanbeusedwithanyflavorofNativeScript(Core,Angular,Vue,TypeScript,and/orJavaScript).
TypeScriptimport{Volume}from'nativescript-volume';exportSomeClass{privatevolume:Volume;constructor(){this.volume=newVolume();}mute(){this.volume.mute();}unmute(){this.volume.unmute();}volumeUp(){this.volume.volumeUp();}volumeHalf(){if(app.ios){//iOSVolumegoesfrom0to1.Withitsincrementsbeing1/16.this.volume.setVolume(0.5);}elseif(app.android){//AndroidVolumeI'munsureoftherange,butbelieveittobe0to15atleastforthemusicstream.this.volume.setVolume(7);}}volumeDown(){this.volume.volumeDown();}getVolume(){//PleaseseeAndroidTODOintheApiSectionalert('Volumeis'+this.volume.getVolume());}}APIMethod:ReturnTypeDescriptionNotesmute():voidMutesthevolumeoftheDeviceunmute():voidUnmutesthevolumeoftheDevicevolumeDown():voidDecreasesthevolumeoftheDevice.AndroidThedevicepickstheactivesoundstream.volumeUp():voidIncreasesthevolumeoftheDevice.AndroidThedevicepickstheactivesoundstream.getVolume():numberGetsthecurrentvolumeoftheDevice.AndroidThiscurrentlyonlygetsthemusicstream'svolume.setVolume(value:number):voidSetsthecurrentvolumeoftheDevice.AndroidThiscurrentlyonlysetsthemusicstream'svolume.LicenseTheMITLicense
评论