本文整理汇总了Java中android.media.AudioManager.requestAudioFocus方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.requestAudioFocus方法的具体用法?Java AudioManager.requestAudioFocus怎么用?Java AudioManager.requestAudioFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.requestAudioFocus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LivePlayerHolder
import android.media.AudioManager; //导入方法依赖的package包/类
public LivePlayerHolder(BaseTvShowActivity mActivity, SurfaceView surfaceView, Integer codec, String mVideoPath) {
this.mActivity = mActivity;
this.codec = codec;
this.mVideoPath = mVideoPath;
this.mSurfaceView = surfaceView;
//init
mSurfaceView.getHolder().addCallback(mCallback);
mAVOptions = new AVOptions();
mAVOptions.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000);
mAVOptions.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000);
mAVOptions.setInteger(AVOptions.KEY_LIVE_STREAMING, 1);
mAVOptions.setInteger(AVOptions.KEY_DELAY_OPTIMIZATION, 1);
mAVOptions.setInteger(AVOptions.KEY_MEDIACODEC, codec);
// whether start play automatically after prepared, default value is 1
mAVOptions.setInteger(AVOptions.KEY_START_ON_PREPARED, 0);
AudioManager audioManager = (AudioManager) App.getAppContext().getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
}
示例2: prepareVideo
import android.media.AudioManager; //导入方法依赖的package包/类
public void prepareVideo() {
Log.d(TAG, "prepareVideo [" + this.hashCode() + "] ");
// 解决全屏模式下的CURRENT_STATE_ERROR状态下, 点击重新加载后退出了全屏模式.
// 间接解决因为mediaplayer状态混乱(全屏模式下会prepare, 全屏模式被退出后小窗口状态异常,被点击后容易导致)引起的App Crash问题
if (currentScreen != SCREEN_WINDOW_FULLSCREEN) {
if (JCVideoPlayerManager.listener() != null) {
JCVideoPlayerManager.listener().onCompletion();
}
}
JCVideoPlayerManager.setListener(this);
addTextureView();
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
JCUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
JCMediaManager.instance().prepare(url, mapHeadData, looping);
JCMediaManager.instance().bufferPercent = 0;
JCMediaManager.instance().videoRotation = 0;
setUiWitStateAndScreen(CURRENT_STATE_PREPARING);
}
示例3: requestAudioFocus
import android.media.AudioManager; //导入方法依赖的package包/类
private boolean requestAudioFocus() {
try {
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int result = audioManager.requestAudioFocus(this, STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Log.v("焦点获得", "获得2");
return true;
}
}catch (Exception e){
e.printStackTrace();
}
//Could not gain focus
return false;
}
示例4: initializeAudioForCall
import android.media.AudioManager; //导入方法依赖的package包/类
public void initializeAudioForCall() {
AudioManager audioManager = ServiceUtil.getAudioManager(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE);
} else {
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
}
示例5: startVideo
import android.media.AudioManager; //导入方法依赖的package包/类
public void startVideo() {
JZVideoPlayerManager.completeAll();
Log.d(TAG, "startVideo [" + this.hashCode() + "] ");
initTextureView();
addTextureView();
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
JZUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
JZMediaManager.setDataSource(dataSourceObjects);
JZMediaManager.setCurrentDataSource(JZUtils.getCurrentFromDataSource(dataSourceObjects, currentUrlMapIndex));
JZMediaManager.instance().positionInList = positionInList;
onStatePreparing();
JZVideoPlayerManager.setFirstFloor(this);
}
示例6: prepareMediaPlayer
import android.media.AudioManager; //导入方法依赖的package包/类
public void prepareMediaPlayer() {
JCVideoPlayerManager.completeAll();
Log.d(TAG, "prepareMediaPlayer [" + this.hashCode() + "] ");
initTextureView();
addTextureView();
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
JCUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
JCMediaManager.CURRENT_PLAYING_URL = url;
JCMediaManager.CURRENT_PLING_LOOP = loop;
JCMediaManager.MAP_HEADER_DATA = headData;
setUiWitStateAndScreen(CURRENT_STATE_PREPARING);
JCVideoPlayerManager.setFirstFloor(this);
}
示例7: requestAudioFocus
import android.media.AudioManager; //导入方法依赖的package包/类
/**
* AudioFocus
*/
private boolean requestAudioFocus() {
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
//Focus gained
return true;
}
//Could not gain focus
return false;
}
示例8: onCreate
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// initialize default output device
if (!BASS.BASS_Init(-1, 44100, 0)) {
return;
}
// look for plugins
plugins = "";
String path = getApplicationInfo().nativeLibraryDir;
String[] list = new File(path).list();
for (String s: list) {
int plug = BASS.BASS_PluginLoad(path+"/"+s, 0);
if (plug != 0) { // plugin loaded...
plugins += s + "\n"; // add it to the list
}
}
if (plugins.equals(""))
plugins = "no plugins - visit the BASS webpage to get some\n";
if(playerInterface != null) {
playerInterface.onPluginsLoaded(plugins);
}
BASS.BASS_SetConfig(BASS.BASS_CONFIG_BUFFER, 1000);
Log.w("BASS.BASS_CONFIG_BUFFER", "" + BASS.BASS_GetConfig(BASS.BASS_CONFIG_BUFFER));
// Pending Intend
Intent intent = new Intent(this, NavigationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendIntent = PendingIntent.getActivity(this, 0, intent, 0);
//tracklist
loadTracks();
loadEqualizerValues();
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(telephone, PhoneStateListener.LISTEN_CALL_STATE);
myBroadcastReceiver = new ServiceBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION");
intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
registerReceiver(myBroadcastReceiver, intentFilter);
ComponentName rcvMedia = new ComponentName(getPackageName(), MediaControlReceiver.class.getName());
mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
mAudioManager.registerMediaButtonEventReceiver(rcvMedia);
// Use the remote control APIs (if available) to set the playback state
if (Build.VERSION.SDK_INT >= 14 && remoteControlClient == null) {
registerRemoteControl(rcvMedia);
}
}
示例9: getAudioFocus
import android.media.AudioManager; //导入方法依赖的package包/类
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);
}
}
示例10: prepareMediaPlayer
import android.media.AudioManager; //导入方法依赖的package包/类
public void prepareMediaPlayer() {
JCVideoPlayerManager.completeAll();
Log.d(TAG, "prepareMediaPlayer [" + this.hashCode() + "] ");
initTextureView();
addTextureView();
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
JCUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
JCMediaManager.CURRENT_PLAYING_URL = url;
JCMediaManager.CURRENT_PLING_LOOP = loop;
setUiWitStateAndScreen(CURRENT_STATE_PREPARING);
JCVideoPlayerManager.setFirstFloor(this);
}
示例11: initAudioManager
import android.media.AudioManager; //导入方法依赖的package包/类
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();
}
}
示例12: initializeAudioForCall
import android.media.AudioManager; //导入方法依赖的package包/类
public void initializeAudioForCall() {
AudioManager audioManager = ServiceUtil.getAudioManager(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE);
} else {
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
}
示例13: startVideo
import android.media.AudioManager; //导入方法依赖的package包/类
public void startVideo() {
JCVideoPlayerManager.completeAll();
Log.d(TAG, "startVideo [" + this.hashCode() + "] ");
initTextureView();
addTextureView();
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
JCUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
JCMediaManager.CURRENT_PLAYING_URL = url;
JCMediaManager.CURRENT_PLING_LOOP = loop;
JCMediaManager.MAP_HEADER_DATA = headData;
onStatePreparing();
JCVideoPlayerManager.setFirstFloor(this);
}
示例14: prepareMediaPlayer
import android.media.AudioManager; //导入方法依赖的package包/类
protected void prepareMediaPlayer() {
VideoPlayerManager.getInstance().completeAll();
initTextureView();
addTextureView();
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
ListVideoUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
MediaManager.CURRENT_PLAYING_URL = url;
onStateAction(CURRENT_STATE_PREPARING);
VideoPlayerManager.getInstance().setCurrentVideoPlayer(this);
}
示例15: createPlayer
import android.media.AudioManager; //导入方法依赖的package包/类
private IParsingPlayer createPlayer(Context context) {
mCurrentState = STATE_IDLE;
IParsingPlayer iParsingPlayer = new ParsingPlayer();
AudioManager audioManager = (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
iParsingPlayer.setOnPreparedListener(this);
iParsingPlayer.setOnVideoSizeChangedListener(this);
iParsingPlayer.setOnCompletionListener(this);
iParsingPlayer.setOnErrorListener(this);
iParsingPlayer.setOnInfoListener(this);
iParsingPlayer.setOnBufferingUpdateListener(this);
iParsingPlayer.setOnSeekCompleteListener(this);
return iParsingPlayer;
}