Android Question Beeper stop working

FERNANDO SILVEIRA

Active Member
Licensed User
Hi guys,

I saw many different thereads on this issue hete. Some of them are very aged now. https://www.b4x.com/android/forum/threads/beeper-bug.14077/

I tried a few of them with no visible effect. After a few times beeper working, it just stops playing sounds. See what I already did:
  1. Used two different beepers
  2. Released it after a few executions
  3. Released it after every execution
  4. Created them at Sub Process_Globals level
The app seems to be working fairly now, only sound portion is unreliable.

Any clues?
Regards,
Fernando


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private wBeeper1, wBeeper2 As Beeper
End Sub

Sub PlayTune(Tune As Int)
    wCtPlayed = wCtPlayed + 1
    Dim t As Int = Tune
    Log(wCtPlayed & ") Reproduzindo tom " & t)
    wBeeper1.Initialize(300, 500 + (t * 100))
    wBeeper1.Beep
End Sub
 

Attachments

Erel

Administrator
Staff member
Licensed User
Please use File - Export as zip when uploading projects.

B4X:
Sub PlayTune(Tune As Int)
    wCtPlayed = wCtPlayed + 1
    Dim t As Int = Tune
    Log(wCtPlayed & ") Reproduzindo tom " & t)
    wBeeper1.Initialize(300, 500 + (t * 100))
    wBeeper1.Beep
    Sleep(300 + 10)
    wBeeper.Release
End Sub
If you are only calling this sub with a few discreet values then you can store them in a Map and avoid creating a new beeper object each time.
 

FERNANDO SILVEIRA

Active Member
Licensed User
Please use File - Export as zip when uploading projects.

B4X:
Sub PlayTune(Tune As Int)
    wCtPlayed = wCtPlayed + 1
    Dim t As Int = Tune
    Log(wCtPlayed & ") Reproduzindo tom " & t)
    wBeeper1.Initialize(300, 500 + (t * 100))
    wBeeper1.Beep
    Sleep(300 + 10)
    wBeeper.Release
End Sub
If you are only calling this sub with a few discreet values then you can store them in a Map and avoid creating a new beeper object each time.

Ok, I watched Collections and Collections Example tutorials but I still don't know how use Map in order to fix my issue.
  1. Can you provide a small example?
  2. And, how is it possible to play a beep without initialize it? (code, please)

Regards,
Fernando
 

udg

Expert
Licensed User
store them in a Map and avoid creating a new beeper object each time.
Hi Fernando,
I guess that Erel intented to suggest you to think along the following lines (pseudo-code):
B4X:
Dim MyTunes as map
Mytunes.Initialize
dim aBeeper as Beeper = CreateBeeper(Tune1)  '<-- Tune1 is just a number you could hardcode here, but using an array defined at the top is better IMHO
MyTune.Put("Beep1", aBeeper)  '<-- use descriptive names instead of Beep1,Beep2..
dim aBeeper as Beeper = CreateBeeper(Tune2)
MyTune.Put("Beep2", aBeeper)  '<-- instead of descriptive names you could use the Tune as the key, if you like so
...

 'when it's time to play you call PlayTune("Beep1")

'on program exit release all the Beepers (maybe not strictly necessary but a clean up habit is better IMHO)

Sub CreateBeeper(Tune) as Beeper
  dim a Beepr as beeper
  aBeeper.Initialize(300, 500 + (Tune * 100))
  return aBeeper
end sub

Sub PlayTune( aTune as string)
  dim aBeeper = MyTunes.get(aTune)
  aBeeper.Beep
  Sleep(300 + 10)
Return
udg
 
Top