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.android.settings.beanstalk.service.AlarmService.java

@Override
public void onCreate() {
    mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    mManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
}

From source file:com.intellisol.plugin.Ringer.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (NATIVE_ACTION_STRING.equals(action)) {
        int mode;
        try {/*from w  ww.java2  s. co m*/
            // get mode from argument
            mode = args.getInt(0);

            // get context (Android)
            Context ctxt = cordova.getActivity().getBaseContext();
            if (mode == NORMAL) {
                // set ringer mode
                AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE);
                audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            } else if (mode == VIBRATE) {
                AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE);
                audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
            } else if (mode == SILENT) {
                AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE);
                audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            }

        } catch (JSONException e) {
            // log error
            Log.d("Ringer", e.toString());
            return false;
        } catch (Exception e) {
            // log error
            Log.d("Ringer", e.toString());
            return false;
        }
    }
    return true;
}

From source file:bala.padio.Player.java

private void Play(String url) {
    try {//w  ww  .  j a v  a 2s . co m

        if (url == null) {
            Log.e(TAG, "Empty url");
            return;
        }

        // request audio focus
        if (audioManager == null) {
            audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        }
        int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);
        if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            Log.e(TAG, "Audio focus not granted");
            return;
        }

        // initialize player
        if (mediaPlayer != null) {
            mediaPlayer.reset();
        } else {
            mediaPlayer = new MediaPlayer();
        }

        // set playerUrl source and prepare media player
        this.playerUrl = url;
        Uri streamUrl = Uri.parse(getStreamUrl(url));
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setDataSource(this, streamUrl);
        mediaPlayer.setOnErrorListener(this);
        mediaPlayer.setOnPreparedListener(this);
        mediaPlayer.prepareAsync();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:net.hyx.app.volumenotification.NotificationFactory.java

private NotificationFactory(Context context) {
    this.context = context;
    resources = context.getResources();/*from www. ja va 2s . c  o  m*/
    manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    settings = new PrefSettings(context);
    _package = context.getPackageName();
}

From source file:edu.ucdavis.glass.sepsis.support.OverviewActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Global.overview = 1;/*from   w w w .ja  va 2s .c  o m*/

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

    mGestureDetector = createGestureDetector(this);
    mHeadGestureDetector = new HeadGestureDetector(this);
    mHeadGestureDetector.setOnHeadGestureListener(this);
    mHeadGestureDetector.start();

    // set up voice command
    if (Global.overviewCreated == 0) {
        String[] items = { "Vitals", "Decision Support", "Events", "Overview" };
        mVoiceConfig = new VoiceConfig("MyVoiceConfig", items);
        mVoiceInputHelper = new VoiceInputHelper(this, new MyVoiceListener(mVoiceConfig),
                VoiceInputHelper.newUserActivityObserver(this));
        mVoiceInputHelper.addVoiceServiceListener();
        Global.overviewCreated = 1;
    }

    setContentView(R.layout.overview);
    loadView();
}

From source file:com.example.android.miwok.activity.ColorsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_list);/*from ww  w. j  a  v a  2s . com*/

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    // Create a list of words
    final ArrayList<Word> words = new ArrayList<Word>();
    words.add(new Word("red", "weei", R.drawable.color_red, R.raw.color_red));
    words.add(new Word("mustard yellow", "chiwii", R.drawable.color_mustard_yellow,
            R.raw.color_mustard_yellow));
    words.add(new Word("dusty yellow", "opiis", R.drawable.color_dusty_yellow, R.raw.color_dusty_yellow));
    words.add(new Word("green", "chokokki", R.drawable.color_green, R.raw.color_green));
    words.add(new Word("brown", "akaakki", R.drawable.color_brown, R.raw.color_brown));
    words.add(new Word("gray", "opoppi", R.drawable.color_gray, R.raw.color_gray));
    words.add(new Word("black", "kululli", R.drawable.color_black, R.raw.color_black));
    words.add(new Word("white", "kelelli", 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(this, words);

    // 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) findViewById(R.id.list);
    listView.setBackgroundColor(Color.parseColor("#8800A0"));
    //listView.setBackgroundColor(R.color.category_colors);

    // 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);

    //plays the audio for number one when any item in the list is clicked click
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //release current resources being used for media player if it currently exists
            //because we are about to play a different sound file.
            releaseMediaPlayer();

            //get the word located in the list that is at same position as the item clicked in the list
            Word currentWord = words.get(position);

            // Request audio focus for playback
            int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener,
                    // Use the music stream.
                    AudioManager.STREAM_MUSIC,
                    // Request temporary focus.
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

                //create the medial player with the audio file that is stored in the list for that word.
                mMediaPlayer = MediaPlayer.create(getApplicationContext(), currentWord.getmMiwokAudio());
                //play the file
                mMediaPlayer.start();

                //listener to stop and release the media player and resources being used
                // once the sounds has finished playing
                mMediaPlayer.setOnCompletionListener(mCompletionListener);
            }

        }
    });
}

