简体   繁体   中英

Is there anyway to control mute/unmute using javascript in ipad

在使用javascript(静音/取消静音)控制ipad中的音频方面需要帮助。任何解决方案或思想都将有所帮助。

Try this is the OpenSource Library try it out

https://github.com/devgeeks/VolumeSlider

phone-gap是完成此任务的唯一方法,html5 api均不支持ipad静音功能

I wanted our app to don't play sounds when the iPhone is muted. After hours of searching I decided to try with the following parameter and works as expected:

myMedia.play({ playAudioWhenScreenIsLocked : false });

The documentation doesn't say anything that this parameter will make the sound to not play when the iPhone is muted, but it behaves like that.

I'm using PhoneGap 2.6.0 and the docs says:

Pass in this option to the play method to specify whether you want to play the audio of the media file when the screen is locked (this defaults to true if not set). If this is set to true, it will ignore the state of the hardware mute button.

Bad documented?

This is old, but as we were just solving this issue, I thought I'd put it up here.

iOS doesn't give you an explicit way to set your device's volume, but there is a way around this. To get around this, you can create an audio slider for your specific audio stream, hide it, and then programmatically set the slider's volume. This was figured out for ios and explained here iOS 7: MPMusicPlayerController volume deprecated. How to change device volume now?

However, that is not in javascript, and we use phonegap, so we forked the devgeeks library to create a way to programmatically control the device's playback volume from your app. This won't give you complete mute/unmute control, but you can at least set it to volume of 0 (muted) or something non-zero. We've ported it to iOS and Android, and our fork can be found here - https://github.com/shibbs/VolumeSlider We've created a pull request, but it's not yet in the main repo.

Below is some code showing how to use the library -

my_media = new Media(soundFile, onSuccess, onError); //create the media object
my_media.setVolume(1.0); //set your volume to w/e you want, we maxed it
volumeSlider = plugins.volumeSlider; //create the volume slider object
volumeSlider.createVolumeSlider(10,350,300,30); // origin x,     origin y, width, height
volumeSlider.setVolumeSlider(1.0); //set your volume slider value to between 0 and 1

volumeSlider.resetVolumeSlider(); //this will reset the device volume to whatever it was set to when you created the volumeSlider. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM