I’m very new to beacon programming. I’ve created a virtual beacon with Beacon Toy and, using Estimote’s sample code, I’m trying to create an app that plays music when the user enters the beacon’s region, and stops playing when the user exits the region. The “start” part works fine but the “stop” part doesn’t work until about 30 seconds after the start part, even if the user exits the region long before the 30 second interval is finished. Here’s my code:
beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
MediaPlayer mediaPlayer;
@Override
public void onEnteredRegion(Region region, List list) {
showNotification(
"Your gate closes in 47 minutes.",
"Current security wait time is 15 minutes, "
+ "and it's a 5 minute walk from security to the gate. "
+ "Looks like you've got plenty of time!");
mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.starsandstripes);
// new MyAsyncTask()
// .execute(mediaPlayer);
mediaPlayer.start();
}
@Override
public void onExitedRegion(Region region) {
Log.i("EXITED", "EXITED"); // Not possible to fire until 30 seconds after onEnteredRegion???
showNotification("Exited", "Exited");
mediaPlayer.stop();
// could add an "exit" notification too if you want (-:
}
});