LucaMs Expert Licensed User Longtime User Jan 10, 2016 #1 In a project containing some AnimationSet (library AnimationPlus) I use a SoundPool object to play a sound. Installed on a device with Android 4.4.2 the sound is correctly played once, on a device with Android 4.0.4, twice. I have developed a sample project (pay no attention to the stupid animations ) - attached. Has this happened to other members? Thank you Attachments SoundPool Test.zip SoundPool Test.zip 21.7 KB · Views: 741 Last edited: Jan 10, 2016
In a project containing some AnimationSet (library AnimationPlus) I use a SoundPool object to play a sound. Installed on a device with Android 4.4.2 the sound is correctly played once, on a device with Android 4.0.4, twice. I have developed a sample project (pay no attention to the stupid animations ) - attached. Has this happened to other members? Thank you
Erel B4X founder Staff member Licensed User Longtime User Jan 10, 2016 #2 You should move SoundPool to Process_Globals. Why are you calling Play multiple times if you want it to play once? Upvote 0
You should move SoundPool to Process_Globals. Why are you calling Play multiple times if you want it to play once?
LucaMs Expert Licensed User Longtime User Jan 10, 2016 #3 The real intention was to play a sound for each animation; then, given that I obtained a single sound (and I don't know why, of course), I used a different sound file, for the whole group of animations. This seemed to work, but when I checked the graphics on a different device... that problem. Thank you, Erel Upvote 0
The real intention was to play a sound for each animation; then, given that I obtained a single sound (and I don't know why, of course), I used a different sound file, for the whole group of animations. This seemed to work, but when I checked the graphics on a different device... that problem. Thank you, Erel
LucaMs Expert Licensed User Longtime User Jan 10, 2016 #4 Small changes but again I get the sound played twice on Android 4.0.4. Has someone a device with the same operating system to test it? Thank you Attachments SoundPool Test 2.zip SoundPool Test 2.zip 18.2 KB · Views: 664 Upvote 0
Small changes but again I get the sound played twice on Android 4.0.4. Has someone a device with the same operating system to test it? Thank you
Erel B4X founder Staff member Licensed User Longtime User Jan 10, 2016 #5 I don't understand your code. Why are you calling Play multiple times if you want it to play once? Code: Copy For A = 0 To NumOfAnim - 1 AnimSets(A).Start(Images(A)) mSoundPool.Play(mMySoundLoadID, 1, 1, 1000, 1, 1) Next Upvote 0
I don't understand your code. Why are you calling Play multiple times if you want it to play once? Code: Copy For A = 0 To NumOfAnim - 1 AnimSets(A).Start(Images(A)) mSoundPool.Play(mMySoundLoadID, 1, 1, 1000, 1, 1) Next
LucaMs Expert Licensed User Longtime User Jan 10, 2016 #6 Erel said: I don't understand your code. Why are you calling Play multiple times if you want it to play once? Code: Copy For A = 0 To NumOfAnim - 1 AnimSets(A).Start(Images(A)) mSoundPool.Play(mMySoundLoadID, 1, 1, 1000, 1, 1) Next Click to expand... I tried to explain why in #3. The goal is to move N Views, each with its own sound. The code would then be that. During the tests, using that code but with the addition of other effects, it seemed that the tablet was playing only one sound; so I preferred to use a different sound file, a file that represented the "group" sound. Anyway, the last attachment produces a sound on the tablet for which 3 views seem to be in motion (even if they are 5 such as sounds called); same thing on my smartphone but the "triple sound" is played twice, one after the other. Thank you P.S. https://xenforo.com/community/resources/audio.3459/ Last edited: Jan 10, 2016 Upvote 0
Erel said: I don't understand your code. Why are you calling Play multiple times if you want it to play once? Code: Copy For A = 0 To NumOfAnim - 1 AnimSets(A).Start(Images(A)) mSoundPool.Play(mMySoundLoadID, 1, 1, 1000, 1, 1) Next Click to expand... I tried to explain why in #3. The goal is to move N Views, each with its own sound. The code would then be that. During the tests, using that code but with the addition of other effects, it seemed that the tablet was playing only one sound; so I preferred to use a different sound file, a file that represented the "group" sound. Anyway, the last attachment produces a sound on the tablet for which 3 views seem to be in motion (even if they are 5 such as sounds called); same thing on my smartphone but the "triple sound" is played twice, one after the other. Thank you P.S. https://xenforo.com/community/resources/audio.3459/
LucaMs Expert Licensed User Longtime User Jan 10, 2016 #7 Another flaw: if I close the app using the Back button and then I re-open it, no more sounds (app's sounds) on my phone (4.0.2), ok on tablet (4.4.2). Last edited: Jan 10, 2016 Upvote 0
Another flaw: if I close the app using the Back button and then I re-open it, no more sounds (app's sounds) on my phone (4.0.2), ok on tablet (4.4.2).
JordiCP Expert Licensed User Longtime User Jan 10, 2016 #8 Hi, I have tested your code and did the same thing when exit with the back button. Change some things and now for me it works. Try to change the initialization to Activity_Resume and free it in Activity_Pause Code: Copy Sub Activity_Resume 'If Not(mSoundPool.IsInitialized) Then mSoundPool.Initialize(5) 'As many as you want to be played at the same time mMySoundLoadID = mSoundPool.Load(File.DirAssets, "notify.ogg") 'End If End Sub Sub Activity_Pause (UserClosed As Boolean) mSoundPool.Unload(mMySoundLoadID) 'Without this line, does not work mSoundPool.Release End Sub About the repetition, I can't reproduce it. But if you do mSoundPool.initialize(1), you are saying that only one sound can be played at the same time. If in your routine you launch it 5 times (even if it is the same), perhaps depending on the OS, device speed or others, one of them is queued when the other has already started playing Also, regarding Soundpool, it has never been clear to me if the "Loops" parameter in SoundPool.Play(...) has to be 0 or 1 for no-repetition. If the above does not work perhaps the difference is here. Upvote 0
Hi, I have tested your code and did the same thing when exit with the back button. Change some things and now for me it works. Try to change the initialization to Activity_Resume and free it in Activity_Pause Code: Copy Sub Activity_Resume 'If Not(mSoundPool.IsInitialized) Then mSoundPool.Initialize(5) 'As many as you want to be played at the same time mMySoundLoadID = mSoundPool.Load(File.DirAssets, "notify.ogg") 'End If End Sub Sub Activity_Pause (UserClosed As Boolean) mSoundPool.Unload(mMySoundLoadID) 'Without this line, does not work mSoundPool.Release End Sub About the repetition, I can't reproduce it. But if you do mSoundPool.initialize(1), you are saying that only one sound can be played at the same time. If in your routine you launch it 5 times (even if it is the same), perhaps depending on the OS, device speed or others, one of them is queued when the other has already started playing Also, regarding Soundpool, it has never been clear to me if the "Loops" parameter in SoundPool.Play(...) has to be 0 or 1 for no-repetition. If the above does not work perhaps the difference is here.
LucaMs Expert Licensed User Longtime User Jan 10, 2016 #9 I have yet to try it but I wanted to thank you for your answer and advices, @JordiCP Upvote 0
LucaMs Expert Licensed User Longtime User Jan 10, 2016 #10 JordiCP said: I have tested your code Click to expand... AOS 4.0.4? Moving the initialization to the Resume event, sounds are played also when I "restart" the app (Back key and start again), as you suggested. Anyway I don't know why writing: Code: Copy Sub Activity_Create If FirstTime then mSoundPool.Initialize(1) End If End Sub Sub Activity_Resume log(mSoundPool.IsInitialized) End Sub this does not create problems on my tablet but on my phone; mSoundPool is initialized, also when the app is restarted, in both devices. The "sounds serie" is still repeated twice, unfortunately; is the problem my bad phone or AOS 4.0.4? JordiCP said: Also, regarding Soundpool, it has never been clear to me if the "Loops" parameter in SoundPool.Play(...) Click to expand... Loops stands for "repetitions", I think. If you set it to -1, the sound will be played continuously (endlessly - damn English ). [I'm thinking that when you want to develop you should pray, before ] Last edited: Jan 10, 2016 Upvote 0
JordiCP said: I have tested your code Click to expand... AOS 4.0.4? Moving the initialization to the Resume event, sounds are played also when I "restart" the app (Back key and start again), as you suggested. Anyway I don't know why writing: Code: Copy Sub Activity_Create If FirstTime then mSoundPool.Initialize(1) End If End Sub Sub Activity_Resume log(mSoundPool.IsInitialized) End Sub this does not create problems on my tablet but on my phone; mSoundPool is initialized, also when the app is restarted, in both devices. The "sounds serie" is still repeated twice, unfortunately; is the problem my bad phone or AOS 4.0.4? JordiCP said: Also, regarding Soundpool, it has never been clear to me if the "Loops" parameter in SoundPool.Play(...) Click to expand... Loops stands for "repetitions", I think. If you set it to -1, the sound will be played continuously (endlessly - damn English ). [I'm thinking that when you want to develop you should pray, before ]
LucaMs Expert Licensed User Longtime User Jan 11, 2016 #11 Testing again. The problem was exactly that parameter, Loop; it means, I suppose now, the number of repetitions AFTER the first playing. Then, set to zero, it plays once, 1 = twice, and so on. In my project I set it to 1 and this is why on my smartphone I get two series of sounds; but the "error" is on my tablet, then, which plays one series only! In addition, the initialization does not convince me. Upvote 0
Testing again. The problem was exactly that parameter, Loop; it means, I suppose now, the number of repetitions AFTER the first playing. Then, set to zero, it plays once, 1 = twice, and so on. In my project I set it to 1 and this is why on my smartphone I get two series of sounds; but the "error" is on my tablet, then, which plays one series only! In addition, the initialization does not convince me.
Erel B4X founder Staff member Licensed User Longtime User Jan 11, 2016 #12 The animations are asynchronous. You need to handle the animation complete event if you want to do something after an animation completed. Upvote 0
The animations are asynchronous. You need to handle the animation complete event if you want to do something after an animation completed.
LucaMs Expert Licensed User Longtime User Jan 11, 2016 #13 Erel said: The animations are asynchronous. You need to handle the animation complete event if you want to do something after an animation completed. Click to expand... Thank you, Erel, but I don't think could be this the problem, different behavior in the two devices. As I wrote, the goal is to move N Views, each with its own sound... asynchronously: View1 (animation) starts with its sound; after few milliseconds... View2 (animation) starts with its sound. Each sound should play during its related animation (translation). To be clear, I'm trying to draw and move coins on a table. The second question (that I discovered during these tests) is the absence of sound if I initialize the SoundPool object in Acitivity_Start, depending on the state of FirstTime; the object is always properly initialized but the sounds are not played even if I don't get errors ("Please, start a new thread for this question"? ). Upvote 0
Erel said: The animations are asynchronous. You need to handle the animation complete event if you want to do something after an animation completed. Click to expand... Thank you, Erel, but I don't think could be this the problem, different behavior in the two devices. As I wrote, the goal is to move N Views, each with its own sound... asynchronously: View1 (animation) starts with its sound; after few milliseconds... View2 (animation) starts with its sound. Each sound should play during its related animation (translation). To be clear, I'm trying to draw and move coins on a table. The second question (that I discovered during these tests) is the absence of sound if I initialize the SoundPool object in Acitivity_Start, depending on the state of FirstTime; the object is always properly initialized but the sounds are not played even if I don't get errors ("Please, start a new thread for this question"? ).
Erel B4X founder Staff member Licensed User Longtime User Jan 11, 2016 #14 LucaMs said: View1 (animation) starts with its sound; after few milliseconds... View2 (animation) starts with its sound. Click to expand... This is not what you've implemented. You are starting all the animations at once. You have also initialized SoundPool with MaxStreams set to 1 so it will only play a single sound at once. About the absence of sound. Have you declared SoundPool as a process global variable? Upvote 0
LucaMs said: View1 (animation) starts with its sound; after few milliseconds... View2 (animation) starts with its sound. Click to expand... This is not what you've implemented. You are starting all the animations at once. You have also initialized SoundPool with MaxStreams set to 1 so it will only play a single sound at once. About the absence of sound. Have you declared SoundPool as a process global variable?
LucaMs Expert Licensed User Longtime User Jan 11, 2016 #15 Erel said: This is not what you've implemented. You are starting all the animations at once. Click to expand... They are executed sequentially, although the time offset can be very small (maybe microseconds). I used also the StartOffset property of AnimationSet. Erel said: You have also initialized SoundPool with MaxStreams set to 1 so it will only play a single sound at once. Click to expand... I know, I tried with the number of views and then I set it to 1 because I had intended to use a single sound file for the whole group of coins, because I get unwanted havior. Erel said: About the absence of sound. Have you declared SoundPool as a process global variable? Click to expand... Yes, and I initialized it: Code: Copy Sub Activity_Create(FirstTime As Boolean) If FirstTime Then mSoundPool.Initialize(5) End If End Sub Upvote 0
Erel said: This is not what you've implemented. You are starting all the animations at once. Click to expand... They are executed sequentially, although the time offset can be very small (maybe microseconds). I used also the StartOffset property of AnimationSet. Erel said: You have also initialized SoundPool with MaxStreams set to 1 so it will only play a single sound at once. Click to expand... I know, I tried with the number of views and then I set it to 1 because I had intended to use a single sound file for the whole group of coins, because I get unwanted havior. Erel said: About the absence of sound. Have you declared SoundPool as a process global variable? Click to expand... Yes, and I initialized it: Code: Copy Sub Activity_Create(FirstTime As Boolean) If FirstTime Then mSoundPool.Initialize(5) End If End Sub
Erel B4X founder Staff member Licensed User Longtime User Jan 11, 2016 #16 I can't help you with the animations. It works as expected. About the sound, if you like upload the updated project and I'll check it. Upvote 0
I can't help you with the animations. It works as expected. About the sound, if you like upload the updated project and I'll check it.
LucaMs Expert Licensed User Longtime User Jan 11, 2016 #17 Erel said: About the sound, if you like upload the updated project and I'll check it. Click to expand... Many thanks; I prefer become a little more crazy, before, because you're already overworked. Upvote 0
Erel said: About the sound, if you like upload the updated project and I'll check it. Click to expand... Many thanks; I prefer become a little more crazy, before, because you're already overworked.
Erel B4X founder Staff member Licensed User Longtime User Jan 11, 2016 #18 LucaMs said: because you're already overworked Click to expand... Not at all. Upvote 0
LucaMs Expert Licensed User Longtime User Jan 11, 2016 #19 Erel said: Not at all. Click to expand... Well, I take this opportunity . I'll attach one of my tests here, it is in fact only a test. But I have to change a small portion, first; trade secret Thank you Upvote 0
Erel said: Not at all. Click to expand... Well, I take this opportunity . I'll attach one of my tests here, it is in fact only a test. But I have to change a small portion, first; trade secret Thank you
LucaMs Expert Licensed User Longtime User Jan 11, 2016 #20 Discovered the problem of no sounds: I must declare also the LoadID in the process globals! Wake up, "Luca". Well, now there is only one (little) problem: the "coin sounds" should be started with a time offset (otherwise it seems to be a unique sound with higher sound volume). I'm thinking to use a timer: what about this? (to test, touch the screen) [please, pay no attention to the confusion in the project ] Attachments MoneyAnim.zip MoneyAnim.zip 123.7 KB · Views: 673 Upvote 0
Discovered the problem of no sounds: I must declare also the LoadID in the process globals! Wake up, "Luca". Well, now there is only one (little) problem: the "coin sounds" should be started with a time offset (otherwise it seems to be a unique sound with higher sound volume). I'm thinking to use a timer: what about this? (to test, touch the screen) [please, pay no attention to the confusion in the project ]