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


Java AudioManager.AUDIOFOCUS_GAIN属性代码示例

本文整理汇总了Java中android.media.AudioManager.AUDIOFOCUS_GAIN属性的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.AUDIOFOCUS_GAIN属性的具体用法?Java AudioManager.AUDIOFOCUS_GAIN怎么用?Java AudioManager.AUDIOFOCUS_GAIN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.media.AudioManager的用法示例。


在下文中一共展示了AudioManager.AUDIOFOCUS_GAIN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            releaseAllVideos();
            Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            try {
                if (JCMediaManager.instance().mediaPlayer != null &&
                        JCMediaManager.instance().mediaPlayer.isPlaying()) {
                    JCMediaManager.instance().mediaPlayer.pause();
                }
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
            Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            break;
    }
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:24,代码来源:JCVideoPlayer.java

示例2: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            onPause();
            Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            try {
                if (MediaManager.instance().mediaPlayer != null &&
                        MediaManager.instance().mediaPlayer.isPlaying()) {
                    MediaManager.instance().mediaPlayer.pause();
                }
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
            Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            break;
    }
}
 
开发者ID:qq1210514049,项目名称:ListVideoPlayer,代码行数:24,代码来源:ListVideoPlayer.java

示例3: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            releaseAllVideos();
            Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            if (JCMediaManager.instance().mediaPlayer != null &&
                    JCMediaManager.instance().mediaPlayer.isPlaying()) {
                JCMediaManager.instance().mediaPlayer.pause();
            }
            Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            break;
    }
}
 
开发者ID:snowwolf10285,项目名称:PicShow-zhaipin,代码行数:20,代码来源:JCVideoPlayer.java

示例4: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS:
            abandonAudioFocus();
            pause();
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            if (mGlue.isMediaPlaying()) {
                pause();
                mPauseTransient = true;
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            mPlayer.mute(true);
            break;
        case AudioManager.AUDIOFOCUS_GAIN:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
            if (mPauseTransient) {
                play();
            }
            mPlayer.mute(false);
            break;
    }
}
 
开发者ID:ad-on-is,项目名称:chilly,代码行数:26,代码来源:PlaybackOverlayFragment.java

示例5: setAudioFocusChangeListener

/**
 * Utility method to generate a listener for changed on Focus. Only available in API Level 8
 * @param player the player which focus will be watched for
 * @return a listener object with associated callbacks for each state.
 */
public static Object setAudioFocusChangeListener(final Player player) {
  Object afChangeListener = (android.media.AudioManager.OnAudioFocusChangeListener) new android
      .media.AudioManager.OnAudioFocusChangeListener() {
    private boolean playbackFlag = false;
    /**
     * This callback method is triggered when audio focus changes. This is necessary because
     * several apps can be managing audio at the same time and for them to interact correctly,
     * they should be using an AudioManager: http://developer.android.com/training/managing-audio/audio-focus.html
     * @param focusChange the type of focus change
     */
    @Override
    public void onAudioFocusChange(int focusChange) {
      switch(focusChange){
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
          // Focus loss transient: Pause playback
          if (player != null && player.playerState == Player.State.PLAYING) {
            player.pause();
            playbackFlag = true;
          }
          break;
        case AudioManager.AUDIOFOCUS_LOSS:
          // Focus loss permanent: focus taken by other players
          playbackFlag = false;
          player.OtherPlayerStarted();
          break;
        case AudioManager.AUDIOFOCUS_GAIN:
          // Focus gain: Resume playback
          if (player != null && playbackFlag && player.playerState == Player.State.PAUSED_BY_EVENT) {
            player.Start();
            playbackFlag = false;
          }
          break;
      }
    }
  };
  return afChangeListener;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:43,代码来源:FroyoUtil.java

示例6: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    if (currentFocus == focusChange) {
        return;
    }

    currentFocus = focusChange;
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
            if (startRequested || pausedForLoss) {
                start();
                startRequested = false;
                pausedForLoss = false;
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            if (isPlaying()) {
                pausedForLoss = true;
                pause();
            }
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            if (isPlaying()) {
                pausedForLoss = true;
                pause();
            }
            break;
    }
}
 
开发者ID:dueeeke,项目名称:dkplayer,代码行数:31,代码来源:BaseIjkVideoView.java

示例7: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            mediaPlayer.start();
            return;
        default:
            releaseMediaPlayer();
            return;
    }
}
 
开发者ID:Velnster,项目名称:Miwok,代码行数:11,代码来源:FamilyFragment.java

示例8: onAudioFocusChange

/**
 * Called by AudioManager on audio focus changes. Implementation of {@link
 * AudioManager.OnAudioFocusChangeListener}.
 */
