ChannelState(c) returns -1 regardless of state

Monkey Targets Forums/Android/ChannelState(c) returns -1 regardless of state

Derron(Posted 2015) [#1]
On my own android 4.3 device "ChannelState" returns -1 regardless of playing or not.
On another device I just tested (also 4.3) it works as expected.

Ideas how to narrow down why channel state does not work as expected there?

Else it isnt that easy to have some kind of "channel pool" to use for your app.


Edit:
I came across this:
http://www.monkey-x.com/Community/posts.php?topic=4156&post=44658&view=all#44658

... seems others have got "odd return values" too.

If this is still true (dunno the latest monkey changes) this means I should try to keep my sfx low and reuse the same channel for the same sfx (one for the player "jump sounds", one for "shoot" and so on). - so double jumps would stop the prior sound - which happens not that often.
Or I know how long sounds play and manuall adjust sound states accordingly.

For the last option: is there a function in Monkey available returning the length of a sound file (play duration)?


Edit2:
logcat brings things like this:
E/AudioCache(  300): Heap size overflow! req size: 1052672, max size: 1048576
... about 100x
E/AudioCache(  300): Heap size overflow! req size: 1052672, max size: 1048576
E/AudioCache(  300): Heap size overflow! req size: 1051648, max size: 1048576
E/AudioFlinger(  300): not enough memory for AudioTrack size=1048640
E/AudioTrack(15221): AudioFlinger could not create track, status: -12
E/SoundPool(15221): Error creating AudioTrack
E/TrackUtils(15221): Tunnel Playback please ignore



Edit3:
Tried it on an older device (android 2.3.7):
E/AudioCache( 1965): Heap size overflow! req size: 1052672, max size: 1048576
E/AudioCache( 1965): Heap size overflow! req size: 1052672, max size: 1048576
...
...
E/AudioCache( 1965): Heap size overflow! req size: 1052672, max size: 1048576
E/AudioFlinger( 1965): not enough memory for AudioTrack size=1048640
E/AudioTrack( 8348): AudioFlinger could not create track, status: -12
E/SoundPool( 8348): Error creating AudioTrack
E/AudioHardwareMSM72XX( 1965): FM CMD: hcitool cmd 0x3f 0x15 0xf8 0 0xf 0
E/AudioHardwareMSM72XX( 1965): FM CMD: hcitool cmd 0x3f 0x15 0xf8 0 0x20 0
E/AudioHardwareMSM72XX( 1965): FM CMD: hcitool cmd 0x3f 0x15 0xf8 0 0x32 0
E/AudioHardwareMSM72XX( 1965): FM CMD: hcitool cmd 0x3f 0x15 0xf8 0 0x41 0
E/AudioHardwareMSM72XX( 1965): FM CMD: hcitool cmd 0x3f 0x15 0xf8 0 0x52 0
...
E/ActivityManager( 2081): Load: 12.92 / 11.69 / 13.74
E/ActivityManager( 2081): CPU usage from 11525ms to 0ms ago:
E/ActivityManager( 2081):   49% 8348/com.monkeycoder.monkeygame: 45% user + 3.7% kernel / faults: 10490 minor



Playing multiple sounds at once is working (with other apps, and with strict playing on two different channels using monkeys PlaySound() ).

bye
Ron


therevills(Posted 2015) [#2]
It is a limitation of the Android system.

The docs for ChannelState does state this:
Note: This function currently returns -1 on the android target.


http://www.monkey-x.com/docs/html/Modules_mojo.audio.html#ChannelState

Within Diddy there is a simple channel pool system, which is "okay" - I havent had any issues using it. It is best to limit multiple sounds playing at the same time.


Derron(Posted 2015) [#3]
I saw your channel pool system. If I correctly remember the nly difference to mine was that yours has some kind of "lastChannel"-variable increasing on every "auto assigned" channel.
Do not take me wrong: diddy has many things I like - some of them do things different to how I would approach them - and I am often not sure whether mine is the better one :p

What made me wonder is: that the doc stats "returns -1 on the android target" (instead of "might return -1 on the android target") because it works on some android devices (correctly returns values on at least 2 china smartphones).
Edit2: I saw
	int ChannelState( int channel ){
		return -1;
	}

In mojo.android.java ... so I guess these chinese smartphones do something odd regarding sounds.

Always thought Monkey is already doing the "LCD"-approach, but this should mean, that "channelState" should be no available command as it does not work on all official targets.


Ok... have to investigate if there is a property for the duration of a sound file - or if I need to provide that information via an external tool (a simple bmx-tool spitting out play lengths to an xml/simple txt or so). Seems with a proper play length I could add a to my already existing TMusic/TSfxFile-Wrappers. My TSoundManager-singleton could then have a timer-var for every channel and rely on this when checking channelState.
Edit: just similar to how others did it before ...



bye
Ron