Example usage for android.content Context AUDIO_SERVICE

List of usage examples for android.content Context AUDIO_SERVICE

Introduction

In this page you can find the example usage for android.content Context AUDIO_SERVICE.

Prototype

String AUDIO_SERVICE

To view the source code for android.content Context AUDIO_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing.

Usage

From source file:com.loloof64.android.capturing_audio.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recordingButton = (ImageButton) findViewById(R.id.button_recording);
    timerTextView = (TextView) findViewById(R.id.timer_text_view);

    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_NORMAL);

    FragmentManager fragmentManager = getSupportFragmentManager();
    recorderFragment = (RecorderFragment) fragmentManager.findFragmentByTag(RECORDER_FRAGMENT_TAG);

    SimpleTimer.setTimerListener(this);

    if (recorderFragment == null) {
        recorderFragment = new RecorderFragment();
        recorderFragment.setFileRenamingManager(this);
        recorderFragment.setRecordingStatusListener(this);
        fragmentManager.beginTransaction().add(recorderFragment, RECORDER_FRAGMENT_TAG).commit();
    }//www  .  jav  a  2s.  c  om

    processStatusChange(recorderFragment.isInRecordingStatus());
}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.FindPhoneActivity.java

public void playRingtone() {
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (mAudioManager != null) {
        userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
    }/*ww  w . ja  v a  2  s  . c o m*/
    mp = new MediaPlayer();

    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    try {
        mp.setDataSource(this, ringtoneUri);
        mp.setAudioStreamType(AudioManager.STREAM_ALARM);
        mp.setLooping(true);
        mp.prepare();
        mp.start();
    } catch (IOException ignore) {
    }
    mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM,
            mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), AudioManager.FLAG_PLAY_SOUND);

}

From source file:com.android.inputmethod.accessibility.AccessibilityUtils.java

private void initInternal(final Context context) {
    mContext = context;/* w  ww  .j  a v  a  2 s . c  om*/
    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}

From source file:org.zywx.wbpalmstar.plugin.uexaudio.EUExAudio.java

public static void onActivityDestroy(Context context) {
    BDebug.i(tag, "onActivityDestroy");
    AudioManager audioManager = (AudioManager) context.getApplicationContext()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION
            || audioManager.getMode() == AudioManager.MODE_IN_CALL) {
        audioManager.setMode(AudioManager.MODE_NORMAL);
    }/*from  www. j a v  a  2  s .  c o m*/
}

From source file:com.example.android.bangla.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 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.bangla_color_red, R.drawable.color_red, R.raw.color_red));
    words.add(new Word(R.string.color_mustard_yellow, R.string.bangla_color_mustard_yellow,
            R.drawable.color_mustard_yellow, R.raw.color_mustard_yellow));
    words.add(new Word(R.string.color_dusty_yellow, R.string.bangla_color_dusty_yellow,
            R.drawable.color_dusty_yellow, R.raw.color_dusty_yellow));
    words.add(new Word(R.string.color_green, R.string.bangla_color_green, R.drawable.color_green,
            R.raw.color_green));/*  ww  w . j  a va2 s . com*/
    words.add(new Word(R.string.color_brown, R.string.bangla_color_brown, R.drawable.color_brown,
            R.raw.color_brown));
    words.add(
            new Word(R.string.color_gray, R.string.bangla_color_gray, R.drawable.color_gray, R.raw.color_gray));
    words.add(new Word(R.string.color_black, R.string.bangla_color_black, R.drawable.color_black,
            R.raw.color_black));
    words.add(new Word(R.string.color_white, R.string.bangla_color_white, R.drawable.color_white,
            R.raw.color_white));

    WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_colors);
    ListView listView = (ListView) rootView.findViewById(R.id.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) {
            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:cx.ring.fragments.CallFragment.java

@Override
public void onCreate(Bundle savedBundle) {
    Log.i(TAG, "onCreate");
    super.onCreate(savedBundle);

    audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);

    setHasOptionsMenu(true);/*from w w  w  .jav a  2  s.c o  m*/
    PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
    mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "cx.ring.onIncomingCall");
    mScreenWakeLock.setReferenceCounted(false);

    Log.d(TAG, "Acquire wake up lock");
    if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) {
        mScreenWakeLock.acquire();
    }
}

