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.bayapps.android.robophish.playback.LocalPlayback.java

public LocalPlayback(Context context, MusicProvider musicProvider) {
    this.mContext = context;
    this.mMusicProvider = musicProvider;
    this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "uAmp_lock");
    this.mState = PlaybackStateCompat.STATE_NONE;
}

From source file:de.tubs.ibr.dtn.dtalkie.TalkieActivity.java

@SuppressWarnings("deprecation")
private void setAudioOutput() {
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    if (am.isBluetoothA2dpOn()) {
        // play without speaker
        am.setSpeakerphoneOn(false);//from  w  w  w  .  j  a v  a2s  .  c  o m
    } else if (am.isWiredHeadsetOn()) {
        // play without speaker
        am.setSpeakerphoneOn(false);
    } else {
        // without headset, enable speaker
        am.setSpeakerphoneOn(true);
    }
}

From source file:com.gelakinetic.mtgfam.fragments.LifeCounterFragment.java

/**
 * When the fragment is created, set up the TTS engine, AudioManager, and MediaPlayer for life total vocalization
 *
 * @param savedInstanceState If the fragment is being re-created from a previous saved state, this is the state.
 *///from  w ww .  j  a va2  s . c o  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mTtsInit = false;
    mTts = new TextToSpeech(getActivity(), this);
    mTts.setOnUtteranceCompletedListener(this);

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

    m9000Player = MediaPlayer.create(getActivity(), R.raw.over_9000);
    if (m9000Player != null) {
        m9000Player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                onUtteranceCompleted(LIFE_ANNOUNCE);
            }
        });
    }
}

From source file:dev.datvt.cloudtracks.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    loadLocale();//www  . j a v  a 2s . co m
    setContentView(R.layout.main);

    // Obtain the shared Tracker instance.
    MyApplication application = (MyApplication) getApplication();
    mTracker = application.getDefaultTracker();

    broadcastReceiver = new PlayerReciever();
    IntentFilter filter = new IntentFilter();
    filter.addAction(ConstantHelper.RESUME_SONG);
    filter.addAction(ConstantHelper.PAUSE_SONG);
    filter.addAction(ConstantHelper.NEXT_SONG);
    filter.addAction(ConstantHelper.PREVIOUS_SONG);
    filter.addAction(ConstantHelper.PLAY_SONG);
    filter.addAction(ConstantHelper.ACTION_COMPLETE_MUSIC);
    filter.addAction(ConstantHelper.ACTION_CLOSE_NOTI);
    registerReceiver(broadcastReceiver, filter);

    sharedPreferences = getSharedPreferences("save_cloud", MODE_PRIVATE);
    editor = sharedPreferences.edit();

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

    rep = sharedPreferences.getInt("repeat", REP);

    Log.d("REPEAT_MAIN", rep + "");

    Intent intentRep = new Intent(this, MediaPlayerService.class);
    intentRep.setAction(ConstantHelper.ACTION_REP);
    intentRep.putExtra("rep", rep);
    startService(intentRep);

    initViewId();
    addEvents();

    recentPlay();

    boolean isNoti = sharedPreferences.getBoolean("isNoti", false);

    if (audioManager.isMusicActive() && isNoti) {
        isPlaying = true;
    } else {
        isPlaying = false;
    }

    Log.e("isPlay_Start", isPlaying + "");

    if (audioManager.isMusicActive() && isPlaying) {
        Log.e("SONG", "audioManager");
        curPos = NotificationUtil.position;
        if (MediaPlayerService.tracks != null) {

            tracks = MediaPlayerService.tracks;
            if (tracks.size() > curPos) {
                curTrack = tracks.get(curPos);
                updateSong();
            }
        }
        tabPlayer.setVisibility(View.VISIBLE);
        rlMain.setBackgroundResource(R.color.colorPrimary);
    }

}

From source file:com.customprogrammingsolutions.MediaStreamer.MediaStreamerService.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)
        return false;
    else//  ww  w  .  j  av a  2 s .  co  m
        return true;
}

