当前位置: 首页>>代码示例>>Java>>正文


Java AudioManager.AUDIOFOCUS_REQUEST_GRANTED属性代码示例

本文整理汇总了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;
}
 
开发者ID:n76,项目名称:Symphony,代码行数:21,代码来源:MusicService.java

示例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;
	}
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:25,代码来源:Sound.java

示例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;
    }
}
 
开发者ID:mdnafiskhan,项目名称:Mp3Player,代码行数:19,代码来源:MusicService.java

示例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;
        }
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:24,代码来源:MediaController.java

示例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;
}
 
开发者ID:dueeeke,项目名称:dkplayer,代码行数:23,代码来源:BaseIjkVideoView.java

示例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;
	}
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:7,代码来源:LinphoneManager.java

示例7: removeAudioFocus

public boolean removeAudioFocus() {
    try {
        if (audioManager != null) {
            return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == audioManager.abandonAudioFocus(this);
        }
    } catch (Exception e){
        e.printStackTrace();
    }
    return true;
}
 
开发者ID:htqqdd,项目名称:music_player,代码行数:10,代码来源:PlayService.java

示例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();
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:32,代码来源:MusicPlaybackService.java

示例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();
    }
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:13,代码来源:AudioActivity.java

示例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();
    }
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:15,代码来源:DefaultPlayerGestureOperationCover.java

示例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);
    }

}
 
开发者ID:rodrigonsh,项目名称:alerta-fraude,代码行数:13,代码来源:AudioHandler.java

示例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;
    }
}
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:10,代码来源:AudioPlaybackListener.java

示例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);
    }
}
 
开发者ID:R-a-dio,项目名称:R-a-dio-Amazing-Android-App,代码行数:14,代码来源:RadioService.java

示例15: requestFocus

private boolean requestFocus() {
    int result = mAudioManager.requestAudioFocus(this,
            AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:6,代码来源:PlayerService.java


注:本文中的android.media.AudioManager.AUDIOFOCUS_REQUEST_GRANTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。