@Override
public void onAudioFocusChange(int focusChange) {
    boolean gotFullFocus = false;
    boolean canDuck = false;
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        gotFullFocus = true;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
    }

    if (gotFullFocus || canDuck) {
        if (mMediaPlayer != null) {
            if (mPlayOnFocusGain) {
                mPlayOnFocusGain = false;
                mMediaPlayer.start();
                mState = PlaybackStateCompat.STATE_PLAYING;
                updatePlaybackState();
            }
            float volume = canDuck ? 0.2f : 1.0f;
            mMediaPlayer.setVolume(volume, volume);
        }
    } else if (mState == PlaybackStateCompat.STATE_PLAYING) {
        mMediaPlayer.pause();
        mState = PlaybackStateCompat.STATE_PAUSED;
        updatePlaybackState();
    }
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:36,代码来源:PlaybackManager.java

示例9: get

public static AudioPlayerManager get(Context context){
    if(instance ==null){
        instance = new AudioPlayerManager();
        instance.context = context;
        instance.am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        instance.listener = new AudioManager.OnAudioFocusChangeListener() {
            @Override
            public void onAudioFocusChange(int focusChange) {
                if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT){
                    //Log.e("dd"," AUDIOFOCUS_LOSS_TRANSIENT ---------------------");
                    if(instance.state == State.playing){
                        instance.stateBeforeFocusChange = State.playing;
                    }
                    instance.pause();
                    // Pause playback
                } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
                    //Log.e("dd"," AUDIOFOCUS_GAIN ---------------------");
                    if(instance.stateBeforeFocusChange == State.playing){
                        instance.resume();
                    }

                    // Resume playback
                } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
                    //Log.e("dd"," AUDIOFOCUS_LOSS ---------------------");
                    //am.unregisterMediaButtonEventReceiver(RemoteControlReceiver);

                    instance.stop();
                    // Stop playback
                }

            }
        };
        instance.registerHeadsetPlugReceiver();
    }
    return instance;
}
 
开发者ID:hss01248,项目名称:SafeMediaPlayer,代码行数:36,代码来源:AudioPlayerManager.java

示例10: onAudioFocusChange

/**
 * Called by AudioManager on audio focus changes. Implementation of {@link
 * AudioManager.OnAudioFocusChangeListener}
 */
@Override
public void onAudioFocusChange(int focusChange) {
    boolean gotFullFocus = false;
    boolean canDuck = false;
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        gotFullFocus = true;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
    }

    if (gotFullFocus || canDuck) {
        if (mMediaPlayer != null) {
            if (mPlayOnFocusGain) {
                mPlayOnFocusGain = false;
                mMediaPlayer.start();
                mState = PlaybackStateCompat.STATE_PLAYING;
                updatePlaybackState();
            }
            float volume = canDuck ? 0.2f : 1.0f;
            mMediaPlayer.setVolume(volume, volume);
        }
    } else if (mState == PlaybackStateCompat.STATE_PLAYING) {
        mMediaPlayer.pause();
        mState = PlaybackStateCompat.STATE_PAUSED;
        updatePlaybackState();
    }
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:36,代码来源:PlaybackManager.java

示例11: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            mediaSessionCallback.onPlay(); // Не очень красиво
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            mediaSessionCallback.onPause();
            break;
        default:
            mediaSessionCallback.onPause();
            break;
    }
}
 
开发者ID:SergeyVinyar,项目名称:AndroidAudioExample,代码行数:14,代码来源:PlayerService.java

示例12: onAudioFocusChange

public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // Permanent loss of audio focus
        // Pause playback immediately
        mediaPlayer.pause();
        mediaPlayer.seekTo(0);
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        relaseMediaResource();
    } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        mediaPlayer.start();
    }
}
 
开发者ID:AnkurBegining,项目名称:My-Miwok-App,代码行数:12,代码来源:NumbersActivity.java

示例13: onAudioFocusChange

public void onAudioFocusChange(int focusChange) {
    if (mPlayer == null) {
        // this activity has handed its MediaPlayer off to the next activity
        // (e.g. portrait/landscape switch) and should abandon its focus
        mAudioManager.abandonAudioFocus(this);
        return;
    }
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS:
            mPausedByTransientLossOfFocus = false;
            mPlayer.pause();
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            if (mPlayer.isPlaying()) {
                mPausedByTransientLossOfFocus = true;
                mPlayer.pause();
            }
            break;
        case AudioManager.AUDIOFOCUS_GAIN:
            if (mPausedByTransientLossOfFocus) {
                mPausedByTransientLossOfFocus = false;
                start();
            }
            break;
    }
    updatePlayPause();
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:28,代码来源:AudioPreview.java

示例14: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        mMediaPlayer.pause();
        mMediaPlayer.seekTo(0);
    } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        mMediaPlayer.start();
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        releaseMediaPlayer();
    }
}
 
开发者ID:hshah11,项目名称:Lang_Tutor,代码行数:12,代码来源:GujaratiPhrasesActivity.java

示例15: onAudioFocusChange

@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK){
        mMediaPlayer.pause();
        mMediaPlayer.seekTo(0);
    }
    else if (focusChange == AudioManager.AUDIOFOCUS_GAIN){
        mMediaPlayer.start();
    }
    else if(focusChange == AudioManager.AUDIOFOCUS_LOSS){
        releaseMediaPlayer();
    }
}
 
开发者ID:hshah11,项目名称:Lang_Tutor,代码行数:14,代码来源:MarathiNumbersFragment.java


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