From source file:com.jinfukeji.jinyihuiup.indexBannerClick.ZhiboActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_zhibo);
    checkWifi();/*from w  ww. ja v  a2 s  . c  o  m*/
    client = new ExampleClient(URI.create(
            JinYiHuiApplication.URL_BOOT + "ws?id=" + JinYiHuiApplication.getInstace().getUser().getId()),
            this);
    am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    streamVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);//???
    streamMaxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    screen_direction = SCREEN_PORT;
    initView();
    initClickListener();
    setOnClick();
    initVariable();
    client.connect();
    isShowLayout = true;
    new Thread(new Runnable() {
        @Override
        public void run() {
            kk = NetUtil.getK();
            initParam(kk);
            initplayer();
            isPlayed = true;
        }
    }).start();
}

From source file:com.android.talkback.eventprocessor.ProcessorVolumeStream.java

@SuppressWarnings("deprecation")
public ProcessorVolumeStream(FeedbackController feedbackController, CursorController cursorController,
        DimScreenController dimScreenController, TalkBackService service) {
    if (feedbackController == null)
        throw new IllegalStateException("CachedFeedbackController is null");
    if (cursorController == null)
        throw new IllegalStateException("CursorController is null");
    if (dimScreenController == null)
        throw new IllegalStateException("DimScreenController is null");

    mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE);
    mCursorController = cursorController;
    mFeedbackController = feedbackController;

    final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, WL_TAG);

    mPrefs = SharedPreferencesUtils.getSharedPreferences(service);
    mService = service;/*w w  w. j a v a 2  s . co  m*/
    mDimScreenController = dimScreenController;
    mPatternDetector = new VolumeButtonPatternDetector();
    mPatternDetector.setOnPatternMatchListener(this);
}

