tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.76k stars 1.21k forks source link

Android: Sound volume property not working if set at creation time #14108

Closed Informate closed 1 month ago

Informate commented 2 months ago

I have searched and made sure there are no existing issues for the issue I am filing

Description

The sound volume property not working if set at creation time on Android

const sound=Titanium.Media.createSound({ url, volume});

FIXING WORKAROUND:

Set it separately:

sound.volume=volume;

Expected Behavior

Set the sound volume

Actual behavior

Play as 1 or as 0

Reproducible sample

X

Steps to reproduce

X

Platform

Android

SDK version you are using

12.4.0.GA

Alloy version you are using

No response

m1ga commented 2 months ago

working fine here

var win = Ti.UI.createWindow();
var tf = Ti.UI.createTextField({value: "0.5"})

win.addEventListener("click", function() {
    var player = Ti.Media.createSound({
        url: "/boing.mp3",
        volume: tf.value
    });
    player.play();

})
win.add(tf);
win.open();

i can change the volume in the textfield and click in the window to play the sound. The volume is changing.

Tested with Ti 12.4.0.GA

m1ga commented 2 months ago

@Informate did you test the code and verify if it is working for you too?

Informate commented 2 months ago

I will do it as soon as I'll can. Anyway I found the volume problem inside a service. I'll make a deeper test but it will take some time.

Informate commented 1 month ago

@m1ga I have done the test also on an unbounded service. Now all is working correctly! I don't know what was not working for me in the other case, but I experienced some problem with this feature. You can mark this as not a bug! Happy for you, not so much for me :(

Informate commented 1 month ago

@m1ga I suppose the issue with the volume control is really present on the background service, but do not happen every time, it also happen more often especially on some device as a low-quality device (GoodTel - vendor ID 1f3a). The background service today also played twice in parralel doubling the sounds ( How it works behind the lines is not fully clear to me or explained in the guide - my setInterval run the on the main app thread instead of in a separate context).

m1ga commented 1 month ago

maybe it depends on the Android SDK version?

Background service: don't know, sorry. Not using those. Maybe you can either clear or check if it is already running using a Ti.App.property or a boolean value? Also make sure not to use Liveview while testing those parts as it might just be an issue there.