Question

I am working on a timer application for Windows Phone, and I am trying to make it so that if the remaining time on the timer is zero, a sound from a BackgroundAudioPlayer will play, regardless of whether or not the application is active, inactive, or under lock.

Currently, my issue is that the tick events don't actually do anything while the application isn't active. As soon as the user goes back into the application, the tick events run to the point that they would've otherwise, but the sound effect (or anything else) wont actually play unless the application is active, or switches to being active.

I do have in my Page.xaml.cs:

PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;

The relevant code is:

    void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        var remaining = this.EndTime - DateTime.Now;
        int remainingSeconds = (int)remaining.TotalSeconds;
        this.timeSpan.Value = TimeSpan.FromSeconds(remainingSeconds);

        if (remaining.TotalSeconds <= 0)
        {
            this.dispatcherTimer.Stop();
            button1.Visibility = Visibility.Collapsed;
            button6.Visibility = Visibility.Visible;
            this.EndTime = DateTime.MinValue;
            this.timeSpan.Value = TimeSpan.FromSeconds(0);
            BackgroundAudioPlayer.Instance.Play();
        }
    }

What can I do to make the tick events run while the application is under the lockscreen, or other wise not active?

Was it helpful?

Solution

Windows Phone has strict limits on background working. May be you need permission to work under lockscreen?

http://developer.nokia.com/community/wiki/Run_Windows_Phone_application_under_lock_screen

But it only stays application active under lockscreen, but not when user press windows or closes your app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top