Java Code Examples for android.media.AudioManager#isMusicActive()

The following examples show how to use android.media.AudioManager#isMusicActive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioManagerUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是否有音乐处于活跃状态
 * @return {@code true} yes, {@code false} no
 */
public static boolean isMusicActive() {
    AudioManager audioManager = AppUtils.getAudioManager();
    if (audioManager != null) {
        try {
            return audioManager.isMusicActive();
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "isMusicActive");
        }
    }
    return false;
}
 
Example 2
Source File: CallAndSmsPresenter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
/**
 * 手机摇晃事件处理
 **/
public boolean shakeHandle() {
    if (!SynthesizerBase.isInited())
        return false;
    if (communicationTimer != null) {
        sendMessageToRobot("取消");
        return true;
    } else if (!AppConfig.dPreferences.getBoolean(AppConfig.SHAKE_WAKE, false)) {
        return false;
    } else if (SynthesizerBase.get().isSpeaking()) {
        SynthesizerBase.get().stopSpeaking();
        return true;
    }
    AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    if (am != null) {
        if (am.isMusicActive()) {
            /* 停止播放音乐 */
            Intent intent = new Intent(mContext, AssistantService.class);
            intent.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.PAUSE_PLAY);
            mContext.startService(intent);
            /* 停止识别、合成,尝试唤醒 */
            Intent voiceIntent = new Intent(mContext, AssistantService.class);
            voiceIntent.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.SEND_TO_ROBOT_FOR_END_TASK);
            voiceIntent.putExtra(AssistantService.END_TASK, false);
            mContext.startService(voiceIntent);
            return true;
        }
    }

    return false;
}
 
Example 3
Source File: MusicPlayer.java    From always-on-amoled with GNU General Public License v3.0 5 votes vote down vote up
public MusicPlayer(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layout = inflater.inflate(R.layout.music_widget, null);
    addView(layout);
    findViewById(R.id.skip_prev).setOnClickListener(this);
    findViewById(R.id.play).setOnClickListener(this);
    findViewById(R.id.skip_next).setOnClickListener(this);

    IntentFilter iF = new IntentFilter();
    iF.addAction("com.android.music.metachanged");
    iF.addAction("com.android.music.playstatechanged");
    iF.addAction("com.htc.music.metachanged");
    iF.addAction("fm.last.android.metachanged");
    iF.addAction("com.sec.android.app.music.metachanged");
    iF.addAction("com.nullsoft.winamp.metachanged");
    iF.addAction("com.amazon.mp3.metachanged");
    iF.addAction("com.miui.player.metachanged");
    iF.addAction("com.real.IMP.metachanged");
    iF.addAction("com.sonyericsson.music.metachanged");
    iF.addAction("com.rdio.android.metachanged");
    iF.addAction("com.samsung.sec.android.MusicPlayer.metachanged");
    iF.addAction("com.andrew.apollo.metachanged");

    context.registerReceiver(mReceiver, iF);
    try {
        AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (!manager.isMusicActive())
            removeView(layout);
        else
            updatePlayPauseButton(true);
    } catch (UnsupportedOperationException e) {
        Utils.logInfo(MusicPlayer.class.getSimpleName(), "Can't connect to music service");
        removeView(layout);
    }
}
 
Example 4
Source File: MusicPlayer.java    From always-on-amoled with GNU General Public License v3.0 5 votes vote down vote up
private void updatePlayPauseButton(boolean reverse) {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (!am.isMusicActive())
        ((AppCompatImageView) findViewById(R.id.play)).setImageResource(reverse ? R.drawable.ic_play : R.drawable.ic_pause);
    else
        ((AppCompatImageView) findViewById(R.id.play)).setImageResource(reverse ? R.drawable.ic_pause : R.drawable.ic_play);
}
 
Example 5
Source File: SpeechUtil.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private static boolean isMusicPlaying() {
    final AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE);
    try {
        return manager.isMusicActive();
    } catch (NullPointerException e) {
        return false;
    }
}
 
Example 6
Source File: SpeechUtil.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private static boolean isMusicPlaying() {
    final AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE);
    try {
        return manager.isMusicActive();
    } catch (NullPointerException e) {
        return false;
    }
}
 
Example 7
Source File: MediaUtil.java    From Android with MIT License 4 votes vote down vote up
public boolean isPlayVoive() {
    AudioManager mAudioManager = (AudioManager) BaseApplication.getInstance().getBaseContext().
            getSystemService(Context.AUDIO_SERVICE);
    return mAudioManager.isMusicActive();
}
 
Example 8
Source File: MusicPlayer.java    From Jockey with Apache License 2.0 4 votes vote down vote up
@Internal boolean shouldResumeOnHeadphonesConnect() {
    AudioManager manager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    return mResumeOnHeadphonesConnect && (mFocused || !manager.isMusicActive());
}