1. Download the free trial version

Play sound with phone off

Discussion in 'Questions' started by DB100, Jul 24, 2013.

  1. DB100

    DB100 New Member Licensed User

    I have a count-down timer app that uses a Service module. It generates a sound when it reaches zero. If I start it at 1 min and then turn-off the phone, the sound won't play. After the timer is over, when I turn the phone back on, the sound plays. It's as if the sound is in some sort of queue, and can't play til the phone is turned on. I have experimented with different methods for generating the sound:

    MediaPlayer
    Notification.sound
    Beep

    They all work the same. They won't play when the phone is off, but do play when the phone is turned back on. I have downloaded count-down timers from Google Play and they do play a sound when the phone is off. So it's not the phone and it's not Android. It must be B4A. Is there a way in B4A to play a sound when the phone is off? Thanks.
  2. NJDude

    NJDude Expert Licensed User

    You have to keep your service "alive", read THIS or search the forums for Services Tutorial
  3. DB100

    DB100 New Member Licensed User

    I tried this. It's a sub within the service.
    It didn't work. It acted the same as I described above:

    Sub PlaySound
    'Use Notification to play sound.
    'DateTime.TimeFormat = "hh:mm:ss"
    'File.WriteString(gsFilePath,"MyTimerX.txt",DateTime.Time(DateTime.Now))
    goNotify.Icon = ""
    goNotify.Light = False
    goNotify.Vibrate = False
    goNotify.Sound = True
    Service.StartForeground(2,goNotify)
    'goNotify.Notify(2)
    End Sub
  4. Erel

    Erel Administrator Staff Member Licensed User

    Try to acquire a partial lock with PhoneWakeState.
  5. DB100

    DB100 New Member Licensed User

    Bingo! PhoneWakeState seems to have it working.

    Thanks.

Share This Page

Loading...