Java Code Examples for android.media.AudioManager#ACTION_AUDIO_BECOMING_NOISY

The following examples show how to use android.media.AudioManager#ACTION_AUDIO_BECOMING_NOISY . 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: ReadAloudService.java    From a with GNU General Public License v3.0 5 votes vote down vote up
private void initBroadcastReceiver() {
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
                pauseReadAloud(true);
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(broadcastReceiver, intentFilter);
}
 
Example 2
Source File: AudioEarPhoneReceiver.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    if(action!=null && action.length()>0){
        switch (action){
            //来电/耳机拔出时暂停播放
            case AudioManager.ACTION_AUDIO_BECOMING_NOISY:
                PlayService.startCommand(context, MusicPlayAction.TYPE_START_PAUSE);
                break;
            default:
                break;
        }
    }
}
 
Example 3
Source File: ReadAloudService.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void initBroadcastReceiver() {
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
                pauseReadAloud(true);
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(broadcastReceiver, intentFilter);
}
 
Example 4
Source File: AudioBookPlayService.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void initBroadcastReceiver() {
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
                pausePlay();
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(broadcastReceiver, intentFilter);
}
 
Example 5
Source File: EarphoneProtector.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean start(Object obj) {
	mReceiver = new EarphoneBroadcastReceiver();
	IntentFilter filter = new IntentFilter(
			AudioManager.ACTION_AUDIO_BECOMING_NOISY);
	getmServiceContext().registerReceiver(mReceiver, filter);
	return true;
}
 
Example 6
Source File: MusicController.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void initView() {
    // Music controller
    musicPlay = mActivity.findViewById(R.id.playerPlay);
    ImageButton musicStop = mActivity.findViewById(R.id.playerStop);
    ImageButton musicNext = mActivity.findViewById(R.id.playerNext);
    ImageButton musicPrevious = mActivity.findViewById(R.id.playerPrevious);
    ImageButton musicList = mActivity.findViewById(R.id.playerList);
    musicReplay = mActivity.findViewById(R.id.playerLoop);
    //playerTopLayout = (LinearLayout) mActivity.findViewById(R.id.playerTopLayout);

    barSongTitle = mActivity.findViewById(R.id.playerSongTitle);
    barSongTitle.setSingleLine(true);
    barSongTitle.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    barSongTitle.setHorizontallyScrolling(true);
    barSongTitle.setSelected(true);

    seekProgressBar = mActivity.findViewById(R.id.playerSeekBar);
    seekProgressBar.setMax(100);
    seekProgressBar.setProgress(0);

    barSongTime = mActivity.findViewById(R.id.playerSongProgress);

    musicPlay.setOnClickListener(playerClick);
    musicStop.setOnClickListener(playerClick);
    musicNext.setOnClickListener(playerClick);
    musicPrevious.setOnClickListener(playerClick);
    musicList.setOnClickListener(playerClick);
    musicReplay.setOnClickListener(playerClick);
    //playerTopLayout.setOnTouchListener(progressBarTouch);
    seekProgressBar.setOnSeekBarChangeListener(seekBarTouch);

    myNoisyAudioStreamReceiver = new NoisyAudioStreamReceiver();
    intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);

}
 
Example 7
Source File: RadioPlaybackService.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Timber.i("onReceive, Intent: %s, Extras:%s", intent.toString(), intent.getExtras()==null ? null : intent.getExtras().toString());
    switch (intent.getAction()) {
        case ACTION_PLAY:
            player.play();
            break;
        case ACTION_NEXT:
            player.next();
            break;
        case ACTION_PREVIOUS:
            player.previous();
            break;
        case ACTION_SEEK_TO_POSITION:
            int position = intent.getIntExtra(EXTRA_POSITION, 0);
            Timber.d("ACTION_SEEK_TO_POSITION, position:%d", position);
            player.seekToPosition(position);
            break;
        case ACTION_SEEK_TO_PERCENT:
            int percent = intent.getIntExtra(EXTRA_PERCENT, 0);
            player.seekToPosition(percent);
            break;
        case ACTION_STOP:
            player.stop();
            break;
        case ACTION_PAUSE:
            player.pause();
            break;
        case AudioManager.ACTION_AUDIO_BECOMING_NOISY:
            player.pause();
            break;

    }
}
 
Example 8
Source File: ReadAloudService.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
private void initBroadcastReceiver() {
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
                pauseReadAloud(true);
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(broadcastReceiver, intentFilter);
}
 
Example 9
Source File: MediaPlaybackService.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
private void registerNoisyReceiver() {
  IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
  registerReceiver(mNoisyAudioStreamReceiver, filter);
}
 
Example 10
Source File: MediaNotificationManager.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(mAudioBecomingNoisyReceiver, filter);
}
 
Example 11
Source File: MediaNotificationManager.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(mAudioBecomingNoisyReceiver, filter);
}
 
Example 12
Source File: PlaybackService.java    From odyssey with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final String intentAction = intent.getAction();
    if (intentAction != null) {
        switch (intentAction) {
            case AudioManager.ACTION_AUDIO_BECOMING_NOISY:
                /*
                    Check if audio focus is currently lost. For example an incoming call gets picked up
                    and now the user disconnects the headphone. The music should not resume when the call
                    is finished and the audio focus is regained.
                 */
                if (mLostAudioFocus) {
                    mLostAudioFocus = false;
                }
                pause();
                break;
            case ACTION_PLAY:
                resume();
                break;
            case ACTION_PAUSE:
                pause();
                break;
            case ACTION_NEXT:
                setNextTrack();
                break;
            case ACTION_PREVIOUS:
                setPreviousTrack();
                break;
            case ACTION_STOP:
                stop();
                break;
            case ACTION_TOGGLEPAUSE:
                togglePause();
                break;
            case ACTION_QUIT:
                // Ensure state is saved when notification is swiped away
                stopService();
                break;
            case ArtworkManager.ACTION_NEW_ARTWORK_READY:
                // Check if artwork is for currently playing album
                String albumKey = intent.getStringExtra(ArtworkManager.INTENT_EXTRA_KEY_ALBUM_KEY);
                mPlaybackServiceStatusHelper.newAlbumArtworkReady(albumKey);
                break;
            case ACTION_SLEEPSTOP:
                if (mStopAfterCurrent) {
                    stopAfterCurrentTrack();
                } else {
                    stopService();
                }
                break;
        }
    }
}
 
Example 13
Source File: MediaNotificationManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(mAudioBecomingNoisyReceiver, filter);
}
 
Example 14
Source File: AudioBecomingNoisyReceiver.java    From react-native-video with MIT License 4 votes vote down vote up
public void setListener(BecomingNoisyListener listener) {
    this.listener = listener;
    IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    context.registerReceiver(this, intentFilter);
}
 
Example 15
Source File: BackgroundAudioService.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private void initNoisyReceiver() {
    //Handles headphones coming unplugged. cannot be done through a manifest receiver
    IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(mNoisyReceiver, filter);
}