Java Code Examples for android.media.AudioManager

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android_packages_apps_phone, under directory /src/com/android/phone/.

Source file: NotificationMgr.java

  35 
vote

/** 
 * Calls either notifySpeakerphone() or cancelSpeakerphone() based on the actual current state of the speaker.
 */
void updateSpeakerNotification(){
  AudioManager audioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  if ((mPhone.getState() == Phone.State.OFFHOOK) && audioManager.isSpeakerphoneOn()) {
    if (DBG)     log("updateSpeakerNotification: speaker ON");
    notifySpeakerphone();
  }
 else {
    if (DBG)     log("updateSpeakerNotification: speaker OFF (or not offhook)");
    cancelSpeakerphone();
  }
}
 

Example 2

From project AlarmApp-Android, under directory /src/org/alarmapp/services/.

Source file: AudioPlayerService.java

  33 
vote

private void startAlarm(MediaPlayer player) throws java.io.IOException, IllegalArgumentException, IllegalStateException {
  final AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
    player.setAudioStreamType(AudioManager.STREAM_ALARM);
    player.setLooping(true);
    player.prepare();
    player.start();
  }
}
 

Example 3

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: BeepManager.java

  33 
vote

private static boolean shouldBeep(SharedPreferences prefs,Context activity){
  boolean shouldPlayBeep=prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP,CaptureActivity.DEFAULT_TOGGLE_BEEP);
  if (shouldPlayBeep) {
    AudioManager audioService=(AudioManager)activity.getSystemService(Context.AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
      shouldPlayBeep=false;
    }
  }
  return shouldPlayBeep;
}
 

Example 4

From project android-thaiime, under directory /latinime/src/com/android/inputmethod/accessibility/.

Source file: AccessibilityUtils.java

  33 
vote

private void initInternal(Context context,SharedPreferences prefs){
  mContext=context;
  mAccessibilityManager=(AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
  mCompatManager=new AccessibilityManagerCompatWrapper(mAccessibilityManager);
  final AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  mAudioManager=new AudioManagerCompatWrapper(audioManager);
}
 

Example 5

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.

Source file: RingerVolumePreference.java

  33 
vote

public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
  setNotificationVolumeVisibility(!isChecked);
  Settings.System.putInt(getContext().getContentResolver(),Settings.System.NOTIFICATIONS_USE_RING_VOLUME,isChecked ? 1 : 0);
  if (isChecked) {
    AudioManager audioManager=(AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,audioManager.getStreamVolume(AudioManager.STREAM_RING),0);
  }
}
 

Example 6

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/accessibility/.

Source file: AccessibilityUtils.java

  33 
vote

private void initInternal(Context context,SharedPreferences prefs){
  mContext=context;
  mAccessibilityManager=(AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
  mCompatManager=new AccessibilityManagerCompatWrapper(mAccessibilityManager);
  final AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  mAudioManager=new AudioManagerCompatWrapper(audioManager);
}
 

Example 7

From project CoinFlip, under directory /src/com/banasiak/coinflip/.

Source file: CoinFlip.java

  33 
vote

private void playSound(final int sound){
  Log.d(TAG,"playSound()");
  if (Settings.getSoundPref(this)) {
    final AudioManager mgr=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
    final float streamVolumeCurrent=mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
    final float streamVolumeMax=mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    final float volume=streamVolumeCurrent / streamVolumeMax;
    soundPool.play(sound,volume,volume,1,0,1f);
  }
}
 

Example 8

From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.

Source file: AudioHandler.java

  33 
vote

/** 
 * Set the audio device to be used for playback.
 * @param output			1=earpiece, 2=speaker
 */
@SuppressWarnings("deprecation") public void setAudioOutputDevice(int output){
  AudioManager audiMgr=(AudioManager)this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
  if (output == 2) {
    audiMgr.setRouting(AudioManager.MODE_NORMAL,AudioManager.ROUTE_SPEAKER,AudioManager.ROUTE_ALL);
  }
 else   if (output == 1) {
    audiMgr.setRouting(AudioManager.MODE_NORMAL,AudioManager.ROUTE_EARPIECE,AudioManager.ROUTE_ALL);
  }
 else {
    System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
  }
}
 

Example 9

From project cornerstone, under directory /frameworks/base/policy/src/com/android/internal/policy/impl/.

Source file: PhoneWindowManager.java

  32 
vote

/** 
 * @return Whether music is being played right now.
 */
boolean isMusicActive(){
  final AudioManager am=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  if (am == null) {
    Log.w(TAG,"isMusicActive: couldn't get AudioManager reference");
    return false;
  }
  return am.isMusicActive();
}
 

Example 10

From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/alarmclock/.

Source file: AlarmKlaxon.java

  32 
vote

private void startAlarm(final MediaPlayer player) throws java.io.IOException, IllegalArgumentException, IllegalStateException {
  final AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
    player.setAudioStreamType(AudioManager.STREAM_ALARM);
    player.setLooping(true);
    player.prepare();
    player.start();
  }
}
 

Example 11

From project framework_base_policy, under directory /src/com/android/internal/policy/impl/.

Source file: PhoneWindowManager.java

  32 
vote

/** 
 * @return Whether music is being played right now.
 */
boolean isMusicActive(){
  final AudioManager am=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  if (am == null) {
    Log.w(TAG,"isMusicActive: couldn't get AudioManager reference");
    return false;
  }
  return am.isMusicActive();
}
 

Example 12

From project ICS_LatinIME_QHD, under directory /java/src/com/android/inputmethod/accessibility/.

Source file: AccessibilityUtils.java

  32 
vote

private void initInternal(Context context,SharedPreferences prefs){
  mContext=context;
  mAccessibilityManager=(AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
  mCompatManager=new AccessibilityManagerCompatWrapper(mAccessibilityManager);
  final AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  mAudioManager=new AudioManagerCompatWrapper(audioManager);
}
 

Example 13

From project Juggernaut_SystemUI, under directory /src/com/android/systemui/statusbar/policy/.

Source file: StatusBarPolicy.java

  32 
vote

private final void updateVolume(){
  AudioManager audioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  final int ringerMode=audioManager.getRingerMode();
  final boolean visible=ringerMode == AudioManager.RINGER_MODE_SILENT || ringerMode == AudioManager.RINGER_MODE_VIBRATE;
  final int iconId=audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) ? R.drawable.stat_sys_ringer_vibrate : R.drawable.stat_sys_ringer_silent;
  if (visible) {
    mService.setIcon("volume",iconId,0);
  }
  if (visible != mVolumeVisible) {
    mService.setIconVisibility("volume",visible);
    mVolumeVisible=visible;
  }
}
 

Example 14

From project mediaphone, under directory /src/ac/robinson/mediaphone/view/.

Source file: CameraView.java

  32 
vote

private void playAutoFocusSound(){
  if (mFocusSoundPlayer != null && mFocusSoundId >= 0) {
    AudioManager audioManager=(AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
    int streamVolumeCurrent=audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
    if (streamVolumeCurrent > 0) {
      float streamVolumeMax=audioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
      float volume=streamVolumeCurrent / streamVolumeMax;
      mFocusSoundPlayer.play(mFocusSoundId,volume,volume,1,0,1);
    }
  }
}
 

Example 15

From project MicDroid, under directory /src/com/intervigil/micdroid/recorder/.

Source file: SimpleRecorder.java

  32 
vote

public void initialize() throws FileNotFoundException, InvalidWaveException, IOException {
  if (instrumentalReader != null) {
    instrumentalReader.openWave();
    Resample.initialize(instrumentalReader.getSampleRate(),sampleRate,Resample.DEFAULT_BUFFER_SIZE,instrumentalReader.getChannels());
  }
  writer.createWaveFile();
  if (isLiveMode) {
    AudioManager am=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_NORMAL);
  }
}
 

Example 16

From project Mobile-Tour-Guide, under directory /zxing-2.0/android/src/com/google/zxing/client/android/.

Source file: BeepManager.java

  32 
vote

private static boolean shouldBeep(SharedPreferences prefs,Context activity){
  boolean shouldPlayBeep=prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP,true);
  if (shouldPlayBeep) {
    AudioManager audioService=(AudioManager)activity.getSystemService(Context.AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
      shouldPlayBeep=false;
    }
  }
  return shouldPlayBeep;
}
 

Example 17

From project NFCShopping, under directory /nfc updater client/NFCUpdater/src/scut/bgooo/updater/ui/.

Source file: NFCWriterActivity.java

  32 
vote

@Override public void onResume(){
  super.onResume();
  mAdapter.enableForegroundDispatch(this,mPendingIntent,mFilters,mTechLists);
  playBeep=true;
  AudioManager audioService=(AudioManager)getSystemService(AUDIO_SERVICE);
  if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
    playBeep=false;
  }
  initBeepSound();
  vibrate=true;
}
 

Example 18

From project OneMoreDream, under directory /src/com/dixheure/.

Source file: AlarmKlaxon.java

  32 
vote

private void startAlarm(MediaPlayer player) throws java.io.IOException, IllegalArgumentException, IllegalStateException {
  mPlaying=true;
  final AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
    player.setAudioStreamType(AudioManager.STREAM_ALARM);
    player.setLooping(true);
    player.prepare();
    player.start();
    Intent intent=new Intent(TRACK_ACTION);
    sendBroadcast(intent);
  }
}
 

Example 19

From project dmix, under directory /MPDroid/src/com/namelessdev/mpdroid/.

Source file: StreamingService.java

  31 
vote

@Override public void onCallStateChanged(int state,String incomingNumber){
  MPDApplication app=(MPDApplication)getApplication();
  if (app == null)   return;
  if (!((MPDApplication)app).getApplicationState().streamingMode) {
    stopSelf();
    return;
  }
  if (state == TelephonyManager.CALL_STATE_RINGING) {
    AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
    int ringvolume=audioManager.getStreamVolume(AudioManager.STREAM_RING);
    if (ringvolume > 0 && isPlaying) {
      isPaused=true;
      pauseStreaming();
    }
  }
 else   if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
    if (isPlaying == false)     return;
    isPaused=(isPaused || isPlaying) && (app.getApplicationState().streamingMode);
    pauseStreaming();
  }
 else   if (state == TelephonyManager.CALL_STATE_IDLE) {
    if (isPaused) {
      resumeStreaming();
    }
  }
}
 

Example 20

From project droidgiro-android, under directory /src/se/droidgiro/scanner/.

Source file: CaptureActivity.java

  31 
vote

@Override protected void onResume(){
  super.onResume();
  resetStatusView();
  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);
  }
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  playBeep=prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP,true);
  if (playBeep) {
    AudioManager audioService=(AudioManager)getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
      playBeep=false;
    }
  }
  vibrate=prefs.getBoolean(PreferencesActivity.KEY_VIBRATE,false);
  initBeepSound();
}
 

Example 21

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/ui/fragments/.

Source file: AppsViewFragment.java

  31 
vote

@Override public boolean onKeyUp(int keyCode,KeyEvent event){
  if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
    if (!event.isTracking()) {
      return true;
    }
    if (!event.isLongPress()) {
      AudioManager audio=(AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
      audio.adjustVolume(AudioManager.ADJUST_RAISE,AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
      return true;
    }
  }
  if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
    if (!event.isTracking()) {
      return true;
    }
    if (!event.isLongPress()) {
      AudioManager audio=(AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
      audio.adjustVolume(AudioManager.ADJUST_LOWER,AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
      return true;
    }
  }
  return false;
}
 

Example 22

From project HapiPodcastJ, under directory /src/info/xuluan/podcast/service/.

Source file: PlayerService.java

  31 
vote

@Override public void onCallStateChanged(int state,String incomingNumber){
  if (state == TelephonyManager.CALL_STATE_RINGING) {
    AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
    int ringvolume=audioManager.getStreamVolume(AudioManager.STREAM_RING);
    if (ringvolume > 0) {
      mResumeAfterCall=(isPlaying() || mResumeAfterCall) && (mItem != null);
      pause();
    }
  }
 else   if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
    mResumeAfterCall=(isPlaying() || mResumeAfterCall) && (mItem != null);
    pause();
  }
 else   if (state == TelephonyManager.CALL_STATE_IDLE) {
    if (mResumeAfterCall) {
      startAndFadeIn();
      mResumeAfterCall=false;
    }
  }
}
 

Example 23

From project iJetty, under directory /console/webapp/src/main/java/org/mortbay/ijetty/console/.

Source file: FinderServlet.java

  31 
vote

public void ring(String sec){
  int seconds=DEFAULT_RING_SEC;
  if (sec != null) {
    sec=sec.trim();
    if (!"".equals(sec))     seconds=Integer.valueOf(sec);
  }
  if (mediaPlayer == null) {
    Uri uri=RingtoneManager.getActualDefaultRingtoneUri(androidContext,RingtoneManager.TYPE_RINGTONE);
    mediaListener=new MediaListener();
    mediaPlayer=new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
      mediaPlayer.setDataSource(androidContext,uri);
      mediaPlayer.setOnPreparedListener(mediaListener);
      mediaPlayer.setOnCompletionListener(mediaListener);
      mediaPlayer.setOnErrorListener(mediaListener);
    }
 catch (    Exception e) {
      Log.i(TAG,"Error preparing ring",e);
    }
  }
  if (!mediaPlayer.isPlaying()) {
    mediaPlayer.prepareAsync();
  }
 else   Log.i(TAG,"Ring already playing");
}
 

Example 24

From project lullaby, under directory /src/net/sileht/lullaby/player/.

Source file: PlayerService.java

  31 
vote

@Override public void onCallStateChanged(int state,String incomingNumber){
  Context ctx=getApplicationContext();
  if (state == TelephonyManager.CALL_STATE_RINGING) {
    AudioManager audioManager=(AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
    int ringvolume=audioManager.getStreamVolume(AudioManager.STREAM_RING);
    if (ringvolume > 0) {
      mResumeAfterCall=(mPlayer.isPlaying() || mResumeAfterCall);
      mPlayer.pause();
    }
  }
 else   if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
    mResumeAfterCall=(mPlayer.isPlaying() || mResumeAfterCall);
    mPlayer.pause();
  }
 else   if (state == TelephonyManager.CALL_STATE_IDLE) {
    if (mResumeAfterCall) {
      mPlayer.start();
      mResumeAfterCall=false;
    }
  }
}
 

Example 25

From project MediaButtons, under directory /src/com/github/mediabuttons/.

Source file: Widget.java

  31 
vote

/** 
 * Return a remote view for a widget with the given action.  Create one if it doesn't exist yet.
 * @param context   The current context.
 * @param action_index   An index in action configuration tables inConfigure.  Represents which type of media button this is.
 * @return   A RemoteViews for the widget requested.
 */
public synchronized static RemoteViews makeRemoteViews(Context context,int action_index){
  if (action_index == Configure.PLAY_PAUSE_ACTION) {
    AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.isMusicActive()) {
      action_index=Configure.PAUSE_PLAY_ACTION;
    }
  }
  if (sViews[action_index] == null) {
    int keyCode=Configure.sKeyCode[action_index];
    Intent intent=new Intent(Broadcaster.BROADCAST_MEDIA_BUTTON);
    intent.setClass(context,Broadcaster.class);
    intent.setData(Uri.parse("http://" + keyCode));
    PendingIntent pendingIntent=PendingIntent.getService(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.widget);
    ButtonImageSource.getSource().setButtonIcon(views,action_index);
    views.setOnClickPendingIntent(R.id.button,pendingIntent);
    sViews[action_index]=views;
  }
  return sViews[action_index];
}
 

Example 26

From project packages_apps_Calendar, under directory /src/com/android/calendar/alerts/.

Source file: AlertService.java

  31 
vote

private static void postNotification(Context context,SharedPreferences prefs,String eventName,String location,int numReminders,boolean quietUpdate,boolean highPriority,long startMillis,boolean allDay){
  if (DEBUG) {
    Log.d(TAG,"###### creating new alarm notification, numReminders: " + numReminders + (quietUpdate ? " QUIET" : " loud")+ (highPriority ? " high-priority" : ""));
  }
  NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
  if (numReminders == 0) {
    nm.cancel(0);
    return;
  }
  Notification notification=AlertReceiver.makeNewAlertNotification(context,eventName,location,numReminders,highPriority,startMillis,allDay);
  notification.defaults|=Notification.DEFAULT_LIGHTS;
  if (!quietUpdate) {
    notification.tickerText=eventName;
    if (!TextUtils.isEmpty(location)) {
      notification.tickerText=eventName + " - " + location;
    }
    String vibrateWhen;
    if (prefs.contains(GeneralPreferences.KEY_ALERTS_VIBRATE_WHEN)) {
      vibrateWhen=prefs.getString(GeneralPreferences.KEY_ALERTS_VIBRATE_WHEN,null);
    }
 else     if (prefs.contains(GeneralPreferences.KEY_ALERTS_VIBRATE)) {
      boolean vibrate=prefs.getBoolean(GeneralPreferences.KEY_ALERTS_VIBRATE,false);
      vibrateWhen=vibrate ? context.getString(R.string.prefDefault_alerts_vibrate_true) : context.getString(R.string.prefDefault_alerts_vibrate_false);
    }
 else {
      vibrateWhen=context.getString(R.string.prefDefault_alerts_vibrateWhen);
    }
    boolean vibrateAlways=vibrateWhen.equals("always");
    boolean vibrateSilent=vibrateWhen.equals("silent");
    AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    boolean nowSilent=audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE;
    if (vibrateAlways || (vibrateSilent && nowSilent)) {
      notification.defaults|=Notification.DEFAULT_VIBRATE;
    }
    String reminderRingtone=prefs.getString(GeneralPreferences.KEY_ALERTS_RINGTONE,null);
    notification.sound=TextUtils.isEmpty(reminderRingtone) ? null : Uri.parse(reminderRingtone);
  }
  nm.notify(0,notification);
}
 

Example 27

From project packages_apps_Phone_1, under directory /src/com/android/phone/.

Source file: EmergencyDialer.java

  31 
vote

/** 
 * Plays the specified tone for TONE_LENGTH_MS milliseconds. The tone is played locally, using the audio stream for phone calls. Tones are played only if the "Audible touch tones" user preference is checked, and are NOT played if the device is in silent mode.
 * @param tone a tone code from {@link ToneGenerator}
 */
void playTone(int tone){
  if (!mDTMFToneEnabled) {
    return;
  }
  AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  int ringerMode=audioManager.getRingerMode();
  if ((ringerMode == AudioManager.RINGER_MODE_SILENT) || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
    return;
  }
synchronized (mToneGeneratorLock) {
    if (mToneGenerator == null) {
      Log.w(LOG_TAG,"playTone: mToneGenerator == null, tone: " + tone);
      return;
    }
    mToneGenerator.startTone(tone,TONE_LENGTH_MS);
  }
}
 

Example 28

From project adg-android, under directory /src/com/analysedesgeeks/android/os_service/.

Source file: PodcastPlaybackService.java

  29 
vote

@Override public void onCreate(){
  super.onCreate();
  mAudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  mAudioManager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(),MediaButtonIntentReceiver.class.getName()));
  mPlayer=new MultiPlayer();
  mPlayer.setHandler(mMediaplayerHandler);
  final IntentFilter commandFilter=new IntentFilter();
  commandFilter.addAction(SERVICECMD);
  commandFilter.addAction(TOGGLEPAUSE_ACTION);
  commandFilter.addAction(PAUSE_ACTION);
  registerReceiver(mIntentReceiver,commandFilter);
  final PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
  mWakeLock=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,this.getClass().getName());
  mWakeLock.setReferenceCounted(false);
  final Message msg=mDelayedStopHandler.obtainMessage();
  mDelayedStopHandler.sendMessageDelayed(msg,IDLE_DELAY);
}
 

Example 29

From project android-context, under directory /src/edu/fsu/cs/contextprovider/.

Source file: ContextAccuracyActivity.java

  29 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  final PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
  wakelock=pm.newWakeLock(PowerManager.FULL_WAKE_LOCK,"ContextAccuracyActivity");
  wakelock.acquire();
  KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE);
  KeyguardManager.KeyguardLock keylock=km.newKeyguardLock(TAG);
  keylock.disableKeyguard();
  getPrefs();
  setContentView(R.layout.accuracy);
  vibrate=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
  audio=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  volume=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  placeBar=(SeekBar)findViewById(R.id.place);
  movementBar=(SeekBar)findViewById(R.id.movement);
  activityBar=(SeekBar)findViewById(R.id.activity);
  shelterGroup=(RadioGroup)findViewById(R.id.shelter);
  shelterCorrect=(RadioButton)findViewById(R.id.shelterCorrect);
  onPersonGroup=(RadioGroup)findViewById(R.id.onPerson);
  onPersonCorrect=(RadioButton)findViewById(R.id.onPersonCorrect);
  placeText=(EditText)findViewById(R.id.editPlace);
  movementText=(EditText)findViewById(R.id.editMovement);
  activityText=(EditText)findViewById(R.id.editActivity);
  shelterText=(EditText)findViewById(R.id.editShelter);
  onPersonText=(EditText)findViewById(R.id.editOnPerson);
  placeText.setText(DerivedMonitor.getPlace());
  movementText.setText(MovementMonitor.getMovementState());
  activityText.setText(DerivedMonitor.getActivity());
  shelterText.setText(DerivedMonitor.getShelterString());
  onPersonText.setText(DerivedMonitor.getOnPersonString());
  submitBtn=(Button)findViewById(R.id.SubmitButton);
  resetBtn=(Button)findViewById(R.id.ResetButton);
  submitBtn.setOnClickListener(this);
  resetBtn.setOnClickListener(this);
  resetBars();
  if (accuracyAudioEnabled)   tone.play();
  if (accuracyVibrateEnabled)   startVibrate();
  timer=new Timer();
  timer.schedule(new ContextDismissTask(),(dismissDelay * 1000));
}
 

Example 30

From project android-gltron, under directory /GlTron/src/com/glTron/Sound/.

Source file: SoundManager.java

  29 
vote

public static void initSounds(Context theContext){
  mContext=theContext;
  mSoundPool=new SoundPool(MAX_SOUNDS,AudioManager.STREAM_MUSIC,0);
  mSoundPoolMap=new HashMap<Integer,Integer>();
  mAudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
}
 

Example 31

From project android-joedayz, under directory /Proyectos/SoundsTest/src/com/androideity/sounds/.

Source file: SoundsTestActivity.java

  29 
vote

/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  snd=new SoundManager(getApplicationContext());
  this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
  laser=snd.load(R.raw.laser);
  explode=snd.load(R.raw.explosion);
  pickup=snd.load(R.raw.pickup);
  meow=snd.load(R.raw.cat);
  bark=snd.load(R.raw.barkloud);
  moo=snd.load(R.raw.cow);
  barChange=new OnSeekBarChangeListener(){
    @Override public void onStopTrackingTouch(    SeekBar seekBar){
    }
    @Override public void onStartTrackingTouch(    SeekBar seekBar){
    }
    @Override public void onProgressChanged(    SeekBar seekBar,    int progress,    boolean fromUser){
switch (seekBar.getId()) {
case R.id.VolBar1:
        snd.setVolume((float)progress / 100.0f);
      break;
case R.id.BalBar:
    snd.setBalance((float)progress / 100.0f);
  break;
case R.id.SpeedBar:
snd.setSpeed((float)progress / 100.0f);
break;
}
}
}
;
SeekBar sb;
sb=(SeekBar)findViewById(R.id.SpeedBar);
sb.setOnSeekBarChangeListener(barChange);
sb=(SeekBar)findViewById(R.id.BalBar);
sb.setOnSeekBarChangeListener(barChange);
sb=(SeekBar)findViewById(R.id.VolBar1);
sb.setOnSeekBarChangeListener(barChange);
}
 

Example 32

From project Android-RTMP, under directory /android-ffmpeg-prototype/src/com/camundo/media/.

Source file: AudioSubscriber.java

  29 
vote

@Override public void run(){
  try {
    pipe.start();
    while (!pipe.initialized()) {
      Log.i(TAG,"[ run() ] pipe not yet running, waiting.");
      try {
        Thread.sleep(1000);
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    int minBufferSize=AudioTrack.getMinBufferSize(pipe.getSampleRate(),pipe.getChannelConfig(),pipe.getEncoding());
    audioTrack=new AudioTrack(AudioManager.STREAM_VOICE_CALL,pipe.getSampleRate(),pipe.getChannelConfig(),pipe.getEncoding(),minBufferSize * 4,AudioTrack.MODE_STREAM);
    ByteBuffer buffer=ByteBuffer.allocate(minBufferSize);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    Log.d(TAG,"buffer length [" + minBufferSize + "]");
    int len;
    pipe.bootstrap();
    boolean started=false;
    while ((len=pipe.read(buffer.array())) > 0) {
      overallBytesReceived+=audioTrack.write(buffer.array(),0,len);
      if (!started && overallBytesReceived > minBufferSize) {
        audioTrack.play();
        started=true;
      }
    }
  }
 catch (  IOException e) {
    Log.e(TAG,"[ run() ]",e);
  }
  Log.i(TAG,"[ run() ] done");
}
 

Example 33

From project android-tether, under directory /src/og/android/tether/.

Source file: C2DMReceiver.java

  29 
vote

public static void playNotificationSound(Context context){
  Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  if (uri != null) {
    Ringtone rt=RingtoneManager.getRingtone(context,uri);
    if (rt != null) {
      rt.setStreamType(AudioManager.STREAM_NOTIFICATION);
      rt.play();
    }
  }
}
 

Example 34

From project android-voip-service, under directory /src/main/java/org/linphone/core/.

Source file: Hacks.java

  29 
vote

public static void galaxySSwitchToCallStreamUnMuteLowerVolume(AudioManager am){
  am.setSpeakerphoneOn(false);
  sleep(200);
  am.setStreamVolume(AudioManager.STREAM_VOICE_CALL,1,0);
  am.setMode(AudioManager.MODE_NORMAL);
  sleep(200);
  am.setMicrophoneMute(true);
  sleep(200);
  am.setMicrophoneMute(false);
  sleep(200);
}
 

Example 35

From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/activity/.

Source file: ConfigurationManager.java

  29 
vote

public void onActivityResume(Activity activity){
switch (mKeyguardState) {
case INT_KEYGUARD_STATUS_REMOTE_ONLY:
    if (activity.getClass().equals(RemoteActivity.class))     disableKeyguard(activity);
 else     enableKeyguard();
  break;
case INT_KEYGUARD_STATUS_ALL:
disableKeyguard(activity);
break;
default :
enableKeyguard();
break;
}
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
mActivity=activity;
}
 

Example 36

From project Android_1, under directory /simperAudioStreamer/src/novoda/audio/service/.

Source file: AudioStreamService.java

  29 
vote

public AudioStreamService(){
  mAudioSrvState=NOT_PLAYING;
  mMediaPlayer=new MediaPlayer();
  mMediaPlayer.setOnBufferingUpdateListener(this);
  mMediaPlayer.setOnCompletionListener(this);
  mMediaPlayer.setOnPreparedListener(this);
  mMediaPlayer.setOnErrorListener(this);
  mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
 

Example 37

From project android_packages_apps_CellBroadcastReceiver, under directory /src/com/android/cellbroadcastreceiver/.

Source file: CellBroadcastAlertAudio.java

  29 
vote

@Override public void onCreate(){
  PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
  mWakeLock=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,TAG);
  mWakeLock.acquire();
  mVibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
  mAudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  mTelephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  mTelephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
}
 

Example 38

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: Camera.java

  29 
vote

private void initializeFocusTone(){
  try {
    mFocusToneGenerator=new ToneGenerator(AudioManager.STREAM_SYSTEM,FOCUS_BEEP_VOLUME);
  }
 catch (  Throwable ex) {
    Log.w(TAG,"Exception caught while creating tone generator: ",ex);
    mFocusToneGenerator=null;
  }
}
 

Example 39

From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.

Source file: NfcService.java

  29 
vote

void initSoundPool(){
synchronized (this) {
    if (mSoundPool == null) {
      mSoundPool=new SoundPool(1,AudioManager.STREAM_NOTIFICATION,0);
      mStartSound=mSoundPool.load(this,R.raw.start,1);
      mEndSound=mSoundPool.load(this,R.raw.end,1);
      mErrorSound=mSoundPool.load(this,R.raw.error,1);
    }
  }
}
 

Example 40

From project android_packages_apps_VoiceDialer_2, under directory /src/com/android/voicedialer/.

Source file: VoiceDialerActivity.java

  29 
vote

public void onInit(int status){
  if (false)   Log.d(TAG,"onInit for tts");
  if (status != TextToSpeech.SUCCESS) {
    Log.e(TAG,"Could not initialize TextToSpeech.");
    mHandler.post(new ErrorRunnable(R.string.recognition_error));
    exitActivity();
    return;
  }
  if (mTts == null) {
    Log.e(TAG,"null tts");
    mHandler.post(new ErrorRunnable(R.string.recognition_error));
    exitActivity();
    return;
  }
  mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener());
  mWaitingForTts=false;
  mBluetoothVoiceVolume=mAudioManager.getStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO);
  int maxVolume=mAudioManager.getStreamMaxVolume(AudioManager.STREAM_BLUETOOTH_SCO);
  int volume=maxVolume - ((18 / (50 / maxVolume)) + 1);
  if (mBluetoothVoiceVolume > volume) {
    mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO,volume,0);
  }
  if (mWaitingForScoConnection) {
  }
 else {
    mHandler.postDelayed(new GreetingRunnable(),FIRST_UTTERANCE_DELAY);
  }
}
 

Example 41

From project Anki-Android, under directory /src/com/ichi2/anki/.

Source file: Sound.java

  29 
vote

/** 
 * Play the sound indicated by the path stored on the position soundToPlayIndex of the mSoundPaths array.
 * @param soundToPlayIndex
 */
private static void playSound(int soundToPlayIndex){
  sStartSoundTime=System.currentTimeMillis();
  sMediaPlayer=new MediaPlayer();
  try {
    sMediaPlayer.setDataSource(sSoundPaths.get(soundToPlayIndex));
    sMediaPlayer.setVolume(AudioManager.STREAM_MUSIC,AudioManager.STREAM_MUSIC);
    sMediaPlayer.prepare();
    sMediaPlayer.setOnCompletionListener(new OnCompletionListener(){
      @Override public void onCompletion(      MediaPlayer mp){
        releaseSound();
        sNumSoundsPlayed++;
        sFinishSoundTime=System.currentTimeMillis();
        if (sNumSoundsPlayed < sSoundPaths.size()) {
          playSound(sNumSoundsPlayed);
        }
 else {
          sFinishTime=System.currentTimeMillis();
        }
      }
    }
);
    sMediaPlayer.start();
  }
 catch (  Exception e) {
    Log.e(AnkiDroidApp.TAG,"playSounds - Error reproducing sound " + (soundToPlayIndex + 1) + " = "+ e.getMessage());
    releaseSound();
  }
}
 

Example 42

From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/.

Source file: AnySoftKeyboard.java

  29 
vote

@Override public void onCreate(){
  super.onCreate();
  Log.i(TAG,"****** AnySoftKeyboard service started.");
  Thread.setDefaultUncaughtExceptionHandler(new ChewbaccaUncaughtExceptionHandler(getApplication().getBaseContext(),null));
  mInputMethodManager=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
  mAudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  updateRingerMode();
  registerReceiver(mSoundPreferencesChangedReceiver,mSoundPreferencesChangedReceiver.createFilterToRegisterOn());
  registerReceiver(mPackagesChangedReceiver,mPackagesChangedReceiver.createFilterToRegisterOn());
  mVibrator=((Vibrator)getSystemService(Context.VIBRATOR_SERVICE));
  loadSettings();
  mConfig.addChangedListener(this);
  mKeyboardSwitcher=new KeyboardSwitcher(this);
  mOrientation=getResources().getConfiguration().orientation;
  mSentenceSeparators=getCurrentKeyboard().getSentenceSeparators();
  if (mSuggest == null) {
    initSuggest();
  }
  if (mKeyboardChangeNotificationType.equals(KEYBOARD_NOTIFICATION_ALWAYS)) {
    notifyKeyboardChangeIfNeeded();
  }
  mVoiceRecognitionTrigger=AnyApplication.getDeviceSpecific().createVoiceInput(this);
  TutorialsProvider.showChangeLogIfNeeded(getApplicationContext());
  mSwitchAnimator=new LayoutSwitchAnimationListener(this);
}
 

Example 43

From project apps-for-android, under directory /CLiCkin2DaBeaT/src/com/google/clickin2dabeat/.

Source file: GameView.java

  29 
vote

public GameView(Context context){
  super(context);
  parent=(C2B)context;
  lastTarget=0;
  score=0;
  comboCount=0;
  longestCombo=0;
  lastRating="";
  drawnTargets=new ArrayList<Target>();
  recordedTargets=new ArrayList<Target>();
  vibe=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
  snd=new SoundPool(10,AudioManager.STREAM_SYSTEM,0);
  missSfx=snd.load(context,R.raw.miss,0);
  hitOkSfx=snd.load(context,R.raw.ok,0);
  hitPerfectSfx=snd.load(context,R.raw.perfect,0);
  innerPaint=new Paint();
  innerPaint.setColor(Color.argb(127,0,0,0));
  innerPaint.setStyle(Paint.Style.FILL);
  borderPaint=new Paint();
  borderPaint.setStyle(Paint.Style.STROKE);
  borderPaint.setAntiAlias(true);
  borderPaint.setStrokeWidth(2);
  haloPaint=new Paint();
  haloPaint.setStyle(Paint.Style.STROKE);
  haloPaint.setAntiAlias(true);
  haloPaint.setStrokeWidth(4);
  Thread monitorThread=(new Thread(new Monitor()));
  monitorThread.setPriority(Thread.MIN_PRIORITY);
  monitorThread.start();
}
 

Example 44

From project BibleQuote-for-Android, under directory /src/com/BibleQuote/activity/.

Source file: ReaderActivity.java

  29 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.reader);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
  getSupportActionBar().setIcon(R.drawable.app_logo);
  getSupportActionBar().setDisplayShowTitleEnabled(false);
  ViewUtils.setActionBarBackground(this);
  BibleQuoteApp app=(BibleQuoteApp)getApplication();
  myLibrarian=app.getLibrarian();
  mAsyncManager=app.getAsyncManager();
  mAsyncManager.handleRetainedTask(getLastNonConfigurationInstance(),this);
  btnChapterNav=(LinearLayout)findViewById(R.id.btn_chapter_nav);
  ImageButton btnChapterPrev=(ImageButton)findViewById(R.id.btn_reader_prev);
  btnChapterPrev.setOnClickListener(onClickChapterPrev);
  ImageButton btnChapterNext=(ImageButton)findViewById(R.id.btn_reader_next);
  btnChapterNext.setOnClickListener(onClickChapterNext);
  ImageButton btnChapterUp=(ImageButton)findViewById(R.id.btn_reader_up);
  btnChapterUp.setOnClickListener(onClickPageUp);
  ImageButton btnChapterDown=(ImageButton)findViewById(R.id.btn_reader_down);
  btnChapterDown.setOnClickListener(onClickPageDown);
  vModuleName=(TextView)findViewById(R.id.moduleName);
  vBookLink=(TextView)findViewById(R.id.linkBook);
  progressMessage=getResources().getString(R.string.messageLoad);
  nightMode=PreferenceHelper.restoreStateBoolean("nightMode");
  vWeb=(ReaderWebView)findViewById(R.id.readerView);
  vWeb.setOnReaderViewListener(this);
  vWeb.setReadingMode(PreferenceHelper.isReadModeByDefault());
  updateActivityMode();
  BibleReference osisLink=new BibleReference(PreferenceHelper.restoreStateString("last_read"));
  if (!myLibrarian.isOSISLinkValid(osisLink)) {
    onChooseChapterClick();
  }
 else {
    mAsyncManager.setupTask(new AsyncOpenChapter(progressMessage,false,myLibrarian,osisLink),this);
  }
}
 

Example 45

From project Binaural-Beats, under directory /src/com/ihunda/android/binauralbeat/.

Source file: BBeat.java

  29 
vote

void initSounds(){
  if (mSoundPool != null) {
    mSoundPool.release();
    mSoundPool=null;
  }
  mSoundPool=new SoundPool(MAX_STREAMS,AudioManager.STREAM_MUSIC,0);
  soundWhiteNoise=mSoundPool.load(this,R.raw.whitenoise,1);
  soundUnity=mSoundPool.load(this,R.raw.unity,1);
  playingStreams=new Vector<StreamVoice>(MAX_STREAMS);
  playingBackground=-1;
}
 

Example 46

From project buzzwords, under directory /src/com/buzzwords/.

Source file: Buzzer.java

  29 
vote

/** 
 * onCreate - initializes a buzzer screen
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  if (BuzzWordsApplication.DEBUG) {
    Log.d(TAG,"onCreate()");
  }
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
  this.setContentView(R.layout.buzzer);
  ImageButton buzzButton=(ImageButton)this.findViewById(R.id.Buzzer_Button);
  buzzButton.setOnTouchListener(mBuzzTouch);
}
 

Example 47

From project Cafe, under directory /testservice/src/com/baidu/cafe/remote/.

Source file: SystemLib.java

  29 
vote

public SystemLib(Context context){
  mContext=context;
  mTelephonyManager=(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
  mKeyguardManager=(KeyguardManager)mContext.getSystemService(Context.KEYGUARD_SERVICE);
  mBatteryState=new BatteryState(mContext);
  mAudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  mPowerManager=(PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
  mWifiManager=(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
  mPackageManager=mContext.getPackageManager();
  mIntentFilter=new IntentFilter();
  mIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
  mWakeLock=mPowerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"Test Acquired!");
  mActivityManager=(ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
}
 

Example 48

From project connectbot, under directory /src/sk/vx/connectbot/.

Source file: ConsoleActivity.java

  29 
vote

@Override public boolean onPrepareOptionsMenu(Menu menu){
  super.onPrepareOptionsMenu(menu);
  setVolumeControlStream(AudioManager.STREAM_NOTIFICATION);
  final View view=findCurrentView(R.id.console_flip);
  boolean activeTerminal=(view instanceof TerminalView);
  boolean sessionOpen=false;
  boolean disconnected=false;
  boolean canForwardPorts=false;
  boolean canTransferFiles=false;
  if (activeTerminal) {
    TerminalBridge bridge=((TerminalView)view).bridge;
    sessionOpen=bridge.isSessionOpen();
    disconnected=bridge.isDisconnected();
    canForwardPorts=bridge.canFowardPorts();
    canTransferFiles=bridge.canTransferFiles();
  }
  disconnect.setEnabled(activeTerminal);
  if (sessionOpen || !disconnected)   disconnect.setTitle(R.string.list_host_disconnect);
 else   disconnect.setTitle(R.string.console_menu_close);
  copy.setEnabled(activeTerminal);
  paste.setEnabled(clipboard.hasText() && sessionOpen);
  portForward.setEnabled(sessionOpen && canForwardPorts);
  urlscan.setEnabled(activeTerminal);
  resize.setEnabled(sessionOpen);
  download.setEnabled(sessionOpen && canTransferFiles);
  upload.setEnabled(sessionOpen && canTransferFiles);
  return true;
}
 

Example 49

From project creamed_glacier_app_settings, under directory /src/com/android/settings/.

Source file: RingerVolumePreference.java

  29 
vote

private void updateSlidersAndMutedStates(){
  for (int i=0; i < SEEKBAR_TYPE.length; i++) {
    int streamType=SEEKBAR_TYPE[i];
    boolean muted=mAudioManager.isStreamMute(streamType);
    if (mCheckBoxes[i] != null) {
      if (streamType == AudioManager.STREAM_RING && muted && mAudioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)) {
        mCheckBoxes[i].setImageResource(com.android.internal.R.drawable.ic_audio_ring_notif_vibrate);
      }
 else {
        mCheckBoxes[i].setImageResource(muted ? SEEKBAR_MUTED_RES_ID[i] : SEEKBAR_UNMUTED_RES_ID[i]);
      }
    }
    if (mSeekBars[i] != null) {
      final int volume=muted ? mAudioManager.getLastAudibleStreamVolume(streamType) : mAudioManager.getStreamVolume(streamType);
      mSeekBars[i].setProgress(volume);
    }
  }
}
 

Example 50

From project cw-advandroid, under directory /SystemServices/Volume/src/com/commonsware/android/syssvc/volume/.

Source file: Volumizer.java

  29 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  mgr=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  alarm=(SeekBar)findViewById(R.id.alarm);
  music=(SeekBar)findViewById(R.id.music);
  ring=(SeekBar)findViewById(R.id.ring);
  system=(SeekBar)findViewById(R.id.system);
  voice=(SeekBar)findViewById(R.id.voice);
  initBar(alarm,AudioManager.STREAM_ALARM);
  initBar(music,AudioManager.STREAM_MUSIC);
  initBar(ring,AudioManager.STREAM_RING);
  initBar(system,AudioManager.STREAM_SYSTEM);
  initBar(voice,AudioManager.STREAM_VOICE_CALL);
}
 

Example 51

From project cw-omnibus, under directory /SystemServices/Volume/src/com/commonsware/android/syssvc/volume/.

Source file: Volumizer.java

  29 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  mgr=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  alarm=(SeekBar)findViewById(R.id.alarm);
  music=(SeekBar)findViewById(R.id.music);
  ring=(SeekBar)findViewById(R.id.ring);
  system=(SeekBar)findViewById(R.id.system);
  voice=(SeekBar)findViewById(R.id.voice);
  initBar(alarm,AudioManager.STREAM_ALARM);
  initBar(music,AudioManager.STREAM_MUSIC);
  initBar(ring,AudioManager.STREAM_RING);
  initBar(system,AudioManager.STREAM_SYSTEM);
  initBar(voice,AudioManager.STREAM_VOICE_CALL);
}
 

Example 52

From project external-replicaisland, under directory /src/com/replica/replicaisland/.

Source file: DifficultyMenuActivity.java

  29 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.difficulty_menu);
  mBabyButton=findViewById(R.id.babyButton);
  mKidsButton=findViewById(R.id.kidsButton);
  mAdultsButton=findViewById(R.id.adultsButton);
  mBabyText=findViewById(R.id.babyText);
  mKidsText=findViewById(R.id.kidsText);
  mAdultsText=findViewById(R.id.adultsText);
  mBackground=findViewById(R.id.mainMenuBackground);
  mBabyButton.setOnClickListener(sBabyButtonListener);
  mKidsButton.setOnClickListener(sKidsButtonListener);
  mAdultsButton.setOnClickListener(sAdultsButtonListener);
  mButtonFlickerAnimation=AnimationUtils.loadAnimation(this,R.anim.button_flicker);
  mFadeOutAnimation=AnimationUtils.loadAnimation(this,R.anim.fade_out);
  mAlternateFadeOutAnimation=AnimationUtils.loadAnimation(this,R.anim.fade_out);
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
 

Example 53

From project flexymind-alpha, under directory /src/com/flexymind/alpha/.

Source file: Settings.java

  29 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.settings_layout);
  Spinner songSpinner=(Spinner)findViewById(R.id.songSpinner);
  ArrayAdapter<CharSequence> songAdapter=ArrayAdapter.createFromResource(this,R.array.songs,android.R.layout.simple_spinner_item);
  songAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  songSpinner.setAdapter(songAdapter);
  songSpinner.setOnItemSelectedListener(this);
  Spinner instrumentSpinner=(Spinner)findViewById(R.id.instrumentSpinner);
  ArrayAdapter<CharSequence> instrumentAdapter=ArrayAdapter.createFromResource(this,R.array.instruments,android.R.layout.simple_spinner_item);
  instrumentAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  instrumentSpinner.setAdapter(instrumentAdapter);
  instrumentSpinner.setOnItemSelectedListener(this);
  SeekBar volumeSeekBar=(SeekBar)findViewById(R.id.volumeSeekBar);
  audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  volumeSeekBar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
}
 

Example 54

From project Gaggle, under directory /src/com/geeksville/android/.

Source file: TonePlayer.java

  29 
vote

private void createNative(){
  audioTrack=new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT,numSamples,AudioTrack.MODE_STATIC);
  audioTrack.write(toneSound,0,toneSound.length);
  audioTrack.setStereoVolume(audioTrack.getMaxVolume(),audioTrack.getMaxVolume());
  audioTrack.setNotificationMarkerPosition(numSamples - 1);
}
 

Example 55

From project GeekAlarm, under directory /android/src/com/geek_alarm/android/activities/.

Source file: TaskActivity.java

  29 
vote

private void createPlayer(){
  Uri music=Utils.getCurrentAlarmSound();
  player=new MediaPlayer();
  try {
    player.setDataSource(this,music);
    player.setAudioStreamType(AudioManager.STREAM_ALARM);
    player.setLooping(true);
    player.prepare();
  }
 catch (  Exception e) {
    player.reset();
    try {
      player.setDataSource(this,RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
      player.setAudioStreamType(AudioManager.STREAM_ALARM);
      player.setLooping(true);
      player.prepare();
    }
 catch (    Exception e2) {
      Log.e(this.getClass().getName(),"Now I don't know what to do.",e2);
    }
  }
}
 

Example 56

From project Gingerbread-Keyboard, under directory /src/com/android/inputmethod/latin/.

Source file: LatinIME.java

  29 
vote

private void updateRingerMode(){
  if (mAudioManager == null) {
    mAudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  }
  if (mAudioManager != null) {
    mSilentMode=(mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
  }
}
 

Example 57

From project gobandroid, under directory /src/org/ligi/gobandroid_hd/ui/.

Source file: GoSoundManager.java

  29 
vote

public GoSoundManager(GobandroidFragmentActivity theContext){
  Log.i("sound_man init");
  mContext=theContext;
  mSoundPool=new SoundPool(4,AudioManager.STREAM_MUSIC,0);
  mSoundPoolMap=new HashMap<Integer,Integer>();
  mAudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  addSound(SOUND_START,R.raw.go_start);
  addSound(SOUND_END,R.raw.go_clearboard);
  addSound(SOUND_PLACE1,R.raw.go_place1);
  addSound(SOUND_PLACE2,R.raw.go_place2);
  addSound(SOUND_PICKUP1,R.raw.go_pickup1);
  addSound(SOUND_PICKUP2,R.raw.go_pickup2);
}
 

Example 58

From project Hawksword, under directory /src/com/bw/hawksword/ocr/.

Source file: BeepManager.java

  29 
vote

public void initSounds(Context theContext,Activity activity){
  mContext=theContext;
  mSoundPool=new SoundPool(4,AudioManager.STREAM_MUSIC,0);
  mSoundPoolMap=new HashMap();
  mAudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  audioService=(AudioManager)activity.getSystemService(Context.AUDIO_SERVICE);
  prefs=PreferenceManager.getDefaultSharedPreferences(activity);
}
 

Example 59

From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/.

Source file: CaptureActivity.java

  29 
vote

/** 
 * Creates the beep MediaPlayer in advance so that the sound can be triggered with the least latency possible.
 */
