Android Question Beeper stop working

Discussion in 'Android Questions' started by FERNANDO SILVEIRA, Apr 7, 2018.

  1. FERNANDO SILVEIRA

    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


    Code:
    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(
    300500 + (t * 100))
        wBeeper1.Beep
    End Sub
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use File - Export as zip when uploading projects.

    Code:
    Sub PlayTune(Tune As Int)
        wCtPlayed = wCtPlayed + 
    1
        
    Dim t As Int = Tune
        
    Log(wCtPlayed & ") Reproduzindo tom " & t)
        wBeeper1.Initialize(
    300500 + (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 likes this.
  3. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Ok.
    I don't know How to use a map.
    Can you be more specific?

    Regards.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    See the Collections and Collections Example tutorials: https://www.b4x.com/etp.html
     
  5. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User


    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
     
  6. udg

    udg Expert Licensed User

    Hi Fernando,
    I guess that Erel intented to suggest you to think along the following lines (pseudo-code):
    Code:
    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(
    300500 + (Tune * 100))
      
    return aBeeper
    end sub

    Sub PlayTune( aTune as string)
      
    dim aBeeper = MyTunes.get(aTune)
      aBeeper.Beep
      Sleep(
    300 + 10)
    Return
    udg
     
    FERNANDO SILVEIRA likes this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    Note that I made two suggestions:
    1. Use Sleep and then release the object. It will solve the issue.

    2. Create a map with the various beeper objects and reuse them. In that case the sleep is not required.
     
    FERNANDO SILVEIRA likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice