Example usage for android.media AudioManager isMusicActive

List of usage examples for android.media AudioManager isMusicActive

Introduction

In this page you can find the example usage for android.media AudioManager isMusicActive.

Prototype

public boolean isMusicActive() 

Source Link

Document

Checks whether any music is active.

Usage

From source file:org.sipdroid.sipua.ui.Receiver.java

static void broadcastCallStateChanged(String state, String number) {
    if (state == null) {
        state = laststate;/*  w w  w.j  a v  a2s  . c om*/
        number = lastnumber;
    }
    if (android.os.Build.VERSION.SDK_INT < 19) {
        Intent intent = new Intent(ACTION_PHONE_STATE_CHANGED);
        intent.putExtra("state", state);
        if (number != null)
            intent.putExtra("incoming_number", number);
        intent.putExtra(mContext.getString(R.string.app_name), true);
        mContext.sendBroadcast(intent, android.Manifest.permission.READ_PHONE_STATE);
    }
    if (state.equals("IDLE")) {
        if (was_playing) {
            if (pstn_state == null || pstn_state.equals("IDLE"))
                mContext.sendBroadcast(new Intent(TOGGLEPAUSE_ACTION));
            was_playing = false;
        }
    } else {
        AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        if ((laststate == null || laststate.equals("IDLE")) && (was_playing = am.isMusicActive()))
            mContext.sendBroadcast(new Intent(PAUSE_ACTION));
    }
    laststate = state;
    lastnumber = number;
}

From source file:fr.inria.ucn.collectors.SysStateCollector.java

@SuppressWarnings("deprecation")
private JSONObject getAudioState(Context c) throws JSONException {
    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    JSONObject data = new JSONObject();

    data.put("is_bluetooth_a2dp_on", am.isBluetoothA2dpOn());
    data.put("is_microphone_mute", am.isMicrophoneMute());
    data.put("is_music_active", am.isMusicActive());
    data.put("is_speaker_phone_on", am.isSpeakerphoneOn());
    data.put("is_wired_headset_on", am.isWiredHeadsetOn());

    switch (am.getMode()) {
    case AudioManager.MODE_IN_CALL:
        data.put("mode", "in_call");
        break;//from  w  ww  .jav a 2s  .  c  o m
    case AudioManager.MODE_IN_COMMUNICATION:
        data.put("mode", "in_comm");
        break;
    case AudioManager.MODE_NORMAL:
        data.put("mode", "normal");
        break;
    case AudioManager.MODE_RINGTONE:
        data.put("mode", "ringtone");
        break;
    case AudioManager.MODE_INVALID:
    default:
        data.put("mode", "invalid");
        break;
    }

    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        data.put("ringer_mode", "vibrate");
        break;
    case AudioManager.RINGER_MODE_SILENT:
        data.put("ringer_mode", "silent");
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        data.put("ringer_mode", "normal");
        break;
    default:
        data.put("ringer_mode", "invalid");
        break;
    }
    return data;
}

From source file:com.trigger_context.Main_Service.java