private void initBeepSound(){
  if (playBeep && mediaPlayer == null) {
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mediaPlayer=new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(beepListener);
    AssetFileDescriptor file=getResources().openRawResourceFd(R.raw.beep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(),file.getStartOffset(),file.getLength());
      file.close();
      mediaPlayer.setVolume(BEEP_VOLUME,BEEP_VOLUME);
      mediaPlayer.prepare();
    }
 catch (    IOException e) {
      mediaPlayer=null;
    }
  }
}
 

Example 60

From project iohack, under directory /src/org/alljoyn/bus/sample/chat/.

Source file: HomeActivity.java

  29 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.home);
  mDeviceHandler=new Handler(this);
  mSettingsPollingHandler=new Handler(this);
  mPreferences=PreferenceManager.getDefaultSharedPreferences(this);
  mPreferences.registerOnSharedPreferenceChangeListener(this);
  mUSBManager=(UsbManager)getSystemService(Context.USB_SERVICE);
  mSoundFiles=new ArrayList<String>();
  setUpButton(R.id.clock_button,R.drawable.ic_clock,R.string.clock);
  setUpButton(R.id.alarm_button,R.drawable.ic_alarm,R.string.alarm);
  setUpButton(R.id.volume_button,R.drawable.ic_volume,R.string.volume);
  setUpButton(R.id.color_button,R.drawable.ic_color,R.string.color);
  setUpButton(R.id.brightness_button,R.drawable.ic_brightness,R.string.brightness);
  setUpButton(R.id.display_button,R.drawable.ic_display,R.string.display);
  setUpButton(R.id.presets_button,R.drawable.ic_presets,R.string.presets);
  updateLockDisplay();
  connectToAccessory();
  startLicenseUpload();
  sHomeActivity=this;
  startPollingSettings();
  soundIds=new int[255];
  soundPool=new SoundPool(255,AudioManager.STREAM_MUSIC,0);
  soundIds[0]=soundPool.load(this,R.raw.fallbackring,1);
  myButton=(Button)findViewById(R.id.button1);
  myButton.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      startActivity(new Intent(HomeActivity.this,ViewChannelActivity.class));
    }
  }
);
  ((Button)findViewById(R.id.button2)).setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      notifyAdk();
    }
  }
);
}
 

Example 61

From project jamendo-android, under directory /src/com/teleca/jamendo/activity/.

Source file: EqualizerActivity.java

  29 
vote

public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.equalizer);
  mRadioGroup=(RadioGroup)findViewById(R.id.equalizerPreset);
  setupEqualizerFxAndUI();
}
 

Example 62

From project k-9, under directory /src/com/fsck/k9/helper/.

Source file: NotificationBuilderApi1.java

  29 
vote

@SuppressWarnings("deprecation") @Override public Notification getNotification(){
  Notification notification=new Notification(mSmallIcon,mTickerText,mWhen);
  notification.number=mNumber;
  notification.setLatestEventInfo(mContext,mContentTitle,mContentText,mContentIntent);
  if (mSoundUri != null) {
    notification.sound=mSoundUri;
    notification.audioStreamType=AudioManager.STREAM_NOTIFICATION;
  }
  if (mVibrationPattern != null) {
    notification.vibrate=mVibrationPattern;
  }
  if (mBlinkLed) {
    notification.flags|=Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB=mLedColor;
    notification.ledOnMS=mLedOnMS;
    notification.ledOffMS=mLedOffMS;
  }
  if (mAutoCancel) {
    notification.flags|=Notification.FLAG_AUTO_CANCEL;
  }
  if (mOngoing) {
    notification.flags|=Notification.FLAG_ONGOING_EVENT;
  }
  return notification;
}
 

Example 63

From project LEGO-MINDSTORMS-MINDdroid, under directory /android/src/com/lego/minddroid/.

Source file: StartSound.java

  29 
vote

@Override public void run(){
  if (myAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
    int ringVolume=myAudioManager.getStreamVolume(AudioManager.STREAM_RING);
    MediaPlayer myMediaPlayer=MediaPlayer.create(myContext,R.raw.startdroid);
    myMediaPlayer.start();
    myMediaPlayer.setVolume(((float)ringVolume) / 10f,((float)ringVolume) / 10f);
    try {
      Thread.sleep(2000);
    }
 catch (    InterruptedException e) {
    }
    myMediaPlayer.stop();
  }
}
 

