List of usage examples for android.content Context AUDIO_SERVICE
String AUDIO_SERVICE
To view the source code for android.content Context AUDIO_SERVICE.
Click Source Link
From source file:com.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java
private void microphoneMute(boolean onoff) { AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (!audioManager.isMicrophoneMute() && onoff) { mIsMuted = true;//from www.j a va 2 s . c om audioManager.setMicrophoneMute(onoff); } else if (!onoff) { audioManager.setMicrophoneMute(onoff); } }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
/** * Start playing bell sound and call runWhenDone when playing finishes but only if bell is not muted - returns true when * sound has been started, false otherwise. *//*from w ww . ja v a 2 s .co m*/ private boolean startPlayingSound(ActivityPrefsAccessor activityPrefs, final Runnable runWhenDone) { Uri bellUri = activityPrefs.getSoundUri(context); audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (prefs.isNoSoundOnMusic() && audioManager.isMusicActive()) { MindBell.logDebug("Sound suppressed because setting is no sound on music and music is playing"); return false; } else if (bellUri == null) { MindBell.logDebug("Sound suppressed because no sound has been set"); return false; } else if (prefs.isPauseAudioOnSound()) { int requestResult = audioManager.requestAudioFocus(this, prefs.getAudioStream(), retrieveDurationHint()); if (requestResult == AUDIOFOCUS_REQUEST_FAILED) { MindBell.logDebug( "Sound suppressed because setting is pause audio on sound and request of audio focus failed"); return false; } MindBell.logDebug("Audio focus successfully requested"); } if (prefs.isUseAudioStreamVolumeSetting()) { // we don't care about setting the volume MindBell.logDebug("Start playing sound without touching audio stream volume"); } else { int originalVolume = getAlarmVolume(); int alarmMaxVolume = getAlarmMaxVolume(); if (originalVolume == alarmMaxVolume) { // "someone" else set it to max, so we don't touch it MindBell.logDebug("Start playing sound found originalVolume " + originalVolume + " to be max, alarm volume left untouched"); } else { MindBell.logDebug("Start playing sound found and stored originalVolume " + originalVolume + ", setting alarm volume to max"); setAlarmVolume(alarmMaxVolume); prefs.setOriginalVolume(originalVolume); } } mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(prefs.getAudioStream()); if (!prefs.isUseAudioStreamVolumeSetting()) { // care about setting the volume float bellVolume = activityPrefs.getVolume(); mediaPlayer.setVolume(bellVolume, bellVolume); } try { try { mediaPlayer.setDataSource(context, bellUri); } catch (IOException e) { // probably because of withdrawn permissions, hence use default bell mediaPlayer.setDataSource(context, prefs.getDefaultReminderBellSoundUri(context)); } mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mp) { finishBellSound(); if (runWhenDone != null) { runWhenDone.run(); } } }); mediaPlayer.start(); return true; } catch (IOException e) { Log.e(TAG, "Could not start playing sound: " + e.getMessage(), e); finishBellSound(); return false; } }
From source file:com.commontime.cordova.audio.AudioHandler.java
/** * Set the audio device to be used for playback. * * @param output 1=earpiece, 2=speaker *//*from ww w .ja v a 2s. co m*/ @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."); } }
From source file:im.vector.activity.CallViewActivity.java
private void refreshSpeakerButton() { if ((null != mCall) && mCall.getCallState().equals(IMXCall.CALL_STATE_CONNECTED)) { mSpeakerSelectionView.setVisibility(View.VISIBLE); AudioManager audioManager = (AudioManager) CallViewActivity.this .getSystemService(Context.AUDIO_SERVICE); if (audioManager.isSpeakerphoneOn()) { mSpeakerSelectionView.setImageResource(R.drawable.ic_material_call); } else {// ww w. j a va 2 s. c om mSpeakerSelectionView.setImageResource(R.drawable.ic_material_volume); } CallViewActivity.this.setVolumeControlStream(audioManager.getMode()); } else { mSpeakerSelectionView.setVisibility(View.GONE); } }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private void handleGeofenceTrigger(Intent intent) { LogUtils.LOGD(TAG, "Handling Geofence trigger ..."); HashMap<Integer, String> mapRingerMode = new HashMap<Integer, String>(); mapRingerMode.put(AudioManager.RINGER_MODE_NORMAL, "Normal"); mapRingerMode.put(AudioManager.RINGER_MODE_SILENT, "Silent"); mapRingerMode.put(AudioManager.RINGER_MODE_VIBRATE, "Vibrate"); HashMap<Integer, String> mapTransition = new HashMap<Integer, String>(); mapTransition.put(Geofence.GEOFENCE_TRANSITION_DWELL, "DWELL"); mapTransition.put(Geofence.GEOFENCE_TRANSITION_ENTER, "ENTER"); mapTransition.put(Geofence.GEOFENCE_TRANSITION_EXIT, "EXIT"); GeofencingEvent geoEvent = GeofencingEvent.fromIntent(intent); if (geoEvent.hasError() == false) { LogUtils.LOGD(TAG, "\tgeoEvent has no error."); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager == null) { LogUtils.LOGD(TAG, "\t !!!!! AudioManager == null !!!!!!!"); return; }//from w ww . jav a 2 s. c o m int currringermode = audioManager.getRingerMode(); List<Geofence> geofences = geoEvent.getTriggeringGeofences(); int transition = geoEvent.getGeofenceTransition(); ContentResolver cr = getContentResolver(); //int enterTransition = Config.TEST_BUILD ? Geofence.GEOFENCE_TRANSITION_ENTER : Geofence.GEOFENCE_TRANSITION_DWELL; LogUtils.LOGD(TAG, "\tTransition: " + mapTransition.get(transition)); if (transition == Geofence.GEOFENCE_TRANSITION_DWELL || transition == Geofence.GEOFENCE_TRANSITION_ENTER) { boolean setted = false; for (Geofence geofence : geofences) { long id = Long.parseLong(geofence.getRequestId()); Uri uri = ContentUris.withAppendedId(RulesColumns.CONTENT_ID_URI_BASE, id); Cursor cursor = cr.query(uri, PROJECTS, RulesColumns.ACTIVATED + " = 1", null, null); if (cursor.getCount() != 0) { cursor.moveToFirst(); int setmode = cursor.getInt(cursor.getColumnIndex(RulesColumns.RINGMODE)); if (currringermode == setmode) { LogUtils.LOGD(TAG, "\tringer mode already is in silent or vibrate. we do nothing"); } else { LogUtils.LOGD(TAG, "\tset ringer mode to " + setmode); audioManager.setRingerMode(setmode); PrefUtils.rememberWhoMuted(this, id); //TODO Notify to user ? } setted = true; } else { LogUtils.LOGD(TAG, "\tid = " + id + " trigger, but does not find in database. maybe disabled."); } cursor.close(); cursor = null; if (setted == true) { break; } } } else if (transition == Geofence.GEOFENCE_TRANSITION_EXIT) { for (Geofence geofence : geofences) { long id = Long.parseLong(geofence.getRequestId()); if (id == PrefUtils.getLastSetMuteId(this)) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am != null) { am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } PrefUtils.cleanLastMuteId(this); break; } } } else { LogUtils.LOGD(TAG, "transition is " + transition + " ; != entertransition && !! EXIT"); } } else { PrefUtils.Geofencing(this, false); if (geoEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) { NotificationUserFailed(); ReceUtils.enableReceiver(this, LocationProviderChangedReceiver.class, true); } else { LogUtils.LOGD(TAG, "\tHandle Geofence trigger error. errcode = " + geoEvent.getErrorCode()); } } LogUtils.LOGD(TAG, "Successful Leave handling Geofence trigger."); }
From source file:com.bluros.music.MusicService.java
@Override public void onCreate() { if (D)//from w w w. j a v a2s .com Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) setUpMediaSession(); mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(SLEEP_MODE_STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); filter.addAction(RemoteSelectDialog.REMOTE_START_SCAN); filter.addAction(RemoteSelectDialog.REMOTE_STOP_SCAN); filter.addAction(RemoteSelectDialog.REMOTE_CONNECT); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler); getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:androidx.media.widget.VideoView2.java
public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); mVideoWidth = 0;/*from ww w .j a v a2 s. c o m*/ mVideoHeight = 0; mSpeed = 1.0f; mFallbackSpeed = mSpeed; mSelectedSubtitleTrackIndex = INVALID_TRACK_INDEX; // TODO: add attributes to get this value. mShowControllerIntervalMs = DEFAULT_SHOW_CONTROLLER_INTERVAL_MS; mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mAudioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build(); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); // TODO: try to keep a single child at a time rather than always having both. mTextureView = new VideoTextureView(getContext()); mSurfaceView = new VideoSurfaceView(getContext()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mTextureView.setLayoutParams(params); mSurfaceView.setLayoutParams(params); mTextureView.setSurfaceListener(this); mSurfaceView.setSurfaceListener(this); addView(mTextureView); addView(mSurfaceView); // mSubtitleView = new SubtitleView(getContext()); // mSubtitleView.setLayoutParams(params); // mSubtitleView.setBackgroundColor(0); // addView(mSubtitleView); boolean enableControlView = (attrs == null) || attrs .getAttributeBooleanValue("http://schemas.android.com/apk/res/android", "enableControlView", true); if (enableControlView) { mMediaControlView = new MediaControlView2(getContext()); } mSubtitleEnabled = (attrs == null) || attrs .getAttributeBooleanValue("http://schemas.android.com/apk/res/android", "enableSubtitle", false); // TODO: Choose TextureView when SurfaceView cannot be created. // Choose surface view by default int viewType = (attrs == null) ? VideoView2.VIEW_TYPE_SURFACEVIEW : attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "viewType", VideoView2.VIEW_TYPE_SURFACEVIEW); if (viewType == VideoView2.VIEW_TYPE_SURFACEVIEW) { Log.d(TAG, "viewType attribute is surfaceView."); mTextureView.setVisibility(View.GONE); mSurfaceView.setVisibility(View.VISIBLE); mCurrentView = mSurfaceView; } else if (viewType == VideoView2.VIEW_TYPE_TEXTUREVIEW) { Log.d(TAG, "viewType attribute is textureView."); mTextureView.setVisibility(View.VISIBLE); mSurfaceView.setVisibility(View.GONE); mCurrentView = mTextureView; } // TODO (b/77158231) /* MediaRouteSelector.Builder builder = new MediaRouteSelector.Builder(); builder.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); builder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO); builder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO); mRouteSelector = builder.build(); */ }
From source file:org.simlar.SimlarService.java
@Override public void onCallStateChanged(final String number, final State callState, final int msgId) { if (!mSimlarCallState.updateCallStateChanged(getContact(number).getNameOrNumber(), callState, msgId)) { Log.d(LOGTAG, "SimlarCallState staying the same: " + mSimlarCallState); return;// w ww. j av a 2 s . co m } if (mSimlarCallState.isEmpty()) { Log.e(LOGTAG, "SimlarCallState is empty: " + mSimlarCallState); return; } Log.i(LOGTAG, "SimlarCallState updated: " + mSimlarCallState); if (mSimlarCallState.isRinging()) { mVibratorThread.start(); mRingtoneThread.start(); } else { mVibratorThread.stop(); mRingtoneThread.stop(); } // make sure WLAN is not suspended while calling if (mSimlarCallState.isNewCall()) { notifySimlarStatusChanged(SimlarStatus.ONGOING_CALL); acquireWakeLock(); acquireWifiLock(); if (((AudioManager) getSystemService(Context.AUDIO_SERVICE)).isMusicActive()) { sendBroadcast(new Intent("com.android.music.musicservicecommand.pause")); mResumeMusicAfterCall = true; } if (mSimlarCallState.isRinging()) { Log.i(LOGTAG, "starting RingingActivity"); startActivity(new Intent(SimlarService.this, RingingActivity.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)); } else { Log.i(LOGTAG, "starting CallActivity"); startActivity(new Intent(SimlarService.this, CallActivity.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)); } } if (mSimlarCallState.isEndedCall()) { notifySimlarStatusChanged(SimlarStatus.ONLINE); releaseWakeLock(); releaseWifiLock(); if (mResumeMusicAfterCall) { sendBroadcast(new Intent("com.android.music.musicservicecommand.togglepause")); mResumeMusicAfterCall = false; } } SimlarServiceBroadcast.sendSimlarCallStateChanged(this); }
From source file:com.saulcintero.moveon.services.MoveOnService.java
@Override public void onCreate() { super.onCreate(); mContext = getApplicationContext();/*from w w w . j av a 2 s. c o m*/ prefs = PreferenceManager.getDefaultSharedPreferences(mContext); tts = TextToSpeechUtils.getInstance(); tts.initTTS(mContext); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); showNotification(); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mHandler = new Handler(); mHandler.postDelayed(mRunnable, 0); acquireWakeLock(); mStepDetector = new StepDetector(); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); registerDetector(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mComponentName = new ComponentName(getPackageName(), MediaButtonEventReceiver.class.getName()); mSettingsObserver = new SettingsObserver(this, mContext, mComponentName); mContentResolver = getContentResolver(); mContentResolver.registerContentObserver(Settings.System.getUriFor(MEDIA_BUTTON_RECEIVER), false, mSettingsObserver); registerMediaButtonReceiver(); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); registerReceiver(mReceiverScreenOff, filter); IntentFilter filter2 = new IntentFilter("android.intent.action.ACTION_SCREEN_REFRESH"); registerReceiver(mReceiverRefreshScreenPreferences, filter2); IntentFilter filter3 = new IntentFilter("android.intent.action.ACTION_SAY_PRACTICE_INFORMATION"); registerReceiver(mReceiverSayInformation, filter3); IntentFilter filter4 = new IntentFilter("android.intent.action.STEP_COUNTER"); registerReceiver(mReceiverStepCounter, filter4); IntentFilter filter5 = new IntentFilter("android.intent.action.BEAT_COUNTER"); registerReceiver(mReceiverBeatCounter, filter5); IntentFilter filter6 = new IntentFilter("android.intent.action.EMPTY_SENSOR_MANAGER"); registerReceiver(mReceiverEmptySensorManager, filter6); IntentFilter filter7 = new IntentFilter("android.intent.action.ACTION_PLAY_SOUND"); registerReceiver(mReceiverPlaySound, filter7); IntentFilter filter8 = new IntentFilter("android.intent.action.ACTION_REFRESH_SENSITIVITY"); registerReceiver(mReceiverRefreshSensitivity, filter8); IntentFilter filter9 = new IntentFilter("android.intent.action.CADENCE"); registerReceiver(mReceiverCadence, filter9); IntentFilter filter10 = new IntentFilter("android.intent.action.REGISTER_MEDIA_BUTTON_STATUS"); registerReceiver(mReceiverRegisterMediaButton, filter10); IntentFilter filter11 = new IntentFilter("android.intent.action.UNREGISTER_MEDIA_BUTTON_STATUS"); registerReceiver(mReceiverUnregisterMediaButton, filter11); mStepCounter = new StepCounter(mContext); mStepDetector.addStepListener(mStepCounter); mTimeManager = new TimeManager(mContext); mDistanceManager = new DistanceManager(mContext); locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); listener = new mGpsListener(); locListener = new mLocationListener(); locMgr.addGpsStatusListener(listener); locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_UPDATE_TIME_INTERVAL, GPS_UPDATE_DISTANCE_INTERVAL, locListener); }
From source file:com.commontime.cordova.audio.AudioHandler.java
/** * Get the audio device to be used for playback. * * @return 1=earpiece, 2=speaker *//*from w w w . j av a2s . co m*/ @SuppressWarnings("deprecation") public int getAudioOutputDevice() { AudioManager audiMgr = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE); if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) { return 1; } else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER) { return 2; } else { return -1; } }