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.peppermint.peppermint.ui.AnswerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mGlowpad = (GlowPadWrapper) inflater.inflate(R.layout.answer_fragment, container, false); vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); myAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); Uri ring = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); r = RingtoneManager.getRingtone(getContext(), ring); r.play();/*w w w . j a v a 2s . com*/ long[] pattern = { 100, 1000, 2000, 1000, 2000, 1000, 2000 }; vibrator.vibrate(pattern, 2); LOGD(TAG, " Creating view for answer fragment"); LOGD(TAG, "Created from activity" + getActivity()); mGlowpad.setAnswerListener(this); mGlowpad.startPing(); callActivity = (CallActivity) getContext(); return mGlowpad; }
From source file:de.questmaster.fatremote.fragments.RemoteFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /* start audio */ mAudioManager = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE); mAudioManager.loadSoundEffects();//from w w w. j av a 2s. co m /* read Settings */ mSettings.readSettings(c); /* setup onClickListener for remote buttons */ ((ImageView) c.findViewById(R.id.remote_button_power)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_up)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_home)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_left)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_ok)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_right)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_back)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_down)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_info)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.textButton)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_rew)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_menu)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_fwd)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_prev)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_play)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_next)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_volup)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_stop)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_zoomup)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_voldown)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_mute)).setOnClickListener(this); ((ImageView) c.findViewById(R.id.remote_button_zoomdown)).setOnClickListener(this); /* setup key listener */ EditText text = (EditText) c.findViewById(R.id.enterText); text.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { hideKeyboard(); return true; } return false; } }); text.addTextChangedListener(determineKeyboardTextChangedListener()); text.setFocusable(true); // check if WIFI available if (!NetworkProxy.getInstance(c).isWifiEnabled()) { Toast.makeText(c, R.string.app_err_enwifi, Toast.LENGTH_LONG).show(); } }
From source file:com.example.android.gft.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 {@link 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.miwok_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.miwok_phrase_what_is_your_name, R.raw.phrase_what_is_your_name)); words.add(new Word(R.string.phrase_my_name_is, R.string.miwok_phrase_my_name_is, R.raw.phrase_my_name_is)); words.add(new Word(R.string.phrase_how_are_you_feeling, R.string.miwok_phrase_how_are_you_feeling, R.raw.phrase_how_are_you_feeling)); words.add(new Word(R.string.phrase_im_feeling_good, R.string.miwok_phrase_im_feeling_good, R.raw.phrase_im_feeling_good)); words.add(new Word(R.string.phrase_are_you_coming, R.string.miwok_phrase_are_you_coming, R.raw.phrase_are_you_coming)); words.add(new Word(R.string.phrase_yes_im_coming, R.string.miwok_phrase_yes_im_coming, R.raw.phrase_yes_im_coming)); words.add(new Word(R.string.phrase_im_coming, R.string.miwok_phrase_im_coming, R.raw.phrase_im_coming)); words.add(new Word(R.string.phrase_lets_go, R.string.miwok_phrase_lets_go, R.raw.phrase_lets_go)); words.add(new Word(R.string.phrase_come_here, R.string.miwok_phrase_come_here, R.raw.phrase_come_here)); // Create an {@link 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); // Find the {@link ListView} object in the view hierarchy of the {@link Activity}. // There should be a {@link ListView} with the view ID called list, which is declared in the // word_list.xml layout file. ListView listView = (ListView) rootView.findViewById(R.id.list); // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the // {@link ListView} will display list items for each {@link Word} in the list. listView.setAdapter(adapter);//w w w .j a v a 2s .co 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) { // Release the media player if it currently exists because we are about to // play a different sound file releaseMediaPlayer(); // Get the {@link Word} object at the given position the user clicked on Word word = words.get(position); // Request audio focus so in order to play the audio file. The app needs to play a // short audio file, so we will request audio focus with a short amount of time // with AUDIOFOCUS_GAIN_TRANSIENT. int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { // We have audio focus now. // Create and setup the {@link MediaPlayer} for the audio resource associated // with the current word mMediaPlayer = MediaPlayer.create(getActivity(), word.getAudioResourceId()); // Start the audio file mMediaPlayer.start(); // Setup a listener on the media player, so that we can stop and release the // media player once the sound has finished playing. mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); return rootView; }
From source file:com.example.android.gft.ColorsFragment.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 {@link 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.color_red, R.string.miwok_color_red, R.drawable.color_red, R.raw.color_red)); words.add(new Word(R.string.color_mustard_yellow, R.string.miwok_color_mustard_yellow, R.drawable.color_mustard_yellow, R.raw.color_mustard_yellow)); words.add(new Word(R.string.color_dusty_yellow, R.string.miwok_color_dusty_yellow, R.drawable.color_dusty_yellow, R.raw.color_dusty_yellow)); words.add(new Word(R.string.color_green, R.string.miwok_color_green, R.drawable.color_green, R.raw.color_green));/* w w w . j a va 2s . co m*/ words.add(new Word(R.string.color_brown, R.string.miwok_color_brown, R.drawable.color_brown, R.raw.color_brown)); words.add( new Word(R.string.color_gray, R.string.miwok_color_gray, R.drawable.color_gray, R.raw.color_gray)); words.add(new Word(R.string.color_black, R.string.miwok_color_black, R.drawable.color_black, R.raw.color_black)); words.add(new Word(R.string.color_white, R.string.miwok_color_white, R.drawable.color_white, R.raw.color_white)); // Create an {@link 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_colors); // Find the {@link ListView} object in the view hierarchy of the {@link Activity}. // There should be a {@link ListView} with the view ID called list, which is declared in the // word_list.xml layout file. ListView listView = (ListView) rootView.findViewById(R.id.list); // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the // {@link ListView} will display list items for each {@link Word} in the list. listView.setAdapter(adapter); // 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) { // Release the media player if it currently exists because we are about to // play a different sound file releaseMediaPlayer(); // Get the {@link Word} object at the given position the user clicked on Word word = words.get(position); // Request audio focus so in order to play the audio file. The app needs to play a // short audio file, so we will request audio focus with a short amount of time // with AUDIOFOCUS_GAIN_TRANSIENT. int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { // We have audio focus now. // Create and setup the {@link MediaPlayer} for the audio resource associated // with the current word mMediaPlayer = MediaPlayer.create(getActivity(), word.getAudioResourceId()); // Start the audio file mMediaPlayer.start(); // Setup a listener on the media player, so that we can stop and release the // media player once the sound has finished playing. mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); return rootView; }
From source file:com.example.android.gft.FamilyFragment.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 {@link 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.family_father, R.string.miwok_family_father, R.drawable.family_father, R.raw.family_father));/*from w w w. j av a 2s . co m*/ words.add(new Word(R.string.family_mother, R.string.miwok_family_mother, R.drawable.family_mother, R.raw.family_mother)); words.add( new Word(R.string.family_son, R.string.miwok_family_son, R.drawable.family_son, R.raw.family_son)); words.add(new Word(R.string.family_daughter, R.string.miwok_family_daughter, R.drawable.family_daughter, R.raw.family_daughter)); words.add(new Word(R.string.family_older_brother, R.string.miwok_family_older_brother, R.drawable.family_older_brother, R.raw.family_older_brother)); words.add(new Word(R.string.family_younger_brother, R.string.miwok_family_younger_brother, R.drawable.family_younger_brother, R.raw.family_younger_brother)); words.add(new Word(R.string.family_older_sister, R.string.miwok_family_older_sister, R.drawable.family_older_sister, R.raw.family_older_sister)); words.add(new Word(R.string.family_younger_sister, R.string.miwok_family_younger_sister, R.drawable.family_younger_sister, R.raw.family_younger_sister)); words.add(new Word(R.string.family_grandmother, R.string.miwok_family_grandmother, R.drawable.family_grandmother, R.raw.family_grandmother)); words.add(new Word(R.string.family_grandfather, R.string.miwok_family_grandfather, R.drawable.family_grandfather, R.raw.family_grandfather)); // Create an {@link 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_family); // Find the {@link ListView} object in the view hierarchy of the {@link Activity}. // There should be a {@link ListView} with the view ID called list, which is declared in the // word_list.xml layout file. ListView listView = (ListView) rootView.findViewById(R.id.list); // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the // {@link ListView} will display list items for each {@link Word} in the list. listView.setAdapter(adapter); // 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) { // Release the media player if it currently exists because we are about to // play a different sound file releaseMediaPlayer(); // Get the {@link Word} object at the given position the user clicked on Word word = words.get(position); // Request audio focus so in order to play the audio file. The app needs to play a // short audio file, so we will request audio focus with a short amount of time // with AUDIOFOCUS_GAIN_TRANSIENT. int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { // We have audio focus now. // Create and setup the {@link MediaPlayer} for the audio resource associated // with the current word mMediaPlayer = MediaPlayer.create(getActivity(), word.getAudioResourceId()); // Start the audio file mMediaPlayer.start(); // Setup a listener on the media player, so that we can stop and release the // media player once the sound has finished playing. mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); return rootView; }
From source file:com.example.android.gft.NumbersFragment.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 {@link 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(//from w w w . j a v a 2s .co m new Word(R.string.number_one, R.string.miwok_number_one, R.drawable.number_one, R.raw.number_one)); words.add( new Word(R.string.number_two, R.string.miwok_number_two, R.drawable.number_two, R.raw.number_two)); words.add(new Word(R.string.number_three, R.string.miwok_number_three, R.drawable.number_three, R.raw.number_three)); words.add(new Word(R.string.number_four, R.string.miwok_number_four, R.drawable.number_four, R.raw.number_four)); words.add(new Word(R.string.number_five, R.string.miwok_number_five, R.drawable.number_five, R.raw.number_five)); words.add( new Word(R.string.number_six, R.string.miwok_number_six, R.drawable.number_six, R.raw.number_six)); words.add(new Word(R.string.number_seven, R.string.miwok_number_seven, R.drawable.number_seven, R.raw.number_seven)); words.add(new Word(R.string.number_eight, R.string.miwok_number_eight, R.drawable.number_eight, R.raw.number_eight)); words.add(new Word(R.string.number_nine, R.string.miwok_number_nine, R.drawable.number_nine, R.raw.number_nine)); words.add( new Word(R.string.number_ten, R.string.miwok_number_ten, R.drawable.number_ten, R.raw.number_ten)); // Create an {@link 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_numbers); // Find the {@link ListView} object in the view hierarchy of the {@link Activity}. // There should be a {@link ListView} with the view ID called list, which is declared in the // word_list.xml layout file. ListView listView = (ListView) rootView.findViewById(R.id.list); // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the // {@link ListView} will display list items for each {@link Word} in the list. listView.setAdapter(adapter); // 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) { // Release the media player if it currently exists because we are about to // play a different sound file releaseMediaPlayer(); // Get the {@link Word} object at the given position the user clicked on Word word = words.get(position); // Request audio focus so in order to play the audio file. The app needs to play a // short audio file, so we will request audio focus with a short amount of time // with AUDIOFOCUS_GAIN_TRANSIENT. int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { // We have audio focus now. // Create and setup the {@link MediaPlayer} for the audio resource associated // with the current word mMediaPlayer = MediaPlayer.create(getActivity(), word.getAudioResourceId()); // Start the audio file mMediaPlayer.start(); // Setup a listener on the media player, so that we can stop and release the // media player once the sound has finished playing. mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); return rootView; }
From source file:com.meiste.tempalarm.ui.Alarm.java
@Override protected void onResume() { super.onResume(); final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // do not play alarms if stream volume is 0 (typically because ringer mode is silent). if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { final Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(final MediaPlayer mp, final int what, final int extra) { Timber.e("Error occurred while playing audio."); mp.stop();//from w w w . ja va 2 s. c o m mp.reset(); mp.release(); mMediaPlayer = null; return true; } }); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); try { mMediaPlayer.setDataSource(this, alert); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (final IOException e) { Timber.e("Failed to play alarm tone: %s", e); } } mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mVibrator.vibrate(sVibratePattern, 0); mPlaying = true; mHandler.sendEmptyMessageDelayed(KILLER, ALARM_TIMEOUT); }
From source file:com.google.android.marvin.talkback.ProcessorVolumeStream.java
@SuppressWarnings("deprecation") public ProcessorVolumeStream(TalkBackService service) { mContext = service;/*from w ww . j a v a 2s . com*/ mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE); mCursorController = service.getCursorController(); mFeedbackController = service.getFeedbackController(); 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:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java
private void prepareSound(Context context, Uri alert) { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); try {/*w w w .j a v a2 s .c o m*/ mMediaPlayer.setDataSource(context, alert); final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); } } catch (IOException e) { System.out.println("OOPS"); } }
From source file:info.tongrenlu.music.LocalPlayback.java
public LocalPlayback(MusicService service) { this.mService = service; this.mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) this.mWifiLock = ((WifiManager) service.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, MusicService.TAG); }