android收音机流电话状态扬声器

时间:2014-11-06 12:12:57

标签: android stream radio speaker

我用服务开发基本的无线电流应用。来电后,无线电流继续但声音播放顶级扬声器。我想从所有扬声器播放。如何做到这一点?

1 个答案:

答案 0 :(得分:0)

private final PhoneStateListener phoneListener = new PhoneStateListener() {



@Override
public void onCallStateChanged(int state, String incomingNumber) {
    try {
        switch (state) {
        case TelephonyManager.CALL_STATE_RINGING: {
            //PAUSE
            if(BackgroundAudioService.mediaPlayer!=null){

                BackgroundAudioService.mediaPlayer.pause();}
            Log.i("pause","pause");
        break;
        }
        case TelephonyManager.CALL_STATE_OFFHOOK: {

        break;
        }
        case TelephonyManager.CALL_STATE_IDLE: {
            //PLAY
            if(BackgroundAudioService.mediaPlayer!=null){
                BackgroundAudioService.mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);                   
                BackgroundAudioService.mediaPlayer.start();
                Log.i("play","play");
                }               
        break;
        }
        default: { }
        }
        } catch (Exception ex) {

        }

    }
};