I see that new audioSession properties are available to get and set in the latest daily build. Is there any documentation on these? [import]uid: 2646 topic_id: 10882 reply_id: 310882[/import]
We still haven’t finalized the API so it is not documented. I am aware some people are blocked by this, so here is some of the preliminary API. Be aware, we may completely change this and break your programs so use at your own risk. Do not expect us to provide a warning or migration path. Also be aware, that this API is considered for “advanced users with very specific needs” and should not be used by anybody who doesn’t absolutely need it. Opting into this API will disable some automatic management we do behind the scenes and will allow you to break your programs if you misuse the API. Also, this API currently is only supported on iOS. (No other platforms have a notion of AudioSessions.)
– returns true on iOS, false on other platforms
local is_supported = audio.supportsSessionProperty
– To set a property:
audio.setSessionProperty( property_name, property_value )
– To get a property
local property_value = audio.getSessionProperty( property_name )
Some property names:
audio.ActiveMode (corresponds to Apple’s AudioSessionSetActive)
audio.MixMode (corresponds to Apple’s kAudioSessionProperty_AudioCategory)
audio.OverrideMixWithOthers
audio.OtherAudioIsPlaying (read-only)
audio.OtherMixableAudioShouldDuck
Some property values:
audio.AmbientMixMode
audio.SoloAmbientMixMode
audio.MediaPlaybackMixMode
audio.RecordAudioMixMode
audio.PlayAndRecordMixMode
Examples:
-- If another app/iPod is playing background music, then allow that music to continue playing,
-- otherwise, play my own background music
if audio.getSessionProperty( audio.OtherAudioIsPlaying ) == 1 then
audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)
else
myBackgroundMusic = audio.loadStream("MyMusic.aac")
audio.play(myBackgroundMusic, {loops=-1})
end
-- Backdoor trick (we will not support this):
-- If you do some research, you can learn that Apple's constant for
-- kAudioSessionProperty\_CurrentHardwareOutputVolume
-- is 1667788662. As an implementation detail, our API currently will pass numbers through.
-- Note kAudioSessionProperty\_CurrentHardwareOutputVolume is a read-only property.
local master\_ringer\_volume = audio.getSessionProperty(1667788662)
You should read Apple’s documentation for more information about Audio Sessions:
http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategories/AudioSessionCategories.html%23//apple_ref/doc/uid/TP40007875-CH4-SW1
http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html%23//apple_ref/doc/uid/TP40007875-CH6-SW1
http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html
We would appreciate feedback on what Audio Session properties you feel you absolutely need and what you feel the final Corona API should look like. (What feels more Corona-ish to you.)
[Update: Changed above code to reflect current API in daily builds] [import]uid: 7563 topic_id: 10882 reply_id: 40474[/import]
Thanks for showing pre-release stuff from Ansca’s labs
But it’s not working for me (build 537), I thought changing “if audio.getSessionProperty( audio.kOtherAudioIsPlaying ) then” for “if audio.getSessionProperty( audio.kOtherAudioIsPlaying ) == 1” would do it, but no [import]uid: 10426 topic_id: 10882 reply_id: 40481[/import]
if I just put “audio.setSessionProperty(audio.kMixMode, audio.kAmbientSound)” without going through any “if” statement it works :).
So the whole “if audio.getSessionProperty( audio.kOtherAudioIsPlaying ) == 1” seems to be the problem for me.
PS. OpenFeint it’s not working as a result? :)/ [import]uid: 10426 topic_id: 10882 reply_id: 40482[/import]
What does calling audio.getSessionProperty( audio.kOtherAudioIsPlaying ) by itself return?
What does printing audio.kOtherAudioIsPlaying show?
Does calling audio.getSessionProperty on something else return a legitimate value, say audio.getSessionProperty( audio.kMixMode ) or audio.getSessionProperty(1667788662)?
[import]uid: 7563 topic_id: 10882 reply_id: 40483[/import]
I’ve tried using the following setting (to allow audio to continue playing when the screen is locked)
audio.setSessionProperty(audio.kMediaPlayback)
and I get the following error:
Unsupported key: kMediaPlayback in audio library [import]uid: 2646 topic_id: 10882 reply_id: 40519[/import]
That error message should only appear on non-iOS devices. Are you sure that is not a Mac simulator message?
I’m not sure if screen locking is going to work yet. There is a bunch of code in Corona that suspends itself (perhaps too aggressively), such as app backgrounding, when perhaps we shouldn’t be suspending. Screen locking might be intertwined in all that.
[import]uid: 7563 topic_id: 10882 reply_id: 40553[/import]
The error message is from the Corona iPhone simulator. [import]uid: 2646 topic_id: 10882 reply_id: 40554[/import]
You should ignore that message in the simulator, or wrap your code in an if block so it doesn’t execute on unsupported platforms
if audio.supportsSessionProperty then
– do audio session stuff
end
[import]uid: 7563 topic_id: 10882 reply_id: 40556[/import]
I can’t ignore it in the simulator as it is a runtime error so the app doesn’t go any further. Putting the if statement in means that it doesn’t have any effect on the iPhone as it says it’s unsupported, so how am I supposed to use it? Are you saying that it should/might work on the device but not on the simulator? It crashes on the Xcode simulator too. [import]uid: 2646 topic_id: 10882 reply_id: 40557[/import]
@spjnowak
Yes, this only works on an actual iOS device.
Even if you get the error for not using the if statement on the simulator it still works on the device.
There are many things (webView, OpenFeint) that won’t work on the simulator because it pretty much has nothing to do with the actual device. Please keep us posted on your results.
@ ewing I’m going to start testing now.
[import]uid: 10426 topic_id: 10882 reply_id: 40564[/import]
I just tried a device build and that crashed too. [import]uid: 2646 topic_id: 10882 reply_id: 40566[/import]
Again, you should wrap your audio session calls in a block like so:
if audio.supportsSessionProperty then
– do audio session stuff
end
audio.supportsSessionProperty should return false on unsupported platforms and will then avoid the undefined key problem.
Crashing on the Xcode simulator is not intended. That we’ll have to look into.
[import]uid: 7563 topic_id: 10882 reply_id: 40567[/import]
Which command(s) are crashing on your device build. And which ones don’t crash? [import]uid: 7563 topic_id: 10882 reply_id: 40568[/import]
All I’m getting on the Xcode console is Jun 13 15:35:42 unknown FastCatch[581] : Error setting audio session active! 560030580 and I can’t see any print message at all (trying to figure out where I messed up) so no answers to your questions yet.
PS. The method that works for me in the iPad 1 doesn’t work in an iPod Touch 2g. [import]uid: 10426 topic_id: 10882 reply_id: 40570[/import]
I have only used the following code …
if audio.supportsSessionProperty then
audio.setSessionProperty(audio.kMediaPlayback)
end
… oh, and one other thing, I am running iOS5 on my phone … [import]uid: 2646 topic_id: 10882 reply_id: 40572[/import]
Are you playing with audio.kActiveMode? If so, generally, you shouldn’t have to set this yourself. We try to turn this one on for you.
[import]uid: 7563 topic_id: 10882 reply_id: 40574[/import]
I haven’y used any other property settings. What’s that one supposed to do? [import]uid: 2646 topic_id: 10882 reply_id: 40577[/import]
I need you all to tell me more precisely which commands are working and which commands are not. I need a baseline to know what is working and what is not. If you think a command is failing, please run the command on it’s own line and tell me what the return result is with any error output. I also need to know which platform and which OS version.
Also please verify if any commands are working for you. If nothing is working, please check the Corona version number.
[import]uid: 7563 topic_id: 10882 reply_id: 40578[/import]
You used the command incorrectly. setSessionProperty takes 2 parameters.
if audio.supportsSessionProperty then
audio.setSessionProperty(audio.kMixMode, audio.kMediaPlayback)
end
[import]uid: 7563 topic_id: 10882 reply_id: 40579[/import]