From source file:com.zion.htf.receiver.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // Get preferences
    Resources res = context.getResources();
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);

    int setId, alarmId;
    try {/* w  w  w.  jav a  2  s.co  m*/
        if (0 == (setId = intent.getIntExtra("set_id", 0)))
            throw new MissingArgumentException("set_id", "int");
        if (0 == (alarmId = intent.getIntExtra("alarm_id", 0)))
            throw new MissingArgumentException("alarm_id", "int");
    } catch (MissingArgumentException e) {
        throw new RuntimeException(e.getMessage());
    }

    // Fetch info about the set
    try {
        // VIBRATE will be added if user did NOT disable notification vibration
        // SOUND won't as it is set even if it is to the default value
        int flags = Notification.DEFAULT_LIGHTS;
        MusicSet set = MusicSet.getById(setId);
        Artist artist = set.getArtist();

        SimpleDateFormat dateFormat;
        if ("fr".equals(Locale.getDefault().getLanguage())) {
            dateFormat = new SimpleDateFormat("HH:mm", Locale.FRANCE);
        } else {
            dateFormat = new SimpleDateFormat("h:mm aa", Locale.ENGLISH);
        }

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(context, ArtistDetailsActivity.class);
        resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);// Do not start a  new activity but reuse the existing one (if any)
        resultIntent.putExtra(ArtistDetailsActivity.EXTRA_SET_ID, setId);

        // Manipulate the TaskStack in order to get a good back button behaviour. See http://developer.android.com/guide/topics/ui/notifiers/notifications.html
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(ArtistDetailsActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        // Extract a bitmap from a file to use a large icon
        Bitmap largeIconBitmap = BitmapFactory.decodeResource(context.getResources(),
                artist.getPictureResourceId());

        // Builds the notification
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_notify_app_icon)
                .setLargeIcon(largeIconBitmap).setAutoCancel(true).setContentIntent(resultPendingIntent)
                .setContentTitle(artist.getName())
                .setContentText(String.format(context.getString(R.string.alarm_notification), artist.getName(),
                        set.getStage(), dateFormat.format(set.getBeginDate())));

        // Vibrate settings
        Boolean defaultVibrate = true;
        if (!pref.contains(res.getString(R.string.pref_key_notifications_alarms_vibrate))) {
            // Get the system default for the vibrate setting
            AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            if (null != audioManager) {
                switch (audioManager.getRingerMode()) {
                case AudioManager.RINGER_MODE_SILENT:
                    defaultVibrate = false;
                    break;
                case AudioManager.RINGER_MODE_NORMAL:
                case AudioManager.RINGER_MODE_VIBRATE:
                default:
                    defaultVibrate = true;
                }
            }
        }
        Boolean vibrate = pref.getBoolean(res.getString(R.string.pref_key_notifications_alarms_vibrate),
                defaultVibrate);

        // Ringtone settings
        String ringtone = pref.getString(res.getString(R.string.pref_key_notifications_alarms_ringtone),
                Settings.System.DEFAULT_NOTIFICATION_URI.toString());

        // Apply notification settings
        if (!vibrate) {
            notificationBuilder.setVibrate(new long[] { 0l });
        } else {
            flags |= Notification.DEFAULT_VIBRATE;
        }

        notificationBuilder.setSound(Uri.parse(ringtone));

        // Get the stage GPS coordinates
        try {
            Stage stage = Stage.getByName(set.getStage());

            // Add the expandable notification buttons
            PendingIntent directionsButtonPendingIntent = PendingIntent
                    .getActivity(context, 1,
                            new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(String.format(Locale.ENGLISH,
                                            "http://maps.google.com/maps?f=d&daddr=%f,%f", stage.getLatitude(),
                                            stage.getLongitude()))),
                            Intent.FLAG_ACTIVITY_NEW_TASK);
            notificationBuilder.addAction(R.drawable.ic_menu_directions,
                    context.getString(R.string.action_directions), directionsButtonPendingIntent);
        } catch (InconsistentDatabaseException e) {
            // Although this is a serious error, its impact on functionality is minimal.
            // Report this through piwik
            if (BuildConfig.DEBUG)
                e.printStackTrace();
        }

        // Finalize the notification
        notificationBuilder.setDefaults(flags);
        Notification notification = notificationBuilder.build();

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(set.getStage(), 0, notification);

        SavedAlarm.delete(alarmId);
    } catch (SetNotFoundException e) {
        throw new RuntimeException(e.getMessage());
        // TODO: Notify that an alarm was planned but some error prevented to display it properly. Open AlarmManagerActivity on click
        // Report this through piwik
    }
}

From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java

public void run() {
    // Start the thread
    mNotificationManager = (NotificationManager) App.mApp.getSystemService(Context.NOTIFICATION_SERVICE);

    Looper.prepare();//  w ww  . j a  v a  2s .c  o  m
    mHandler = new ClementineConnectionHandler(this);

    mPebble = new Pebble();

    // Get a Wakelock Object
    PowerManager pm = (PowerManager) App.mApp.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clementine");

    Resources res = App.mApp.getResources();
    mNotificationHeight = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
    mNotificationWidth = (int) res.getDimension(android.R.dimen.notification_large_icon_width);

    mAudioManager = (AudioManager) App.mApp.getSystemService(Context.AUDIO_SERVICE);
    mClementineMediaButtonEventReceiver = new ComponentName(App.mApp.getPackageName(),
            ClementineMediaButtonEventReceiver.class.getName());

    mMediaButtonBroadcastReceiver = new ClementineMediaButtonEventReceiver();

    fireOnConnectionReady();

    Looper.loop();
}

From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java

@Override
public void onCreate() {
    // Create the service
    super.onCreate();

    restService = RESTService.getInstance();

    currentListPosition = 0;/*  www . j  av  a  2s. c om*/

    mediaElementList = new ArrayList<>();

    // Setup media session
    mediaSessionCallback = new MediaSessionCallback();
    mediaSession = new MediaSessionCompat(this, "SMSPlayer");
    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);
    mediaState = PlaybackStateCompat.STATE_NONE;
    updatePlaybackState();

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

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sms");
    wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL,
            "sms");
}