简体   繁体   English

反正有使用ipad中的javascript控制静音/取消静音的功能

[英]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 https://github.com/devgeeks/VolumeSlider

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

I wanted our app to don't play sounds when the iPhone is muted. 我希望我们的应用在iPhone静音时不播放声音。 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. 文档没有说明此参数将使iPhone静音时无法播放声音,但它的行为是这样的。

I'm using PhoneGap 2.6.0 and the docs says: 我正在使用PhoneGap 2.6.0,文档说:

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). 将此选项传递给play方法,以指定在屏幕锁定时是否要播放媒体文件的音频(如果未设置,则默认为true)。 If this is set to true, it will ignore the state of the hardware mute button. 如果将其设置为true,它将忽略硬件静音按钮的状态。

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. iOS没有为您提供明确的方法来设置设备的音量,但是有一种解决方法。 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. 这是针对ios找出的,并在以下iOS 7中进行了解释:不建议使用MPMusicPlayerController卷。 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. 但是,这不是用javascript编写的,我们使用phonegap,因此我们派出了devgeeks库来创建一种方法,以编程方式从您的应用控制设备的播放音量。 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. 这不会给您完整的静音/取消静音控制,但是您至少可以将其设置为0(静音)或非零的音量。 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. 我们已经将其移植到iOS和Android,我们的fork可以在这里找到-https: //github.com/shibbs/VolumeSlider我们已经创建了pull请求,但是它不在主仓库中。

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. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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