Ignored for app to get exclusive access to the device output sound card, first app needs to request the Audio service for focus change
The code is like below.
AudioManager am = (AudioManager)(AppUtils.getAppContext()).getSystemService(Context.AUDIO_SERVICE);
int result = am.requestAudioFocus(new AudioManager.OnAudioFocusChangeListener(){
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
}
}
},
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
// Start playback.
Intent objIntent = new Intent(AppUtils.getAppContext(), AudioPlayerService.class);
AppUtils.getAppContext().startService(objIntent);
References:
No comments:
Post a Comment