use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class VolumeControlAction method shouldUpdateAudioVolume.
private boolean shouldUpdateAudioVolume(boolean mute) {
// Do nothing if in mute.
if (mute) {
return true;
}
// Update audio status if current volume position is edge of volume bar,
// i.e max or min volume.
AudioManager audioManager = tv().getService().getAudioManager();
int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
if (mIsVolumeUp) {
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
return currentVolume == maxVolume;
} else {
return currentVolume == 0;
}
}
use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class PhoneWindowManager method performAuditoryFeedbackForAccessibilityIfNeed.
private void performAuditoryFeedbackForAccessibilityIfNeed() {
if (!isGlobalAccessibilityGestureEnabled()) {
return;
}
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.isSilentMode()) {
return;
}
Ringtone ringTone = RingtoneManager.getRingtone(mContext, Settings.System.DEFAULT_NOTIFICATION_URI);
ringTone.setStreamType(AudioManager.STREAM_MUSIC);
ringTone.play();
}
use of android.media.AudioManager in project wechat by motianhuo.
the class VoicePlayClickListener method playVoice.
public void playVoice(String filePath) {
if (!(new File(filePath).exists())) {
return;
}
((ChatActivity) activity).playMsgId = message.getMsgId();
AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
mediaPlayer = new MediaPlayer();
if (EMChatManager.getInstance().getChatOptions().getUseSpeaker()) {
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(true);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
} else {
// 关闭扬声器
audioManager.setSpeakerphoneOn(false);
// 把声音设定成Earpiece(听筒)出来,设定为正在通话中
audioManager.setMode(AudioManager.MODE_IN_CALL);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
}
try {
mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mediaPlayer.release();
mediaPlayer = null;
// stop animation
stopPlayVoice();
}
});
isPlaying = true;
currentPlayListener = this;
mediaPlayer.start();
showAnimation();
// 如果是接收的消息
if (message.direct == EMMessage.Direct.RECEIVE) {
try {
if (!message.isAcked) {
message.isAcked = true;
// 告知对方已读这条消息
if (chatType != ChatType.GroupChat)
EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
}
} catch (Exception e) {
message.isAcked = false;
}
if (!message.isListened() && iv_read_status != null && iv_read_status.getVisibility() == View.VISIBLE) {
// 隐藏自己未播放这条语音消息的标志
iv_read_status.setVisibility(View.INVISIBLE);
EMChatManager.getInstance().setMessageListened(message);
}
}
} catch (Exception e) {
}
}
use of android.media.AudioManager in project wechat by motianhuo.
the class CaptureActivity method onResume.
@Override
protected void onResume() {
super.onResume();
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
if (hasSurface) {
initCamera(surfaceHolder);
} else {
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
decodeFormats = null;
characterSet = null;
playBeep = true;
AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
playBeep = false;
}
initBeepSound();
vibrate = true;
}
use of android.media.AudioManager in project android-app-common-tasks by multidots.
the class Common method setCurrentDeviceVolume.
/*public static <T> void callFacebookLogin(Activity mContext, String appID) {
// Intent mIntent = new Intent(mContext, className);
// mIntent.putExtra("app_id", appID);
// mContext.startActivity(mIntent);
facebook = new Facebook(appID);
mAsyncRunner = new AsyncFacebookRunner(facebook);
restoreCredentials(facebook, mContext);
if (!facebook.isSessionValid()) {
System.out.println("In if");
LoginWithFaceBook(mContext);
} else {
System.out.println("In if else ");
Editor editor = mContext.getSharedPreferences(APP_FB_PREFS,
Context.MODE_PRIVATE).edit();
editor.clear();
editor.commit();
}
}
public static void LoginWithFaceBook(Activity mContext) {
// TODO Auto-generated method stub
facebook.authorize(mContext, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
new LoginDialogListener());
}
public static boolean restoreCredentials(Facebook facebook, Context mContext) {
SharedPreferences sharedPreferences = mContext.getSharedPreferences(
APP_FB_PREFS, Context.MODE_PRIVATE);
facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}
public static boolean saveCredentials(Context mContext) {
Editor editor = mContext.getSharedPreferences(APP_FB_PREFS,
Context.MODE_PRIVATE).edit();
System.out.println("111 data fb:" + facebook.getAccessToken() + ":"
+ facebook.getAccessExpires());
editor.putString(TOKEN, facebook.getAccessToken());
editor.putLong(EXPIRES, facebook.getAccessExpires());
return editor.commit();
}
public static void getProfileInformation() {
mAsyncRunner.request("me", new RequestListener() {
public void onComplete(String response, Object state) {
Log.d("Profile", response);
System.out.println("FaceBook ni profile no response -->>"
+ response);
String json = response;
try {
JSONObject profile = new JSONObject(json);
// getting name of the user
final String name = profile.getString("name");
// getting email of the user
final String first_name = profile.getString("first_name");
final String last_name = profile.getString("last_name");
final String email = profile.getString("email");
Editor editor = preferences.edit();
editor.putString(Common.LOGIN_FIRST_NAME, first_name);
editor.putString(Common.LOGIN_LAST_NAME, last_name);
editor.putString(Common.LOGIN_EMAIL, email);
editor.commit();
System.out.println("name" + name + "email" + email
+ first_name + last_name);
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// // Likes();
// // Intent iii = new Intent(ctx, Logout.class);
// // startActivity(iii);
// // What u want to do after response come do here....
// }
// });
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onIOException(IOException e, Object state) {
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
@Override
public void onFacebookError(FacebookError e, Object state) {
}
});
}*/
/**
* Use current volume in application
*
* @param mContext
*/
public static void setCurrentDeviceVolume(Context mContext) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, 0);
}
Aggregations