Back to project page caddisfly-app-camera.
The source code is released under:
GNU General Public License
If you think the Android project caddisfly-app-camera listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) TernUp Research Labs/* ww w . j a v a 2 s . co m*/ * * This file is part of Caddisfly * * Caddisfly is free software: you can redistribute it and modify it under the terms of * the GNU Affero General Public License (AGPL) as published by the Free Software Foundation, * either version 3 of the License or any later version. * * Caddisfly is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License included below for more details. * * The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>. */ package com.ternup.caddisfly.util; import android.content.Context; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.RingtoneManager; import android.net.Uri; import java.io.IOException; public class AudioUtils { private AudioUtils() { } /** * Play an alarm sound on the device * * @param context The context * @return MediaPlayer */ public static MediaPlayer playAlarmSound(Context context) { MediaPlayer mediaPlayer = new MediaPlayer(); try { mediaPlayer.setDataSource(context, getAlarmUri()); final AudioManager audioManager = (AudioManager) context .getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.prepare(); mediaPlayer.start(); } return mediaPlayer; } catch (IOException e) { return null; } } /** * Get an alarm sound. Try for an alarm. If none set, try notification, otherwise, ringtone. * * @return Alarm media uri */ private static Uri getAlarmUri() { Uri alarm = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_ALARM); if (alarm == null) { alarm = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alarm == null) { alarm = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_RINGTONE); } } return alarm; } }