Here are the examples of the java api me.jfenn.alarmio.data.SoundData.play() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
8
Source : AlarmActivity.java
with Apache License 2.0
from fennifith
with Apache License 2.0
from fennifith
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);
alarmio = (Alarmio) getApplicationContext();
overlay = findViewById(R.id.overlay);
date = findViewById(R.id.date);
time = findViewById(R.id.time);
actionView = findViewById(R.id.slideView);
// Lock orientation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
textColorPrimaryInverseSubscription = Aesthetic.Companion.get().textColorPrimaryInverse().subscribe(integer -> overlay.setBackgroundColor(integer));
isDarkSubscription = Aesthetic.Companion.get().isDark().subscribe(aBoolean -> isDark = aBoolean);
actionView.setLeftIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_snooze, getTheme()));
actionView.setRightIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_close, getTheme()));
actionView.setListener(this);
isSlowWake = PreferenceData.SLOW_WAKE_UP.getValue(this);
slowWakeMillis = PreferenceData.SLOW_WAKE_UP_TIME.getValue(this);
isAlarm = getIntent().hasExtra(EXTRA_ALARM);
if (isAlarm) {
alarm = getIntent().getParcelableExtra(EXTRA_ALARM);
isVibrate = alarm.isVibrate;
if (alarm.hreplacedound())
sound = alarm.getSound();
} else if (getIntent().hasExtra(EXTRA_TIMER)) {
timer = getIntent().getParcelableExtra(EXTRA_TIMER);
isVibrate = timer.isVibrate;
if (timer.hreplacedound())
sound = timer.getSound();
} else
finish();
date.setText(FormatUtils.format(new Date(), FormatUtils.FORMAT_DATE + ", " + FormatUtils.getShortFormat(this)));
if (sound != null && !sound.isSetVolumeSupported()) {
// Use the backup method if it is not supported
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
originalVolume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
if (isSlowWake) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
minVolume = audioManager.getStreamMinVolume(AudioManager.STREAM_ALARM);
} else {
minVolume = 0;
}
volumeRange = originalVolume - minVolume;
currentVolume = minVolume;
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, minVolume, 0);
}
}
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
triggerMillis = System.currentTimeMillis();
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
long elapsedMillis = System.currentTimeMillis() - triggerMillis;
String text = FormatUtils.formatMillis(elapsedMillis);
time.setText(String.format("-%s", text.substring(0, text.length() - 3)));
if (isVibrate) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
vibrator.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
else
vibrator.vibrate(500);
}
if (sound != null && !sound.isPlaying(alarmio))
sound.play(alarmio);
if (alarm != null && isSlowWake) {
float slowWakeProgress = (float) elapsedMillis / slowWakeMillis;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = Math.max(0.01f, Math.min(1f, slowWakeProgress));
getWindow().setAttributes(params);
getWindow().addFlags(WindowManager.LayoutParams.FLAGS_CHANGED);
if (sound != null && sound.isSetVolumeSupported()) {
float newVolume = Math.min(1f, slowWakeProgress);
sound.setVolume(alarmio, newVolume);
} else if (currentVolume < originalVolume) {
// Backup volume setting behavior
int newVolume = minVolume + (int) Math.min(originalVolume, slowWakeProgress * volumeRange);
if (newVolume != currentVolume) {
audioManager.setStreamVolume(audioManager.STREAM_ALARM, newVolume, 0);
currentVolume = newVolume;
}
}
}
handler.postDelayed(this, 1000);
}
};
handler.post(runnable);
if (sound != null)
sound.play(alarmio);
SleepReminderService.refreshSleepTime(alarmio);
if (PreferenceData.RINGING_BACKGROUND_IMAGE.getValue(this))
ImageUtils.getBackgroundImage((ImageView) findViewById(R.id.background));
}