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:edu.cmu.mpcs.dashboard.TagViewer.java

private String ringerSetting(String settingString) {
    /*****/*from   w ww.j ava  2  s. co  m*/
     * Setting the phone on Silent, Vibrate and Normal modes
     *****/

    if (settingString.contains("ringer")) {
        AudioManager audMangr;
        audMangr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);

        // For Normal mode
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        // For Silent mode
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        // For vibrate
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

        if (settingString.contains("ringer:Loud")) {
            audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            return ("Phone Ringer:Loud\n");

        } else {
            audMangr.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
            return ("Phone Ringer:Vibrate\n");

        }

        /* Adjusting volume */
        // if (audMangr.getRingerMode() == AudioManager.RINGER_MODE_NORMAL)
        // {
        // Log.d("RINGER", "setting ringer to silent");
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        // audMangr.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        //
        // } else {
        // Log.d("RINGER", "setting ringer to normal");
        //
        //
        // }
    }

    return ("");

}

From source file:com.PPRZonDroid.MainActivity.java

/**
 * Play warning sound if airspeed goes below the selected value
 *
 * @param context/*from   www.  ja v a  2s  . c o  m*/
 * @throws IllegalArgumentException
 * @throws SecurityException
 * @throws IllegalStateException
 * @throws IOException
 */
public void play_sound(Context context)
        throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    MediaPlayer mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDataSource(context, soundUri);
    final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    //Set volume max!!!
    audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM,
            audioManager.getStreamMaxVolume(audioManager.STREAM_SYSTEM), 0);

    if (audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) != 0) {
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_SYSTEM);
        mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();
    }
}

From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java

public static void playbackFile(final Activity context, final FileMirakel file, final boolean loud) {
    final MediaPlayer mPlayer = new MediaPlayer();
    final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (!loud) {//from w w w .  j av  a2s.c o  m
        am.setSpeakerphoneOn(false);
        am.setMode(AudioManager.MODE_IN_CALL);
        context.setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
    }
    try {
        mPlayer.reset();
        if (!loud) {
            mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
        }
        mPlayer.setDataSource(file.getFileStream(context).getFD());
        mPlayer.prepare();
        mPlayer.start();
        mPlayer.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(final MediaPlayer mp) {
                audio_playback_dialog.dismiss();
            }
        });
        am.setMode(AudioManager.MODE_NORMAL);
        audio_playback_playing = true;
    } catch (final IOException e) {
        Log.e(TAG, "prepare() failed");
    }
    audio_playback_dialog = new AlertDialog.Builder(context).setTitle(R.string.audio_playback_title)
            .setPositiveButton(R.string.audio_playback_pause, null)
            .setNegativeButton(R.string.audio_playback_stop, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    mPlayer.release();
                }
            }).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(final DialogInterface dialog) {
                    mPlayer.release();
                    dialog.cancel();
                }
            }).create();
    audio_playback_dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            final Button button = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View v) {
                    if (audio_playback_playing) {
                        button.setText(R.string.audio_playback_play);
                        mPlayer.pause();
                        audio_playback_playing = false;
                    } else {
                        button.setText(R.string.audio_playback_pause);
                        mPlayer.start();
                        audio_playback_playing = true;
                    }
                }
            });
        }
    });
    audio_playback_dialog.show();
}

From source file:com.sean.takeastand.alarmprocess.AlarmService.java

private void updateNotification() {
    /*if (!bRepeatingAlarmStepCheck) {
    mNotifTimePassed++;/*ww w.  java2s  . com*/
    }
    Log.i(TAG, "time since first notification: " + mNotifTimePassed + setMinutes(mNotifTimePassed));*/
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent[] pendingIntents = makeNotificationIntents();
    RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification);
    rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]);
    rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime);
    /*rvRibbon.setTextViewText(R.id.stand_up_minutes, mNotifTimePassed +
        setMinutes(mNotifTimePassed));
    rvRibbon.setTextViewText(R.id.topTextView, getString(R.string.stand_up_time_up));*/
    NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this);
    alarmNotificationBuilder.setContent(rvRibbon);
    alarmNotificationBuilder.setContentIntent(pendingIntents[0]).setAutoCancel(false)
            .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small)
            .setContentTitle("Take A Stand ")
            //.setContentText("Mark Stood\n" + mNotifTimePassed + setMinutes(mNotifTimePassed))
            .extend(new NotificationCompat.WearableExtender().addAction(
                    new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[1])
                            .build())
                    .setContentAction(0).setHintHideIcon(true)
    //                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed))
    );

    boolean[] alertType;
    if (mCurrentAlarmSchedule != null) {
        alertType = mCurrentAlarmSchedule.getAlertType();
    } else {
        alertType = Utils.getDefaultAlertType(this);
    }

    if ((alertType[0])) {
        alarmNotificationBuilder.setLights(238154000, 1000, 4000);
    }
    if (Utils.getRepeatAlerts(this)) {
        if (alertType[1]) {
            boolean bUseLastStepCounters = false;
            if (!bRepeatingAlarmStepCheck) {
                bRepeatingAlarmStepCheck = true;
                bUseLastStepCounters = UseLastStepCounters(null);
            }
            if (!bUseLastStepCounters) {
                bRepeatingAlarmStepCheck = false;
                alarmNotificationBuilder.setVibrate(mVibrationPattern);
                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT
                        && Utils.getVibrateOverride(this)) {
                    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                    v.vibrate(mVibrationPattern, -1);
                }
            }
        }
        if (alertType[2]) {
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            alarmNotificationBuilder.setSound(soundUri);
        }
    }

    Notification alarmNotification = alarmNotificationBuilder.build();
    notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification);
}

