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


Java AudioManager.requestAudioFocus方法代码示例

本文整理汇总了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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:LivePlayerHolder.java

示例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);
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:21,代码来源:JCVideoPlayer.java

示例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;
}
 
开发者ID:htqqdd,项目名称:music_player,代码行数:15,代码来源:PlayService.java

示例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);
    }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:10,代码来源:SignalAudioManager.java

示例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);
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:16,代码来源:JZVideoPlayer.java

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

示例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;
}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:14,代码来源:AudioService.java

示例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);
       }
}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:57,代码来源:PlayerService.java

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

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

示例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);
}
 
开发者ID:snowwolf10285,项目名称:PicShow-zhaipin,代码行数:14,代码来源:JCVideoPlayer.java

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

示例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);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:10,代码来源:SignalAudioManager.java

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

示例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);
}
 
开发者ID:qq1210514049,项目名称:ListVideoPlayer,代码行数:12,代码来源:ListVideoPlayer.java

示例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;
}
 
开发者ID:TedaLIEz,项目名称:ParsingPlayer,代码行数:15,代码来源:ParsingPlayerProxy.java


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