本文整理汇总了Java中android.media.AudioManager.AUDIOFOCUS_REQUEST_GRANTED属性的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.AUDIOFOCUS_REQUEST_GRANTED属性的具体用法?Java AudioManager.AUDIOFOCUS_REQUEST_GRANTED怎么用?Java AudioManager.AUDIOFOCUS_REQUEST_GRANTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.AUDIOFOCUS_REQUEST_GRANTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: go
public synchronized void go() {
Log.d(TAG,"go() entry.");
if (currentTrackPlayer != null) {
deferredGo = false;
if (!haveAudioFocus) {
int result = am.requestAudioFocus(afChangeListener,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN);
haveAudioFocus = (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
}
if (haveAudioFocus) {
registerReceiver(myNoisyAudioStreamReceiver, intentFilter);
noisyReceiverRegistered = true;
currentTrackPlayer.start();
tellTheWorld(SERVICE_NOW_PLAYING);
}
} else
deferredGo = true;
}
示例2: requestFocus
private void requestFocus() {
SharedPreferences prefs;
try{
prefs = PreferenceManager.getDefaultSharedPreferences(host);
} catch(Exception e) {
noFocus = true;
return;
}
if(prefs == null) {
noFocus = true;
return;
}
if(prefs.getInt("pref_musicvolume", 60) > 0) {
int result = audioCEO.requestAudioFocus(this,
// Use the music stream.
AudioManager.STREAM_RING,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
noFocus = false;
} else
noFocus = true;
}
}
示例3: requestAudioFocusForMyApp
private boolean requestAudioFocusForMyApp(final Context context) {
AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
// am.registerMediaButtonEventReceiver(new ComponentName(this, MediaButtonReceiver.class));
// Request audio focus for playback
int result = am.requestAudioFocus(this,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.d("AudioFocus", "Audio focus received");
return true;
} else {
Log.d("AudioFocus", "Audio focus NOT received");
return false;
}
}
示例4: checkAudioFocus
private void checkAudioFocus(MessageObject messageObject) {
int neededAudioFocus;
if (messageObject.isVoice()) {
if (useFrontSpeaker) {
neededAudioFocus = 3;
} else {
neededAudioFocus = 2;
}
} else {
neededAudioFocus = 1;
}
if (hasAudioFocus != neededAudioFocus) {
hasAudioFocus = neededAudioFocus;
int result;
if (neededAudioFocus == 3) {
result = NotificationsController.getInstance().audioManager.requestAudioFocus(this, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
} else {
result = NotificationsController.getInstance().audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, neededAudioFocus == 2 ? AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK : AudioManager.AUDIOFOCUS_GAIN);
}
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
audioFocus = AUDIO_FOCUSED;
}
}
}
示例5: requestFocus
/**
* Requests to obtain the audio focus
*
* @return True if the focus was granted
*/
boolean requestFocus() {
if (currentFocus == AudioManager.AUDIOFOCUS_GAIN) {
return true;
}
if (mAudioManager == null) {
return false;
}
int status = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (AudioManager.AUDIOFOCUS_REQUEST_GRANTED == status) {
currentFocus = AudioManager.AUDIOFOCUS_GAIN;
return true;
}
startRequested = true;
return false;
}
示例6: requestAudioFocus
private void requestAudioFocus(int stream){
if (!mAudioFocused){
int res = mAudioManager.requestAudioFocus(null, stream, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT );
Log.d("Audio focus requested: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) mAudioFocused=true;
}
}
示例7: removeAudioFocus
public boolean removeAudioFocus() {
try {
if (audioManager != null) {
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == audioManager.abandonAudioFocus(this);
}
} catch (Exception e){
e.printStackTrace();
}
return true;
}
示例8: play
public void play() {
int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (D) {
Logger.d(TAG, "Starting playback: audio focus request status = " + status);
}
if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
return;
}
mAudioManager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));
if (mPlayer != null && mPlayer.isInitialized()) {
final long duration = mPlayer.duration();
if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) {
gotoNext(false);
}
mPlayer.start();
mPlayerHandler.removeMessages(FADEDOWN);
mPlayerHandler.sendEmptyMessage(FADEUP);
if (!mIsSupposedToBePlaying) {
mIsSupposedToBePlaying = true;
notifyChange(PLAYSTATE_CHANGED);
}
cancelShutdown();
updateNotification();
}
}
示例9: startPlayback
private void startPlayback() {
try {
if (audioPlay == null)
initAudioPlayer();
int result = audioMgr.requestAudioFocus(audioFocusListener,
AudioManager.STREAM_MUSIC, AudioManager
.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
audioPlay.start();
} catch (IOException ioe) {
Snackbar.make(recordBtn, "Unable to initialize Audio", Snackbar.LENGTH_LONG).show();
}
}
示例10: initAudioManager
private void initAudioManager(Context context) {
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mMaxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
// Request audio focus for playback
int result = audioManager.requestAudioFocus(afChangeListener,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
// Start playback.
abandonAudioManagerFocus();
}
}
示例11: getAudioFocus
public void getAudioFocus() {
String TAG2 = "AudioHandler.getAudioFocus(): Error : ";
AudioManager am = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
int result = am.requestAudioFocus(focusChangeListener,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
LOG.e(TAG2,result + " instead of " + AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
}
}
示例12: tryToGetAudioFocus
private void tryToGetAudioFocus() {
Logger.d(TAG, "tryToGetAudioFocus");
int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
mAudioFocus = AUDIO_FOCUSED;
} else {
mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
}
}
示例13: speak
@ReactMethod
public void speak(String utterance, String queueMode, Promise promise) {
if(notReady(promise)) return;
if(IS_DUCKING) {
int amResult = audioManager.requestAudioFocus(afChangeListener,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
if(amResult != AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
promise.reject("error", "Android AudioManager error, failed to request audio focus");
}
String utteranceId = Integer.toString(utterance.hashCode());
int mode = TextToSpeech.QUEUE_ADD;
if(queueMode.equals("ADD"))
mode = TextToSpeech.QUEUE_ADD;
else if(queueMode.equals("FLUSH"))
mode = TextToSpeech.QUEUE_FLUSH;
int speakResult = speak(utterance, mode, utteranceId);
if(speakResult == TextToSpeech.SUCCESS) {
promise.resolve(utteranceId);
} else {
promise.reject("error", "Unable to play. Error at speak(utterance, queueMode)");
}
}
开发者ID:echo8795,项目名称:react-native-android-text-to-speech,代码行数:28,代码来源:RNAndroidTextToSpeechModule.java
示例14: beginPlaying
public void beginPlaying() {
int result = am.requestAudioFocus(focusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
PlayerState.CURRENTLY_PLAYING = true;
createNotification();
setupMediaPlayer();
if(sep != null)
sep.setPlayWhenReady(true);
acquireWakeLocks();
startForeground(1, notification);
}
}
示例15: requestFocus
private boolean requestFocus() {
int result = mAudioManager.requestAudioFocus(this,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN);
return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}