0

Need help on controlling audio in ipad using javascript(mute/unmute)..any solution or thought will be helpful..

codebreaker
  • 1,465
  • 1
  • 12
  • 18

4 Answers4

0

Try this is the OpenSource Library try it out

https://github.com/devgeeks/VolumeSlider

Akshay Joy
  • 1,765
  • 1
  • 14
  • 23
0

phone-gap is the only way to achieve this task, none of the html5 api supports the ipad mute functionality

0

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?

kzfabi
  • 2,065
  • 1
  • 22
  • 26
0

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. 
Community
  • 1
  • 1
shibbs
  • 21
  • 3