警报对话框:播放mp3直到显示

时间:2016-10-10 05:04:43

标签: android

我使用以下代码向用户显示通知:

                            AlertDialog.Builder alert = new AlertDialog.Builder(track.this);
                            alert.setTitle("Bus arriving !");
                            alert.setMessage("Bus has reached into your tracking area");
                            alert.setPositiveButton("OK",null);
                            alert.show();

我有以下代码向用户播放通知提醒:

void PlayAlertfNeeded()
{
    try {
        if (player.isPlaying()) {
            player.stop();
            player.release();
            player = new MediaPlayer();
        }

        ToneGenerator toneGen1 = new ToneGenerator(AudioManager.STREAM_ALARM, 100);
        toneGen1.startTone(ToneGenerator.TONE_CDMA_ABBR_ALERT,500);
        toneGen1.startTone(ToneGenerator.TONE_CDMA_ABBR_ALERT,2000);


        AssetFileDescriptor descriptor = getAssets().openFd("canttrackthebus.mp3");
        player.reset();
        player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
        descriptor.close();

        player.prepare();
        player.setVolume(1f, 1f);
        player.setLooping(false);
        player.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

我需要显示警告对话框并保持mp3循环直到用户按下OK按钮。

没有onCreate可用于警报,那么如何实现呢?

1 个答案:

答案 0 :(得分:0)

 class SequenceTable(models.Model):
        id = models.AutoField( primary_key=True )
        route_id = models.ForeignKey( route, on_delete=models.CASCADE)
        station_id = models.ForeignKey(Stations, on_delete=models.CASCADE)
        sequence_no = models.IntegerField( null=True )

        #def __str__(self):
        #   return self.sequence_no
class Stations(models.Model):
    station_id = models.AutoField( primary_key=True )
    station = models.CharField( max_length=20 )
    station_code = models.CharField( max_length=10 )
  def __str__(self):
        return self.station_code