is Changing sound volume constrained on iPad ?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
macnomad2
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Sat Oct 28, 2006 10:04 pm

is Changing sound volume constrained on iPad ?

Post by macnomad2 » Sun Dec 11, 2011 7:52 pm

Hi
In my iPad app (soon on the store) the user can change the sound volume using a slider
set the play loudness to tVolume
and I use only the "play" commando play short sounds

On the Mac it works fine from 0% to 100%, but on the iPad the volume can only be set up to the maximum set by the user externally (physical volume buttons for example)
If the volume has been set externally to 0, I can't get sound. If it has been set to 30 for example, I can't go higher either

Is this a limitation set by Apple ? How do other apps do ? Can LC do that ?
Does it mean that the user has to set the maximum volume externally, which may be a problem, because LC does not allow for suspend or multitasking ?
Thanks
Georges

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is Changing sound volume constrained on iPad ?

Post by Mark » Thu Dec 15, 2011 5:55 pm

Hi Georges,

It looks like this is a limitation imposed by Apple. You'd need an external to change it.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

macnomad2
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Sat Oct 28, 2006 10:04 pm

Re: is Changing sound volume constrained on iPad ?

Post by macnomad2 » Thu Dec 15, 2011 7:47 pm

Thanks
If this is imposed by Apple, even an external
should be forbidden by Apple to do it (forbidden private APIs)
No ? And I don't know any such external.
Any idea ?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is Changing sound volume constrained on iPad ?

Post by Mark » Thu Dec 15, 2011 7:51 pm

Hi,

The limitation is that you need to use a special API to change the general sound volume. It means that the sound volume of player objects is limited by Apple, but you can still use the API to change the general sound volume. E.g. if you write an app to make it easier to change the user settings on an iPhone, I'd presume that Apple would allow it.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

macnomad2
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Sat Oct 28, 2006 10:04 pm

Re: is Changing sound volume constrained on iPad ?

Post by macnomad2 » Thu Dec 15, 2011 8:52 pm

Thanks a lot

I don't think I am able to write such an external
But I will research how for fun ;)
it would just be in my mind sthing like
SetGlobalVolume tnumber
Georges

macnomad2
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Sat Oct 28, 2006 10:04 pm

Re: is Changing sound volume constrained on iPad ?

Post by macnomad2 » Fri Dec 16, 2011 12:55 pm

OK, so...
From : https://developer.apple.com/library/ios ... index.html

How do I access the hardware volume controller?
Global system volume, including your application's volume, is handled by iPhone OS and is not accessible by applications.

How do I control playback level?
On iPhone and 2nd generation iPod touch, the user controls playback level using the hardware volume control. You can control relative playback level when playing sounds with Audio Queue Services (AudioToolbox/AudioQueue.h). To control relative playback level, create a playback audio queue object and use the AudioQueueSetParameter function with the kAudioQueueParam_Volume parameter.
System Audio Services, AudioToolbox/AudioServices.h, does not offer level control.

So it seems I can't do it, unless somebody has an idea...

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: is Changing sound volume constrained on iPad ?

Post by richardmac » Sat Dec 17, 2011 3:34 am

You can use iPhonePlaySoundOnChannel. You can play audio files with it and it has a way to change the volume. You do it like this:

Code: Select all

-- Start playing the sound
put specialFolderPath("engine") & slash & "sounds/my_audio.aif" into daSound
 iPhonePlaySoundOnChannel daSound, "Ch1","now"
Then to change the volume of the sound being played, do this:

iphoneSetSoundChannelVolume "Ch1", 100

The number at the end is a value from 0 to 100 with 0 being all the way down and 100 being all the way up. You'd tie that to your slider and issue the command in real time. I don't have the code to do that part - never had to write it yet - but the iphoneSetSoundChannelVolume command definitely works very well.

macnomad2
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Sat Oct 28, 2006 10:04 pm

Re: is Changing sound volume constrained on iPad ?

Post by macnomad2 » Sat Dec 17, 2011 12:03 pm

Thank you richardmac, but same result as the play and set the playloudness commands
They are all constrained to relative volume, the global one being set only by physical controls (on iOS)
For the moment I have seen only Apple apps (like" video") able to change global volume.
So I am afraid there is no solution. Well, I understand Apple's point of view from the user perspective.

With LC this is a limitation, because you can't multitask. So if the user needs to multitask in order to change the global volume, LC has to restart...
and my app also. We'll just wait for a "do not exit on suspend" possibility.

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: is Changing sound volume constrained on iPad ?

Post by richardmac » Sat Dec 17, 2011 6:57 pm

Ah, I get it - you want to change the volume of the device itself, meaning if the user turns it down in your app, it would be turned down for the entire machine.

I'm curious as to why you would want this ability. But if it's an important feature for a cool app and you don't want to blab it all over the net, I'd understand. :)

LiveCode is all about workarounds. It's the price tag for having human readable code. :)

Post Reply