private boolean testConditions(String mac) {
    SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE);
    Map<String, ?> cond_map = conditions.getAll();
    Set<String> key_set = cond_map.keySet();
    boolean takeAction = true;
    if (key_set.contains("bluetooth")) {
        // checking the current state against the state set by the user
        final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        takeAction = new Boolean(bluetoothAdapter.isEnabled())
                .equals(conditions.getString("bluetooth", "false"));
    }//ww w  .jav a  2s .c  om
    if (takeAction && key_set.contains("wifi")) {
        final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        takeAction = new Boolean(wm.isWifiEnabled()) == conditions.getBoolean("wifi", false);
    }

    if (takeAction && key_set.contains("gps")) {
        final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        takeAction = new Boolean(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
                .equals(conditions.getString("gps", "false"));
    }
    if (takeAction && key_set.contains("sms")) {
        final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
        Cursor c = getContentResolver().query(SMS_INBOX, null, "read = 0", null, null);
        if (c != null) {
            int unreadMessagesCount = c.getCount();
            c.close();
            takeAction = new Boolean(unreadMessagesCount > 0).equals(conditions.getString("sms", "false"));
        } else {
            takeAction = false;
        }
    }

    // "NOT TESTED" head set, missed call, accelerometer, proximity, gyro,
    // orientation
    if (takeAction && key_set.contains("headset")) {
        AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        takeAction = am.isMusicActive() == conditions.getBoolean("headset", false);
        // am.isWiredHeadsetOn() is deprecated

    }
    /*
     * if(takeAction && key_set.contains("missedCall")) { final String[]
     * projection = null; final String selection = null; final String[]
     * selectionArgs = null; final String sortOrder =
     * android.provider.CallLog.Calls.DATE + " DESC"; Cursor cursor = null;
     * try{ cursor = getApplicationContext().getContentResolver().query(
     * Uri.parse("content://call_log/calls"), projection, selection,
     * selectionArgs, sortOrder); while (cursor.moveToNext()) { String
     * callLogID =
     * cursor.getString(cursor.getColumnIndex(android.provider.CallLog
     * .Calls._ID)); String callNumber =
     * cursor.getString(cursor.getColumnIndex
     * (android.provider.CallLog.Calls.NUMBER)); String callDate =
     * cursor.getString
     * (cursor.getColumnIndex(android.provider.CallLog.Calls.DATE)); String
     * callType =
     * cursor.getString(cursor.getColumnIndex(android.provider.CallLog
     * .Calls.TYPE)); String isCallNew =
     * cursor.getString(cursor.getColumnIndex
     * (android.provider.CallLog.Calls.NEW)); if(Integer.parseInt(callType)
     * == android.provider.CallLog.Calls.MISSED_CALL_TYPE &&
     * Integer.parseInt(isCallNew) > 0){
     * 
     * } } }catch(Exception ex){ }finally{ cursor.close(); }
     * 
     * }
     */
    return takeAction;
}

From source file:edu.cmu.mpcs.dashboard.TagViewer.java

private void launchmusicSetting(String settingString) {

    if (settingString.contains("launch music")) {

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

        if (!mAudioManager.isMusicActive()) {
            Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.music");
            startActivity(LaunchIntent);
        }/*from   w ww.ja va  2s .c o m*/

        if (settingString.contains("launch music:On")) {
            /** Launching the Music App **/
            Intent commandIntent = new Intent("com.android.music.musicservicecommand");
            commandIntent.putExtra("command", "play");
            sendBroadcast(commandIntent);

        } else {
            Intent commandIntent = new Intent("com.android.music.musicservicecommand");
            commandIntent.putExtra("command", "pause");
            sendBroadcast(commandIntent);

        }
    }

}

From source file:me.spadival.podmode.PodModeService.java

@Override
public void onDestroy() {
    // Service is being killed, so make sure we release our resources
    mState = State.Stopped;/*from  w w w . ja va2s .  co m*/
    mPodRunning = false;

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

    if ((mPodStatus == podStat.SIMPLEREMOTE || mPodStatus == podStat.ADVANCEDHACK) && am.isMusicActive()) {
        broadcastMediaButtons(KeyEvent.KEYCODE_MEDIA_STOP, null);
    }

    // Stop the timer task
    if (mMediaChangeTimer != null)
        mMediaChangeTimer.cancel();

    // Stop the main thread
    if (mMainThread != null) {
        Thread moribund = mMainThread;
        mMainThread = null;
        moribund.interrupt();
    }

    // mProvider.dropRemoteControls(true);

    relaxResources(true);
    giveUpAudioFocus();

    if (mSerialHost != null)
        mSerialHost.end();

    if (mSerialDevice != null)
        mSerialDevice.DestroyAccessory(true);

    if (mBTDevice != null)
        mBTDevice.stop();

    if (podWakeLock != null)
        podWakeLock.release();

    unregisterReceiver(mUsbReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mNotifyReceiver);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    mRetriever.saveState(prefs, mNowPlaying);
    super.onDestroy();
}