Example 64

From project LitHub, under directory /LitHub-Android/src/us/lithub/appengine/.

Source file: MessageDisplay.java

  29 
vote

private static void playNotificationSound(Context context){
  Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  if (uri != null) {
    Ringtone rt=RingtoneManager.getRingtone(context,uri);
    if (rt != null) {
      rt.setStreamType(AudioManager.STREAM_NOTIFICATION);
      rt.play();
    }
  }
}
 

Example 65

From project maven-android-plugin-samples, under directory /apidemos-android-10/application/src/main/java/com/example/android/apis/media/.

Source file: AudioFxDemo.java

  29 
vote

@Override public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
  mStatusTextView=new TextView(this);
  mLinearLayout=new LinearLayout(this);
  mLinearLayout.setOrientation(LinearLayout.VERTICAL);
  mLinearLayout.addView(mStatusTextView);
  setContentView(mLinearLayout);
  mMediaPlayer=MediaPlayer.create(this,R.raw.test_cbr);
  Log.d(TAG,"MediaPlayer audio session ID: " + mMediaPlayer.getAudioSessionId());
  setupVisualizerFxAndUI();
  setupEqualizerFxAndUI();
  mVisualizer.setEnabled(true);
  mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
    public void onCompletion(    MediaPlayer mediaPlayer){
      mVisualizer.setEnabled(false);
    }
  }
);
  mMediaPlayer.start();
  mStatusTextView.setText("Playing audio...");
}
 

Example 66

From project MIT-Mobile-for-Android, under directory /src/com/google/zxing/client/android/.

Source file: CaptureActivity.java

  29 
vote

/** 
 * Creates the beep MediaPlayer in advance so that the sound can be triggered with the least latency possible.
 */
private void initBeepSound(){
  if (playBeep && mediaPlayer == null) {
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mediaPlayer=new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(beepListener);
    AssetFileDescriptor file=getResources().openRawResourceFd(R.raw.beep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(),file.getStartOffset(),file.getLength());
      file.close();
      mediaPlayer.setVolume(BEEP_VOLUME,BEEP_VOLUME);
      mediaPlayer.prepare();
    }
 catch (    IOException e) {
      mediaPlayer=null;
    }
  }
}
 

Example 67

From project mp3tunes-android, under directory /src/com/mp3tunes/android/activity/.

Source file: PlaylistBrowser.java

  29 
vote

/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
  Music.bindToService(this);
  if (!Music.connectToDb(this))   finish();
  setContentView(R.layout.media_picker_activity);
  ListView lv=getListView();
  lv.setFastScrollEnabled(true);
  lv.setOnCreateContextMenuListener(this);
  lv.setTextFilterEnabled(true);
  mAdapter=(PlaylistListAdapter)getLastNonConfigurationInstance();
  if (mAdapter == null) {
    mAdapter=new PlaylistListAdapter(getApplication(),this,R.layout.track_list_item,mPlaylistCursor,new String[]{},new int[]{});
    setListAdapter(mAdapter);
    setTitle(R.string.title_working_playlists);
    mPlaylistTask=new FetchPlaylistsTask().execute();
  }
 else {
    mAdapter.setActivity(this);
    setListAdapter(mAdapter);
    mPlaylistCursor=mAdapter.getCursor();
    if (mPlaylistCursor != null) {
      init(mPlaylistCursor);
    }
 else {
      setTitle(R.string.title_working_playlists);
      mPlaylistTask=new FetchPlaylistsTask().execute();
    }
  }
}
 

Example 68

From project MWM-for-Android, under directory /src/org/metawatch/manager/.

Source file: MetaWatchService.java

  29 
vote

@Override public void onCreate(){
  super.onCreate();
  context=this;
  createNotification();
  connectionState=ConnectionState.CONNECTING;
  watchState=WatchStates.OFF;
  watchType=WatchType.DIGITAL;
  if (bluetoothAdapter == null)   bluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
  powerManger=(PowerManager)getSystemService(Context.POWER_SERVICE);
  wakeLock=powerManger.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MetaWatch");
  audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  Monitors.start(this,telephonyManager);
  start();
}
 

Example 69

From project Notes, under directory /src/net/micode/notes/ui/.

Source file: AlarmAlertActivity.java

  29 
vote

private void playAlarmSound(){
  Uri url=RingtoneManager.getActualDefaultRingtoneUri(this,RingtoneManager.TYPE_ALARM);
  int silentModeStreams=Settings.System.getInt(getContentResolver(),Settings.System.MODE_RINGER_STREAMS_AFFECTED,0);
  if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
    mPlayer.setAudioStreamType(silentModeStreams);
  }
 else {
    mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
  }
  try {
    mPlayer.setDataSource(this,url);
    mPlayer.prepare();
    mPlayer.setLooping(true);
    mPlayer.start();
  }
 catch (  IllegalArgumentException e) {
    e.printStackTrace();
  }
catch (  SecurityException e) {
    e.printStackTrace();
  }
catch (  IllegalStateException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 70

From project npr-android-app, under directory /src/org/npr/android/news/.

Source file: PlayerActivity.java

  29 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
  setContentView(R.layout.main);
  titleText=(TextView)findViewById(R.id.LogoNavText);
  titleText.setText(getMainTitle());
  listenView=new ListenView(this);
  ((ViewGroup)findViewById(R.id.MediaPlayer)).addView(listenView,new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
 

Example 71

From project OpenComm, under directory /SoundSpatialization/workspace/OpenCommKakapo/src/ss/kakapo/.

Source file: AudioSS.java

  29 
vote

/** 
 * Constructor: a new instance of AudioSS with AudioTrack input as well as initial position (px, py) in pixels; the region of the user and ITD/vol based on the initial position is updated; it is assumed that the user is not in any private space 
 */
public AudioSS(int px,int py){
  this.region=0;
  this.itd=0;
  this.vol=new float[2];
  this.pspace=new boolean[AudioSS.NoPSPACE];
  this.audio=new AudioTrack(AudioManager.STREAM_MUSIC,8000,AudioFormat.CHANNEL_OUT_STEREO,AudioFormat.ENCODING_PCM_16BIT,AudioSS.BUFFER_SIZE * 2 * 2,AudioTrack.MODE_STREAM);
  this.setRegion(px,py);
  this.setSS();
  Log.i(AudioSS.TAG,"AudioSS constructed for region " + this.region + ", ITD: "+ this.itd+ ", Volume: "+ this.vol[0]+ ", "+ this.vol[1]);
}
 

Example 72

From project open_robot, under directory /Android/OpenRobotLibrary/src/com/openrobot/common/.

Source file: AudioSerialOutMono.java

  29 
vote

private static void playSound(){
  active=true;
  while (active) {
    try {
      Thread.sleep(Long.MAX_VALUE);
    }
 catch (    InterruptedException e) {
      while (playque.isEmpty() == false) {
        if (audiotrk != null) {
          if (generatedSnd != null) {
            while (audiotrk.getPlaybackHeadPosition() < (generatedSnd.length))             SystemClock.sleep(50);
          }
          audiotrk.release();
        }
        UpdateParameters(false);
        generatedSnd=playque.poll();
        length=generatedSnd.length;
        if (minbufsize < length)         minbufsize=length;
        audiotrk=new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_8BIT,minbufsize,AudioTrack.MODE_STATIC);
        audiotrk.setStereoVolume(2,2);
        audiotrk.write(generatedSnd,0,length);
        audiotrk.play();
      }
    }
  }
}