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.example.android.bangla.PhrasesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.word_list, container, false); // Create and setup the AudioManager to request audio focus mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); // Create a list of words final ArrayList<Word> words = new ArrayList<Word>(); words.add(new Word(R.string.phrase_where_are_you_going, R.string.bangla_phrase_where_are_you_going, R.raw.phrase_where_are_you_going)); words.add(new Word(R.string.phrase_what_is_your_name, R.string.bangla_phrase_what_is_your_name, R.raw.phrase_what_is_your_name)); words.add(new Word(R.string.phrase_my_name_is, R.string.bangla_phrase_my_name_is, R.raw.phrase_my_name)); words.add(new Word(R.string.phrase_how_are_you_feeling, R.string.bangla_phrase_how_are_you_feeling, R.raw.phrase_how_are_you_feeling)); words.add(new Word(R.string.phrase_im_feeling_good, R.string.bangla_phrase_im_feeling_good, R.raw.phrase_i_am_feeling_good)); words.add(new Word(R.string.phrase_are_you_coming, R.string.bangla_phrase_are_you_coming, R.raw.phrase_are_you_coming)); words.add(new Word(R.string.phrase_yes_im_coming, R.string.bangla_phrase_yes_im_coming, R.raw.phrase_yes_i_am_coming)); words.add(new Word(R.string.phrase_im_coming, R.string.bangla_phrase_im_coming, R.raw.phrase_i_am_coming)); words.add(new Word(R.string.phrase_lets_go, R.string.bangla_phrase_lets_go, R.raw.phrase_lets_go)); words.add(new Word(R.string.phrase_come_here, R.string.bangla_phrase_come_here, R.raw.phrase_come_here)); // Create an WordAdapter whose data source is a list of {@link Word}s. The // adapter knows how to create list items for each item in the list. WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_phrases); ListView listView = (ListView) rootView.findViewById(R.id.list); listView.setAdapter(adapter);/*from w w w.jav a 2 s. c o m*/ // Set a click listener to play the audio when the list item is clicked on listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { releaseMediaPlayer(); Word word = words.get(position); int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { mMediaPlayer = MediaPlayer.create(getActivity(), word.getAudioResourceId()); mMediaPlayer.start(); mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); return rootView; }
From source file:com.morphoss.jumble.frontend.SettingsActivity.java
/** * This methods controls the audio//from w ww . j a v a2s . c om */ private void initControls() { setVolumeControlStream(AudioManager.STREAM_MUSIC); setContentView(R.layout.activity_settings); try { volumeSeekbar = (SeekBar) findViewById(R.id.seekBar1); audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); volumeSeekbar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)); volumeSeekbar.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)); volumeSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar bar) { } @Override public void onStartTrackingTouch(SeekBar bar) { } @Override public void onProgressChanged(SeekBar bar, int paramInt, boolean paramBoolean) { audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, paramInt, 0); } }); btnreset = (Button) findViewById(R.id.reset); btnreset.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { deleteWords(); deleteKnownCategories(); } }); enFlag = (ImageView) findViewById(R.id.enFlag); enFlag.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setLanguage("en"); } }); frFlag = (ImageView) findViewById(R.id.frFlag); frFlag.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setLanguage("fr"); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.kaliturin.blacklist.utils.Notifications.java
private static void notify(Context context, String title, String message, String ticker, @DrawableRes int icon, String action, Uri ringtone, boolean vibration) { // turn off sound and vibration if phone is in silent mode AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: ringtone = null;//from ww w .j a va2 s .c om vibration = false; break; case AudioManager.RINGER_MODE_VIBRATE: ringtone = null; break; case AudioManager.RINGER_MODE_NORMAL: break; } // pending intent for activating app on click in status bar Intent intent = new Intent(context, MainActivity.class); intent.setAction(action); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); // build notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentIntent(pendingIntent); builder.setContentTitle(title); builder.setTicker(ticker); builder.setContentText(message); builder.setSmallIcon(icon); builder.setColor(getColor(context, R.attr.colorAccent)); builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)); builder.setPriority(PRIORITY_MAX); builder.setAutoCancel(true); if (ringtone != null) { builder.setSound(ringtone); } if (vibration) { builder.setVibrate(new long[] { 0, 300, 300, 300 }); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
From source file:com.reallynourl.nourl.fmpfoldermusicplayer.backend.MediaService.java
private boolean requestAudioFocus() { AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { mIsPreparedToPlay = false;//from ww w . ja v a 2 s . c om Toast.makeText(getApplicationContext(), "Failed to get audio focus. Not starting playback.", Toast.LENGTH_LONG).show(); if (mMediaPlayer != null) { mMediaPlayer.stop(); } return false; } else { mMediaPlayer.setVolume(1.0f, 1.0f); } return true; }
From source file:com.google.android.marvin.mytalkback.ProcessorVolumeStream.java
@SuppressWarnings("deprecation") public ProcessorVolumeStream(TalkBackService service) { mContext = service;//from w w w .ja va 2 s . c om mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE); mCursorController = service.getCursorController(); mLongPressHandler = new LongPressHandler(this); final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, WL_TAG); }
From source file:org.wso2.emm.agent.AlertActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_alert); btnOK = (Button) findViewById(R.id.btnOK); txtMessage = (TextView) findViewById(R.id.txtMessage); txtMessageTitle = (TextView) findViewById(R.id.txtMessageTitle); horizontalLine = findViewById(R.id.hLine); deviceInfo = new DeviceInfo(this); context = AlertActivity.this.getApplicationContext(); this.resources = context.getResources(); audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(getResources().getString(R.string.intent_extra_message_title))) { messageTitle = extras.getString(getResources().getString(R.string.intent_extra_message_title)); } else {/*from w w w .j ava2 s . co m*/ messageTitle = context.getResources().getString(R.string.txt_message_title); } if (extras.containsKey(getResources().getString(R.string.intent_extra_message_text))) { messageText = extras.getString(getResources().getString(R.string.intent_extra_message_text)); } else { messageText = context.getResources().getString(R.string.txt_message); } type = extras.getString(getResources().getString(R.string.intent_extra_type)); if (DEVICE_OPERATION_RING.equalsIgnoreCase(type)) { startRing(); } else if (Constants.Operation.VPN.equalsIgnoreCase(type)) { payload = extras.getString(getResources().getString(R.string.intent_extra_payload)); } } if (extras.containsKey(getResources().getString(R.string.intent_extra_operation_id))) { operationId = extras.getInt(getResources().getString(R.string.intent_extra_operation_id)); } txtMessageTitle.setText(messageTitle); txtMessage.setText(messageText); btnOK.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (DEVICE_OPERATION_RING.equalsIgnoreCase(type)) { stopRing(); AlertActivity.this.finish(); } else if (OPEN_LOCK_SETTINGS.equalsIgnoreCase(type)) { openPasswordSettings(); AlertActivity.this.finish(); } else if (Constants.Operation.VPN.equalsIgnoreCase(type)) { startVpn(); } else { updateNotification(operationId); AlertActivity.this.finish(); } } }); }
From source file:hyplink.net.pot.GameActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // load logic grid = new Grid(); // load controller controller = new SwipeController(this); // load data/*w w w . jav a 2s . co m*/ gamePreferences = new GamePreferences(this); // load sound audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0); // load view setOrientation(); StartAppSDK.init(this, "108710732", "208747074", true); StartAppAd.showSplash(this, savedInstanceState); setContentView(R.layout.game); loadView(); // load animation animation = AnimationUtils.loadAnimation(this, R.anim.cell_animation); }
From source file:gstb.fd.eofficial.oa.im.widget.chatrow.EaseChatRowVoicePlayClickListener.java
public void playVoice(String filePath) { Log.e("sssssss", "sssssssssssssss"); if (!(new File(filePath).exists())) { return;/*from ww w . j a v a 2 s . com*/ } // playMsgId = message.getMsgId(); AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); mediaPlayer = new MediaPlayer(); // if (EaseUI.getInstance().getSettingsProvider().isSpeakerOpened()) { audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setSpeakerphoneOn(true); mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); // } else { // audioManager.setSpeakerphoneOn(false);// // ?Earpiece??? // audioManager.setMode(AudioManager.MODE_IN_CALL); // mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); // } try { mediaPlayer.setDataSource(filePath); mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mediaPlayer.release(); mediaPlayer = null; stopPlayVoice(); // stop animation } }); isPlaying = true; currentPlayListener = this; mediaPlayer.start(); showAnimation(); // ? if (message.direct() == EMMessage.Direct.RECEIVE) { // if (!message.isAcked() && chatType == EMMessage.ChatType.Chat) { // // ?? //// EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); // } if (!message.isListened() && iv_read_status != null && iv_read_status.getVisibility() == View.VISIBLE) { // ???? iv_read_status.setVisibility(View.INVISIBLE); message.setListened(true); MessageDao.instance(activity).updateListen(message.getMsgId()); // EMClient.getInstance().chatManager().setMessageListened(message); } } } catch (Exception e) { System.out.println(); } }
From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java
/** * Handle the tap event from the touchpad. */// ww w. j av a 2s . c o m @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { // Handle tap events. case KeyEvent.KEYCODE_DPAD_CENTER: //case KeyEvent.KEYCODE_ENTER: AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); _speech.speak("The weather is" + mCurrent + "Fahrenheit and" + mDescription, TextToSpeech.QUEUE_FLUSH, null); Bitmap bitmap = loadImageFromURL("http://openweathermap.org/img/w/10d.png"); _weatherIconImageView.setImageBitmap(bitmap); return true; default: return super.onKeyDown(keyCode, event); } }
From source file:com.duongnx.ndk.examples.activities.NativeAudioActivity.java
/** * Called when the activity is first created. *///from w w w .j a v a2s . co m @Override @TargetApi(17) protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_native_audio); setTitle(Defines.NATIVE_AUDIO); assetManager = getAssets(); // initialize native audio system createEngine(); int sampleRate = 0; int bufSize = 0; /* * retrieve fast audio path sample rate and buf size; if we have it, we pass to native * side to create a player with fast audio enabled [ fast audio == low latency audio ]; * IF we do not have a fast audio path, we pass 0 for sampleRate, which will force native * side to pick up the 8Khz sample rate. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); String nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); sampleRate = Integer.parseInt(nativeParam); nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); bufSize = Integer.parseInt(nativeParam); } createBufferQueueAudioPlayer(sampleRate, bufSize); // initialize URI spinner Spinner uriSpinner = (Spinner) findViewById(R.id.uri_spinner); ArrayAdapter<CharSequence> uriAdapter = ArrayAdapter.createFromResource(this, R.array.uri_spinner_array, android.R.layout.simple_spinner_item); uriAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); uriSpinner.setAdapter(uriAdapter); uriSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { URI = parent.getItemAtPosition(pos).toString(); } public void onNothingSelected(AdapterView parent) { URI = null; } }); // initialize button click handlers ((Button) findViewById(R.id.hello)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_HELLO, 5); } }); ((Button) findViewById(R.id.android)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_ANDROID, 7); } }); ((Button) findViewById(R.id.sawtooth)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_SAWTOOTH, 1); } }); ((Button) findViewById(R.id.reverb)).setOnClickListener(new OnClickListener() { boolean enabled = false; public void onClick(View view) { enabled = !enabled; if (!enableReverb(enabled)) { enabled = !enabled; } } }); ((Button) findViewById(R.id.embedded_soundtrack)).setOnClickListener(new OnClickListener() { boolean created = false; public void onClick(View view) { if (!created) { created = createAssetAudioPlayer(assetManager, "background.mp3"); } if (created) { isPlayingAsset = !isPlayingAsset; setPlayingAssetAudioPlayer(isPlayingAsset); } } }); // native uriPlayer is broken in android 21 and over, internal bug id: b/29321867 // will re-open after it is fixed in later OSes if (Build.VERSION.SDK_INT <= 19) { ((Button) findViewById(R.id.uri_soundtrack)).setOnClickListener(new OnClickListener() { boolean created = false; public void onClick(View view) { if (!created && URI != null) { created = createUriAudioPlayer(URI); } } }); ((Button) findViewById(R.id.pause_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { setPlayingUriAudioPlayer(false); } }); ((Button) findViewById(R.id.play_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { setPlayingUriAudioPlayer(true); } }); ((Button) findViewById(R.id.loop_uri)).setOnClickListener(new OnClickListener() { boolean isLooping = false; public void onClick(View view) { isLooping = !isLooping; setLoopingUriAudioPlayer(isLooping); } }); ((Button) findViewById(R.id.mute_left_uri)).setOnClickListener(new OnClickListener() { boolean muted = false; public void onClick(View view) { muted = !muted; setChannelMuteUriAudioPlayer(0, muted); } }); ((Button) findViewById(R.id.mute_right_uri)).setOnClickListener(new OnClickListener() { boolean muted = false; public void onClick(View view) { muted = !muted; setChannelMuteUriAudioPlayer(1, muted); } }); ((Button) findViewById(R.id.solo_left_uri)).setOnClickListener(new OnClickListener() { boolean soloed = false; public void onClick(View view) { soloed = !soloed; setChannelSoloUriAudioPlayer(0, soloed); } }); ((Button) findViewById(R.id.solo_right_uri)).setOnClickListener(new OnClickListener() { boolean soloed = false; public void onClick(View view) { soloed = !soloed; setChannelSoloUriAudioPlayer(1, soloed); } }); ((Button) findViewById(R.id.mute_uri)).setOnClickListener(new OnClickListener() { boolean muted = false; public void onClick(View view) { muted = !muted; setMuteUriAudioPlayer(muted); } }); ((Button) findViewById(R.id.enable_stereo_position_uri)).setOnClickListener(new OnClickListener() { boolean enabled = false; public void onClick(View view) { enabled = !enabled; enableStereoPositionUriAudioPlayer(enabled); } }); ((Button) findViewById(R.id.channels_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { if (numChannelsUri == 0) { numChannelsUri = getNumChannelsUriAudioPlayer(); } Toast.makeText(NativeAudioActivity.this, "Channels: " + numChannelsUri, Toast.LENGTH_SHORT) .show(); } }); ((SeekBar) findViewById(R.id.volume_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() { int lastProgress = 100; public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) { throw new AssertionError(); } lastProgress = progress; } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { int attenuation = 100 - lastProgress; int millibel = attenuation * -50; setVolumeUriAudioPlayer(millibel); } }); ((SeekBar) findViewById(R.id.pan_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() { int lastProgress = 100; public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) { throw new AssertionError(); } lastProgress = progress; } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { int permille = (lastProgress - 50) * 20; setStereoPositionUriAudioPlayer(permille); } }); } else { int[] uriIds = { R.id.uri_soundtrack, R.id.pause_uri, R.id.play_uri, R.id.loop_uri, R.id.mute_left_uri, R.id.mute_right_uri, R.id.solo_left_uri, R.id.solo_right_uri, R.id.mute_uri, R.id.enable_stereo_position_uri, R.id.channels_uri, R.id.volume_uri, R.id.pan_uri, R.id.uri_spinner, }; for (int id : uriIds) findViewById(id).setVisibility(View.GONE); } ((Button) findViewById(R.id.record)).setOnClickListener(new OnClickListener() { public void onClick(View view) { int status = ActivityCompat.checkSelfPermission(NativeAudioActivity.this, Manifest.permission.RECORD_AUDIO); if (status != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(NativeAudioActivity.this, new String[] { Manifest.permission.RECORD_AUDIO }, AUDIO_ECHO_REQUEST); return; } recordAudio(); } }); ((Button) findViewById(R.id.playback)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_PLAYBACK, 3); } }); }