From source file:com.example.android.bangla.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 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.bangla_family_father, R.drawable.family_father,
            R.raw.family_father));//from  w  ww.  ja  v a2s.  c  o  m
    words.add(new Word(R.string.family_mother, R.string.bangla_family_mother, R.drawable.family_mother,
            R.raw.family_mother));
    words.add(
            new Word(R.string.family_son, R.string.bangla_family_son, R.drawable.family_son, R.raw.family_son));
    words.add(new Word(R.string.family_daughter, R.string.bangla_family_daughter, R.drawable.family_daughter,
            R.raw.family_daughter));
    words.add(new Word(R.string.family_older_brother, R.string.bangla_family_older_brother,
            R.drawable.family_older_brother, R.raw.family_older_brother));
    words.add(new Word(R.string.family_younger_brother, R.string.bangla_family_younger_brother,
            R.drawable.family_younger_brother, R.raw.family_younger_brother));
    words.add(new Word(R.string.family_older_sister, R.string.bangla_family_older_sister,
            R.drawable.family_older_sister, R.raw.family_older_sister));
    words.add(new Word(R.string.family_younger_sister, R.string.bangla_family_younger_sister,
            R.drawable.family_younger_sister, R.raw.family_younger_sister));
    words.add(new Word(R.string.family_grandmother, R.string.bangla_family_grandmother,
            R.drawable.family_grandmother, R.raw.family_grandmother));
    words.add(new Word(R.string.family_grandfather, R.string.bangla_family_grandfather,
            R.drawable.family_grandfather, R.raw.family_grandfather));

    WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_family);
    ListView listView = (ListView) rootView.findViewById(R.id.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) {
            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.example.android.bangla.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 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 2  s .  com
            new Word(R.string.number_one, R.string.bangla_number_one, R.drawable.number_one, R.raw.number_one));
    words.add(
            new Word(R.string.number_two, R.string.bangla_number_two, R.drawable.number_two, R.raw.number_two));
    words.add(new Word(R.string.number_three, R.string.bangla_number_three, R.drawable.number_three,
            R.raw.number_three));
    words.add(new Word(R.string.number_four, R.string.bangla_number_four, R.drawable.number_four,
            R.raw.number_four));
    words.add(new Word(R.string.number_five, R.string.bangla_number_five, R.drawable.number_five,
            R.raw.number_five));
    words.add(
            new Word(R.string.number_six, R.string.bangla_number_six, R.drawable.number_six, R.raw.number_six));
    words.add(new Word(R.string.number_seven, R.string.bangla_number_seven, R.drawable.number_seven,
            R.raw.number_seven));
    words.add(new Word(R.string.number_eight, R.string.bangla_number_eight, R.drawable.number_eight,
            R.raw.number_eight));
    words.add(new Word(R.string.number_nine, R.string.bangla_number_nine, R.drawable.number_nine,
            R.raw.number_nine));
    words.add(
            new Word(R.string.number_ten, R.string.bangla_number_ten, R.drawable.number_ten, R.raw.number_ten));

    // 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_numbers);
    ListView listView = (ListView) rootView.findViewById(R.id.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) {
            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.dena.app.usage.watcher.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mHandler = new Handler();
    startSplash();//w  ww .j  a  va 2s .  c  om
    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    WatchReceiver watchReceiver = new WatchReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WatchService.WATCH_ACTION);
    registerReceiver(watchReceiver, intentFilter);

    watchReceiver.registerHandler(new Handler() {
        public void handleMessage(Message msg) {
            if (null == mSwitchCompat) {
                return;
            }
            Bundle bundle = msg.getData();
            String message = bundle.getString(WatchService.WATCH_MESSAGE);
            if (message.equals(WatchService.WATCH_ACTION)) {
                mSwitchCompat.setChecked(true);
            }
        }
    });
}

From source file:com.lithiumli.fiction.PlaybackService.java

public int onStartCommand(Intent intent, int flags, int startId) {
    if (mQueue == null) {
        mQueue = new PlaybackQueue();
    }//from   w  w w. j a v a 2s.  c  om

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    if (intent != null && intent.getAction() != null) {
        String action = intent.getAction();
        if (action.equals(ACTION_PLAY_PAUSE)) {
            if (mPaused) {
                unpause();
            } else {
                pause();
            }
        } else if (action.equals(ACTION_PREV)) {
            this.prev();
        } else if (action.equals(ACTION_NEXT)) {
            this.next();
        }
    }
    return START_STICKY;
}