From source file:com.example.android.miwok.activity.PhrasesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_list);//  w  ww  .j a  v a2  s.c o m

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

    // Create a list of words
    final ArrayList<Word> words = new ArrayList<Word>();
    words.add(new Word("Where are you going?", "minto wuksus", R.raw.phrase_where_are_you_going));
    words.add(new Word("What is your name?", "tinn oyaase'n", R.raw.phrase_what_is_your_name));
    words.add(new Word("My name is...", "oyaaset...", R.raw.phrase_my_name_is));
    words.add(new Word("How are you feeling?", "michkss?", R.raw.phrase_how_are_you_feeling));
    words.add(new Word("Im feeling good.", "kuchi achit", R.raw.phrase_im_feeling_good));
    words.add(new Word("Are you coming?", "ns'aa?", R.raw.phrase_are_you_coming));
    words.add(new Word("Yes, Im coming.", "h nm", R.raw.phrase_yes_im_coming));
    words.add(new Word("Im coming.", "nm", R.raw.phrase_im_coming));
    words.add(new Word("Lets go.", "yoowutis", R.raw.phrase_lets_go));
    words.add(new Word("Come here.", "nni'nem", 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(this, words);

    // 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) findViewById(R.id.list);
    listView.setBackgroundColor(Color.parseColor("#16AFCA"));
    //listView.setBackgroundColor(R.color.category_phrases);

    // 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);

    //plays the audio for number one when any item in the list is clicked click
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //release current resources being used for media player if it currently exists
            //because we are about to play a different sound file.
            releaseMediaPlayer();

            //get the word located in the list that is at same position as the item clicked in the list
            Word currentWord = words.get(position);

            /// Request audio focus for playback
            int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener,
                    // Use the music stream.
                    AudioManager.STREAM_MUSIC,
                    // Request temporary focus.
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

                //create the medial player with the audio file that is stored in the list for that word.
                mMediaPlayer = MediaPlayer.create(getApplicationContext(), currentWord.getmMiwokAudio());
                //play the file
                mMediaPlayer.start();

                //listener to stop and release the media player and resources being used
                // once the sounds has finished playing
                mMediaPlayer.setOnCompletionListener(mCompletionListener);
            }
        }
    });
}

From source file:com.example.android.miwok.activity.FamilyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_list);/* www  .  j a  va 2 s  .c o  m*/

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

    // Create a list of words
    final ArrayList<Word> words = new ArrayList<Word>();
    words.add(new Word("father", "p", R.drawable.family_father, R.raw.family_father));
    words.add(new Word("mother", "a", R.drawable.family_mother, R.raw.family_mother));
    words.add(new Word("son", "angsi", R.drawable.family_son, R.raw.family_son));
    words.add(new Word("daughter", "tune", R.drawable.family_daughter, R.raw.family_daughter));
    words.add(new Word("older brother", "taachi", R.drawable.family_older_brother, R.raw.family_older_brother));
    words.add(new Word("younger brother", "chalitti", R.drawable.family_younger_brother,
            R.raw.family_younger_brother));
    words.add(new Word("older sister", "tee", R.drawable.family_older_sister, R.raw.family_older_sister));
    words.add(new Word("younger sister", "kolliti", R.drawable.family_younger_sister,
            R.raw.family_younger_sister));
    words.add(new Word("grandmother ", "ama", R.drawable.family_grandmother, R.raw.family_grandmother));
    words.add(new Word("grandfather", "paapa", 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(this, words);

    // 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) findViewById(R.id.list);
    listView.setBackgroundColor(Color.parseColor("#379237")); //<--this is another way to set the background color is it wasn't in colors.xml
    //listView.setBackgroundColor(R.color.category_family);

    // 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);

    //plays the audio for number one when any item in the list is clicked click
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //release current resources being used for media player if it currently exists
            //because we are about to play a different sound file.
            releaseMediaPlayer();

            //get the word located in the list that is at same position as the item clicked in the list
            Word currentWord = words.get(position);

            // Request audio focus for playback
            int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener,
                    // Use the music stream.
                    AudioManager.STREAM_MUSIC,
                    // Request temporary focus.
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

                //create the medial player with the audio file that is stored in the list for that word.
                mMediaPlayer = MediaPlayer.create(getApplicationContext(), currentWord.getmMiwokAudio());
                //play the file
                mMediaPlayer.start();

                //listener to stop and release the media player and resources being used
                // once the sounds has finished playing
                mMediaPlayer.setOnCompletionListener(mCompletionListener);
            }
        }
    });
}

From source file:com.glanznig.beepme.view.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from w  w w .  j ava2  s.  c o m

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

    pagerAdapter = new MainSectionsPagerAdapter(getSupportFragmentManager(), this);
    final ActionBar actionBar = getActionBar();

    final BeeperApp app = (BeeperApp) getApplication();

    if (app.getPreferences().isTestMode()) {
        actionBar.setSubtitle(getString(R.string.pref_title_test_mode));
    }

    // displaying tabs in the action bar
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    pager = (ViewPager) findViewById(R.id.main_tab_pager);
    pager.setAdapter(pagerAdapter);

    // set gap between pages
    pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
            this.getResources().getDisplayMetrics()));
    pager.setPageMarginDrawable(R.drawable.swipe_filler);

    // listening for page changes
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // for each of the sections in the app, add a tab to the action bar
    for (int i = 0; i < pagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(pagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:capstone.se491_phm.Alarm.java

public static void loudest(Context context, int stream) {
    AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int loudest = manager.getStreamMaxVolume(stream);
    manager.setStreamVolume(stream, loudest, 0);
}