From source file:com.ieeton.agency.activity.ChatActivity.java

private void playSound() {
    AudioManager mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    int curVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
    if (curVolume == 0) {
        return;/*  w w w .j av a  2 s.  c om*/
    }

    mStreamID = mSoundPool.play(mSoundID, curVolume, curVolume, 0, 0, 1);
}

From source file:im.vector.activity.CallViewActivity.java

/**
 * Initialize the audio volume./*from ww  w.  j ava 2s.co  m*/
 */
private void initMediaPlayerVolume() {
    AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    // use the ringing volume to initialize the playing volume
    // it does not make sense to ring louder
    int maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int minValue = firstCallAlert ? FIRST_PERCENT_VOLUME : DEFAULT_PERCENT_VOLUME;
    int ratio = (audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) * 100) / maxVol;

    firstCallAlert = false;

    // ensure there is a minimum audio level
    // some users could complain they did not hear their device was ringing.
    if (ratio < minValue) {
        setMediaPlayerVolume(minValue);
    } else {
        setMediaPlayerVolume(ratio);
    }
}

From source file:im.vector.activity.CallViewActivity.java

private void setMediaPlayerVolume(int percent) {
    if (percent < 0 || percent > 100) {
        Log.e(LOG_TAG, "setMediaPlayerVolume percent is invalid: " + percent);
        return;/*from w w w  .  ja v a  2 s. com*/
    }

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

    mCallVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);

    int maxMusicVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int maxVoiceVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);

    if (maxMusicVol > 0) {
        int volume = (int) ((float) percent / 100f * maxMusicVol);
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);

        volume = (int) ((float) percent / 100f * maxVoiceVol);
        audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, volume, 0);
    }
    Log.i(LOG_TAG,
            "Set media volume (ringback) to: " + audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
}

From source file:org.linphone.LinphoneService.java

void addCallListner() {

    mIncomingCallReceiver = new IncomingCallReceiver();

    IntentFilter mIntentFilter = new IntentFilter();
    // /*from w  w  w .  java2s. c  o m*/
    mIntentFilter.addAction("android.intent.action.PHONE_STATE");
    mIntentFilter.setPriority(1000);
    // 
    //      mIntentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
    // BroadcastReceiver
    registerReceiver(mIncomingCallReceiver, mIntentFilter);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    // endcall
    TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    try {
        Method getITelephonyMethod = TelephonyManager.class.getDeclaredMethod("getITelephony", (Class[]) null);
        getITelephonyMethod.setAccessible(true);
        //       mITelephony = (ITelephony)
        getITelephonyMethod.invoke(mTelephonyManager, (Object[]) null);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.digium.respokesdk.RespokeCall.java

private void addLocalStreams(Context context) {
    AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
    // TODO(fischman): figure out how to do this Right(tm) and remove the suppression.
    @SuppressWarnings("deprecation")
    boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn();
    audioManager.setMode(isWiredHeadsetOn ? AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION);
    audioManager.setSpeakerphoneOn(!isWiredHeadsetOn);

    localStream = peerConnectionFactory.createLocalMediaStream("ARDAMS");

    if (!audioOnly) {
        VideoCapturer capturer = getVideoCapturer();
        MediaConstraints videoConstraints = new MediaConstraints();
        videoSource = peerConnectionFactory.createVideoSource(capturer, videoConstraints);
        VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("ARDAMSv0", videoSource);
        videoTrack.addRenderer(new VideoRenderer(localRender));
        localStream.addTrack(videoTrack);
    }//from   w  ww. j av a  2 s  . c  o  m

    localStream.addTrack(peerConnectionFactory.createAudioTrack("ARDAMSa0",
            peerConnectionFactory.createAudioSource(new MediaConstraints())));

    peerConnection.addStream(localStream);
}

From source file:com.intel.xdk.player.Player.java

public void setAudioVolume(String volume) {
    //Valid volumes 0.0 to 1.0
    double castVol = Float.parseFloat(volume);
    if (castVol > 1.0)
        castVol = 1.0;/*from w w  w  .  ja v  a2s . c o  m*/
    // Get the AudioManager
    AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    int newVol = (int) (audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * castVol);
    // Set the volume of played media to maximum.
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, newVol, 0);

    String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.player.audio.volume.set',true,true);document.dispatchEvent(e);";
    injectJS(js);
}