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:dk.dr.radio.afspilning.Afspiller.java
/** * Responding to the loss of audio focus *//*from w ww .j a v a 2 s .com*/ @SuppressLint("NewApi") private OnAudioFocusChangeListener getOnAudioFocusChangeListener() { if (onAudioFocusChangeListener == null) onAudioFocusChangeListener = new OnAudioFocusChangeListener() { //private int lydstyreFrDuck = -1; @TargetApi(Build.VERSION_CODES.FROYO) public void onAudioFocusChange(int focusChange) { Log.d("onAudioFocusChange " + focusChange); AudioManager am = (AudioManager) App.instans.getSystemService(Context.AUDIO_SERVICE); switch (focusChange) { // Kommer ved f.eks. en SMS eller taleinstruktion i Google Maps case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK): Log.d("JPER duck"); if (afspillerstatus != Status.STOPPET) { // Vi 'dukker' lyden mens den vigtigere lyd hres // St lydstyrken ned til en 1/3-del //lydstyreFrDuck = am.getStreamVolume(AudioManager.STREAM_MUSIC); //am.setStreamVolume(AudioManager.STREAM_MUSIC, (lydstyreFrDuck + 2) / 3, 0); mediaPlayer.setVolume(0.1f, 0.1f); // logaritmisk skala - 0.1 svarer til 1/3-del } break; // Dette sker ved f.eks. opkald case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT): Log.d("JPER pause"); if (afspillerstatus != Status.STOPPET) { pauseAfspilning(); // stter afspilningPPause=false if (afspillerlyde) afspillerlyd.stop.start(); afspilningPPause = true; } break; // Dette sker hvis en anden app med lyd startes, f.eks. et spil case (AudioManager.AUDIOFOCUS_LOSS): Log.d("JPER stop"); stopAfspilning(); am.abandonAudioFocus(this); break; // Dette sker nr opkaldet er slut og ved f.eks. opkald case (AudioManager.AUDIOFOCUS_GAIN): Log.d("JPER Gain"); if (afspillerstatus == Status.STOPPET) { if (afspilningPPause) startAfspilningIntern(); } else { // Genskab lydstyrke fr den blev dukket mediaPlayer.setVolume(1f, 1f); //if (lydstyreFrDuck > 0) { // am.setStreamVolume(AudioManager.STREAM_MUSIC, lydstyreFrDuck, 0); //} // Genstart ikke afspilning, der spilles allerede! //startAfspilningIntern(); } } } }; return (OnAudioFocusChangeListener) onAudioFocusChangeListener; }
From source file:com.example.recordvoice.service.RecordService.java
private void startRecording(Intent intent) { Log.d(Constants.TAG, "RecordService startRecording"); boolean exception = false; // try { ///*from www . j a v a 2 s. co m*/ // Log.d(Constants.TAG, "RecordService recorderStarted"); // } catch (IllegalStateException e) { // Log.e(Constants.TAG, "IllegalStateException"); // e.printStackTrace(); // exception = true; // } catch (IOException e) { // Log.e(Constants.TAG, "IOException"); // e.printStackTrace(); // exception = true; // } catch (Exception e) { // Log.e(Constants.TAG, "Exception"); // e.printStackTrace(); // exception = true; // } if (!startMediaRecorder(MediaRecorder.AudioSource.VOICE_CALL)) { if (startMediaRecorder(MediaRecorder.AudioSource.MIC)) { audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(3, audioManager.getStreamMaxVolume(3), 0); Intent intent1 = new Intent(getBaseContext(), DialogConfirmActivity.class); intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent1); } else { exception = true; } } if (exception) { terminateAndEraseFile(); } if (recording) { Toast toast = Toast.makeText(this, this.getString(R.string.receiver_start_call), Toast.LENGTH_SHORT); toast.show(); } else { Toast toast = Toast.makeText(this, this.getString(R.string.record_impossible), Toast.LENGTH_LONG); toast.show(); } }
From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java
private void initGestureScanner(final Context context) { slop = ViewConfiguration.get(context).getScaledTouchSlop(); screenWidth = ScreenUtil.getScreenWidth(context); gestureDetector = new GestureDetectorCompat(context, new LilyGestureListener()); setOnTouchListener(new OnTouchListener() { @Override// w ww. j ava 2 s. c o m public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_UP: if (adjustProgress) { adjustProgress = false; int newPosition = (int) (getCurrentPosition() + scrollX / screenWidth * 1000 * 90); if (newPosition < 0) { seekTo(0); } else { seekTo(newPosition); } start(); mAdjustProgressView.setVisibility(GONE); if (mMediaController.isShowing()) { showAllBoard(); } } scrollX = 0; scrollY = 0; level = 0; adjustVolume = false; adjustBrightness = false; break; case MotionEvent.ACTION_DOWN: lastX = motionEvent.getRawX(); lastY = motionEvent.getRawY(); if (motionEvent.getRawX() > screenWidth / 2 + 150) { adjustVolume = true; adjustBrightness = false; } else if (motionEvent.getRawX() < screenWidth / 2 - 150) { adjustBrightness = true; adjustVolume = false; } break; case MotionEvent.ACTION_MOVE: if (adjustProgress) { break; } if (Math.abs(motionEvent.getRawY() - lastY) > Math.abs(motionEvent.getRawX() - lastX)) { AudioManager audioManager = (AudioManager) mAppContext .getSystemService(Context.AUDIO_SERVICE); if (motionEvent.getRawY() > lastY) { level += motionEvent.getRawY() - lastY; if (level > slop) { if (adjustVolume) { audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); } else if (adjustBrightness) { float brightness = ScreenUtil.getScreenBrightness((Activity) context); if (brightness <= 0.1f) { ScreenUtil.setScreenBrightness((Activity) context, 0.0f); } else { ScreenUtil.setScreenBrightness((Activity) context, ScreenUtil.getScreenBrightness((Activity) context) - 0.1f); } } level = 0; } } else { level += lastY - motionEvent.getRawY(); if (level > slop) { if (adjustVolume) { audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); } else if (adjustBrightness) { float brightness = ScreenUtil.getScreenBrightness((Activity) context); if (brightness >= 0.9f) { ScreenUtil.setScreenBrightness((Activity) context, 1.0f); } else { ScreenUtil.setScreenBrightness((Activity) context, ScreenUtil.getScreenBrightness((Activity) context) + 0.1f); } } level = 0; } } } lastX = motionEvent.getRawX(); lastY = motionEvent.getRawY(); break; } return gestureDetector.onTouchEvent(motionEvent); } }); }
From source file:org.protocoderrunner.apprunner.AppRunnerFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); MLog.d(TAG, "onActivityCreated"); String toolbarName = ""; if (mProjectFolder.equals("examples")) { toolbarName = "example > " + mProjectName; } else {//from w w w.j a v a2 s .c om toolbarName = mProjectName; } mActivity.setToolBar(toolbarName, null, null); //catch errors and send them to the webIDE or the app console AppRunnerInterpreter.InterpreterInfo appRunnerCb = new AppRunnerInterpreter.InterpreterInfo() { @Override public void onError(String message) { MLog.d(TAG, "error " + message); showConsole(message); // send to web ide JSONObject obj = new JSONObject(); try { obj.put("type", "error"); obj.put("values", message); //MLog.d(TAG, "error " + obj.toString(2)); IDEcommunication.getInstance(mActivity).send(obj); } catch (JSONException er1) { er1.printStackTrace(); } } }; interp.addListener(appRunnerCb); // load the libraries MLog.d(TAG, "loaded preloaded script" + mIntentPrefixScript); interp.eval(AppRunnerInterpreter.SCRIPT_PREFIX); if (!mIntentPrefixScript.isEmpty()) interp.eval(mIntentPrefixScript); // run the script if (null != mScript) { interp.eval(mScript, mProjectName); } //can accept intent code if no project is loaded if (!mIsProjectLoaded) { interp.eval(mIntentCode); } //script postfix if (!mIntentPostfixScript.isEmpty()) interp.eval(mIntentPostfixScript); interp.eval(AppRunnerInterpreter.SCRIPT_POSTFIX); //call the javascript method setup interp.callJsFunction("setup"); // TODO fix actionbar color //if (mActivity.mActionBarSet == false) { // mActivity.setToolBar(null, , getResources().getColor(R.color.white)); //} // Call the onCreate JavaScript function. interp.callJsFunction("onCreate", savedInstanceState); //audio AudioManager audio = (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE); int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); mActivity.setVolumeControlStream(AudioManager.STREAM_MUSIC); //nfc mActivity.initializeNFC(); //file observer will notifify project file changes startFileObserver(); // send ready to the webIDE //TODO this is gone ?! }
From source file:com.Duo.music.player.Services.AudioPlaybackService.java
/** * Prepares the MediaPlayer objects for first use * and starts the service. The workflow of the entire * service starts here./*from w w w. j av a2 s .c om*/ * * @param intent Calling intent. * @param flags Service flags. * @param startId Service start ID. */ @SuppressLint("NewApi") @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); //Context. mContext = getApplicationContext(); mService = this; mHandler = new Handler(); mApp = (Common) getApplicationContext(); mApp.setService((AudioPlaybackService) this); mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); //Initialize Google Analytics. //initGoogleAnalytics(); //Initialize the MediaPlayer objects. initMediaPlayers(); //Time to play nice with other music players (and audio apps) and request audio focus. mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mAudioManagerHelper = new AudioManagerHelper(); // Request audio focus for playback mAudioManagerHelper.setHasAudioFocus(requestAudioFocus()); //Grab the crossfade duration for this session. mCrossfadeDuration = mApp.getCrossfadeDuration(); //Initialize audio effects (equalizer, virtualizer, bass boost) for this session. initAudioFX(); mMediaButtonReceiverComponent = new ComponentName(this.getPackageName(), HeadsetButtonsReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (mApp.getSharedPreferences().getBoolean(Common.SHOW_LOCKSCREEN_CONTROLS, true) == true) { initRemoteControlClient(); } mApp.getPlaybackKickstarter().setBuildCursorListener(buildCursorListener); //The service has been successfully started. setPrepareServiceListener(mApp.getPlaybackKickstarter()); getPrepareServiceListener().onServiceRunning(this); return START_STICKY; }
From source file:com.levien.audiobuffersize.AudioBufferSize.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) void getJbMr1Params(AudioParams params) { AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); String sr = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); String bs = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); params.confident = true;/* w w w . j ava2s. c o m*/ params.sampleRate = Integer.parseInt(sr); params.bufferSize = Integer.parseInt(bs); logUI("from platform: " + params); }
From source file:com.luhuiguo.cordova.voice.VoiceHandler.java
/** * Set the voice device to be used for playback. * * @param output 1=earpiece, 2=speaker */// ww w . ja va 2s . c om public void setVoiceOutputDevice(int output) { AudioManager audiMgr = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE); if (output == 2) { audiMgr.setSpeakerphoneOn(true); } else if (output == 1) { audiMgr.setSpeakerphoneOn(false); } else { System.out.println("VoiceHandler.setVoiceOutputDevice() Error: Unknown output device."); } }
From source file:org.skt.runtime.additionalapis.AudioHandler.java
/** * Set the audio device to be used for playback. * * @param output 1=earpiece, 2=speaker *//*w w w . j a v a 2 s.c om*/ @SuppressWarnings("deprecation") public void setAudioOutputDevice(int output) { AudioManager audiMgr = (AudioManager) this.ctx.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:com.smc.tw.waltz.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (DEBUG)/*www .j ava 2 s .c o m*/ Log.d(TAG, "onCreate"); overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out); super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_main); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG); mPreferences = PreferenceManager.getDefaultSharedPreferences(this); mFragmentManager = getSupportFragmentManager(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mAudioRecordBufferSize = 5600;//AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT)*10; mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, mAudioRecordBufferSize); mNotifyChannelList = new ArrayList<String>(); setupLayout(); if (savedInstanceState != null) { mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); } // mRegistrationBroadcastReceiver = new BroadcastReceiver() { // @Override // public void onReceive(Context context, Intent intent) { // // // checking for type intent filter // if (intent.getAction().equals(MainApplication.REGISTRATION_COMPLETE)) { // // gcm successfully registered // // now subscribe to `global` topic to receive app wide notifications // String token = intent.getStringExtra("token"); // // //Toast.makeText(getApplicationContext(), "GCM registration token: " + token, Toast.LENGTH_LONG).show(); // // } else if (intent.getAction().equals(MainApplication.SENT_TOKEN_TO_SERVER)) { // // gcm registration id is stored in our server's MySQL // // Toast.makeText(getApplicationContext(), "GCM registration token is stored in server!", Toast.LENGTH_LONG).show(); // // } else if (intent.getAction().equals(MainApplication.PUSH_NOTIFICATION)) { // // new push notification is received // // Toast.makeText(getApplicationContext(), "Push notification is received!", Toast.LENGTH_LONG).show(); // } // } // }; // if (checkPlayServices()) { registerGCM(); } }
From source file:com.android.nobug.view.pattern.PatternView.java
public PatternView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternView, defStyleAttr, 0); mRowCount = a.getInteger(R.styleable.PatternView_rowCount, PATTERN_SIZE_DEFAULT); mColumnCount = a.getInteger(R.styleable.PatternView_columnCount, PATTERN_SIZE_DEFAULT); final String aspect = a.getString(R.styleable.PatternView_aspect); if ("square".equals(aspect)) { mAspect = ASPECT_SQUARE;//from www. j av a2 s . com } else if ("lock_width".equals(aspect)) { mAspect = ASPECT_LOCK_WIDTH; } else if ("lock_height".equals(aspect)) { mAspect = ASPECT_LOCK_HEIGHT; } else { mAspect = ASPECT_SQUARE; } setClickable(true); mPathPaint.setAntiAlias(true); mPathPaint.setDither(true); mRegularColor = a.getColor(R.styleable.PatternView_regularColor, mRegularColor); mErrorColor = a.getColor(R.styleable.PatternView_errorColor, mErrorColor); mSuccessColor = a.getColor(R.styleable.PatternView_successColor, mSuccessColor); a.recycle(); mPathPaint.setStyle(Paint.Style.STROKE); mPathPaint.setStrokeJoin(Paint.Join.ROUND); mPathPaint.setStrokeCap(Paint.Cap.ROUND); mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width); mPathPaint.setStrokeWidth(mPathWidth); mDotSize = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size); mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated); mPaint.setAntiAlias(true); mPaint.setDither(true); updatePatternSize(); mFastOutSlowInInterpolator = new FastOutSlowInInterpolator(); mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator(); mExploreByTouchHelper = new PatternExploreByTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper); mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); }