We just started using AsyncPlayer player with one of our applications
to play an "alarm" sound at a specified time. When the alarm sounds,
we show the user a Stop and a Snooze button that respectively stops
and resets the alarm. tho we can't reproduce it, we've had a user
complain that when the alarm goes off, the alarm sound plays but
cannot be stopped by pushing Stop or Snooze, that the app had to be
terminated (as opposed to paused or finalized).

I actually saw similar behavior early on in testing (weeks ago) and
had assumed I had inadvertently coded my way out of it. Basically,
AsyncPlayer starts but won't stop unless I use a process killer like
TaskKill. That is, none of my calls to AsyncPlayer.stop() appear to be
honored.

Has anyone seen this or have an idea what I mite be doing wrong???
TIA//

here's a paraphrasing of the code from our main activity class:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private long mNextAlarmOn;
private boolean mAlarmIsPlaying = false;
private AsyncPlayer mAlarmSoundPlayer;
private Handler mHandler = new Handler();

private void startClock(){
        this.mNextAlarmOn = this.calculateNextAlarmTime();
        long currentTime = System.currentTimeMillis();
        Date currentDate = new Date(currentTime);
        this.mHandler.postDelayed(
                                this.mUpdateClockViewsRunnable,
                                1000 * (60 - currentDate.getSeconds())
                                );
};

private Runnable mUpdateClockViewsRunnable = new Runnable(){
        @Override
        public void run() {
                MainActivity.this.checkAlarm();
                MainActivity.this.mHandler.postDelayed
(MainActivity.this.mUpdateClockViewsRunnable, 1000 * 60);
        }
};

private void checkAlarm(){
        if(!this.mAlarmIsPlaying && this.mNextAlarmOn != 0 &&
this.mNextAlarmOn <= System.currentTimeMillis())
                this.raiseAlarm();
};

private void raiseAlarm(){
        this.mAlarmIsPlaying = true;
        if(this.mAlarmSoundPlayer != null){
                this.mAlarmSoundPlayer.stop();
                this.mAlarmSoundPlayer = null;
        }
        AudioManager audioManager = (AudioManager)this.getSystemService
(Context.AUDIO_SERVICE);
        audioManager.setStreamVolume(
                        AudioManager.STREAM_ALARM,
                        
audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM),
                        0
                        );
        this.mAlarmSoundPlayer = new AsyncPlayer("OurAlarmSound");
        this.mAlarmSoundPlayer.play(
                        this,
                        Uri.parse(this.getAlarmRingtoneUri()),
                        true,
                        AudioManager.STREAM_ALARM
                        );
};

private void stopAlarm(){
        this.releaseAlarm();
};


@Override
public void onPause(){
        super.onPause();
        this.releaseAlarm();
};


@Override
public void finish(){
        super.finish();
        this.releaseAlarm();
};

private void releaseAlarm(){
        if(this.mAlarmSoundPlayer != null){
                this.mAlarmSoundPlayer.stop();
                this.mAlarmSoundPlayer = null;
        }
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to