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


Java AudioManager类代码示例

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


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

示例1: shouldBeep

import android.media.AudioManager; //导入依赖的package包/类
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
	boolean shouldPlayBeep = true;
	if (shouldPlayBeep) {
		// See if sound settings overrides this
		AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
		if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
			shouldPlayBeep = false;
		}
	}
	return shouldPlayBeep;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:12,代码来源:BeepManager.java

示例2: buildMediaPlayer

import android.media.AudioManager; //导入依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:22,代码来源:BeepManager.java

示例3: buildMediaPlayer

import android.media.AudioManager; //导入依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(this.rawBeep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    } finally {
      file.close();
    }
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setLooping(false);
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
    return mediaPlayer;
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer.release();
    return null;
  }
}
 
开发者ID:10045125,项目名称:QrCode,代码行数:22,代码来源:BeepManager.java

示例4: buildRenderers

import android.media.AudioManager; //导入依赖的package包/类
@Override
public void buildRenderers(DemoPlayer player) {
  Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
  Handler mainHandler = player.getMainHandler();

  // Build the video and audio renderers.
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, null);
  DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator,
      BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, mainHandler, player, 0);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
      sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      mainHandler, player, 50);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
      MediaCodecSelector.DEFAULT, null, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);
  TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, player,
      mainHandler.getLooper());

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:27,代码来源:ExtractorRendererBuilder.java

示例5: onAudioFocusChange

import android.media.AudioManager; //导入依赖的package包/类
@Override
public void onAudioFocusChange(int focusChange) {
    if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT ||
            focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // The AUDIOFOCUS_LOSS_TRANSIENT case means that we've lost audio focus for a
        // short amount of time. The AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK case means that
        // our app is allowed to continue playing sound but at a lower volume. We'll treat
        // both cases the same way because our app is playing short sound files.

        // Pause playback and reset player to the start of the file. That way, we can
        // play the word from the beginning when we resume playback.
        mMediaPlayer.pause();
        mMediaPlayer.seekTo(0);
    } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        // The AUDIOFOCUS_GAIN case means we have regained focus and can resume playback.
        mMediaPlayer.start();
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
        // The AUDIOFOCUS_LOSS case means we've lost audio focus and
        // Stop playback and clean up resources
        releaseMediaPlayer();
    }
}
 
开发者ID:rahularity,项目名称:miwokapp,代码行数:23,代码来源:PhrasesActivity.java

示例6: release

import android.media.AudioManager; //导入依赖的package包/类
public void release(boolean cleartargetstate) {
    if (mPlayer != null) {
        mPlayer.reset();
        mPlayer.release();
        mPlayer = null;
        // REMOVED: mPendingSubtitleTracks.clear();
        mCurrentState = STATE_IDLE;
        if (cleartargetstate) {
            mTargetState = STATE_IDLE;
        }
        AudioManager am = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);
        am.abandonAudioFocus(null);
        // TODO: 2017/1/11
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(this);
            mHandler = null;
        }
    }
}
 
开发者ID:SethWen,项目名称:GestureVideoView,代码行数:20,代码来源:GestureVideoView.java

示例7: execute

import android.media.AudioManager; //导入依赖的package包/类
@Override
public void execute(AudioManager audioManager) {
    if (voiceMediator.isBlueToothHeadSet()) {
        if (!voiceMediator.isSuportA2DP()) {
            if (audioManager.getMode() != AudioManager.MODE_NORMAL) {
                Log.e(TAG, "playInChannel>>setMode(AudioManager.MODE_NORMAL)");
                audioManager.setMode(AudioManager.MODE_NORMAL);
            }
            if (audioManager.isBluetoothScoOn()) {
                audioManager.setBluetoothScoOn(false);
                audioManager.stopBluetoothSco();
            }
        } else {
            if (!audioManager.isBluetoothA2dpOn()) {
                Log.e(TAG, "playInChannel>>setBluetoothA2dpOn(true)");
                audioManager.setBluetoothA2dpOn(true);
            }
        }
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:21,代码来源:AssistantService.java

示例8: onAudioFocusChange

import android.media.AudioManager; //导入依赖的package包/类
public void onAudioFocusChange(int focusChange) {
    switch (focusChange) {

        case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) :
            if(sep != null)
                sep.setVolume(0.2f);
            break;
        case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) :
            mutePlayer();
            break;

        case (AudioManager.AUDIOFOCUS_LOSS) :
            stopPlaying();
            break;

        case (AudioManager.AUDIOFOCUS_GAIN) :
            unmutePlayer();
            break;
        default: break;
    }
}
 
开发者ID:R-a-dio,项目名称:R-a-dio-Amazing-Android-App,代码行数:22,代码来源:RadioService.java

示例9: onCompletion

import android.media.AudioManager; //导入依赖的package包/类
public void onCompletion() {
        Log.i(TAG, "onCompletion " + " [" + this.hashCode() + "] ");
        //save position
        if (currentState == CURRENT_STATE_PLAYING || currentState == CURRENT_STATE_PAUSE) {
            int position = getCurrentPositionWhenPlaying();
//            int duration = getDuration();
            JCUtils.saveProgress(getContext(), url, position);
        }
        cancelProgressTimer();
        setUiWitStateAndScreen(CURRENT_STATE_NORMAL);
        // 清理缓存变量
        textureViewContainer.removeView(JCMediaManager.textureView);
        JCMediaManager.instance().currentVideoWidth = 0;
        JCMediaManager.instance().currentVideoHeight = 0;

        AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
        mAudioManager.abandonAudioFocus(onAudioFocusChangeListener);
        JCUtils.scanForActivity(getContext()).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        clearFullscreenLayout();
        JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(NORMAL_ORIENTATION);

        JCMediaManager.textureView = null;
        JCMediaManager.savedSurfaceTexture = null;
    }
 
开发者ID:Longalei,项目名称:Edu,代码行数:25,代码来源:JCVideoPlayer.java

示例10: createAudioPlugReceiver

import android.media.AudioManager; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private BroadcastReceiver createAudioPlugReceiver() {
    return new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (action == null)
                return;
            if (action.equalsIgnoreCase(AudioManager.ACTION_HDMI_AUDIO_PLUG)) {
                final boolean hasHdmi = intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) == 1;
                final long encodingFlags = !hasHdmi ? 0 :
                        getEncodingFlags(intent.getIntArrayExtra(AudioManager.EXTRA_ENCODINGS));
                updateAudioOutputDevice(encodingFlags, "stereo");
            }
        }
    };
}
 
开发者ID:pedroSG94,项目名称:vlc-example-streamplayer,代码行数:18,代码来源:MediaPlayer.java

示例11: onKeyDown

import android.media.AudioManager; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        //call on back button
        onBackPressed();

    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && !AppPreference.isVolumeKeyNavigation()) {
        //volume down
        audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 1);
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && !AppPreference.isVolumeKeyNavigation()) {
        //volume up
        audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 1);
    }
    return true;
}
 
开发者ID:fekracomputers,项目名称:QuranAndroid,代码行数:17,代码来源:QuranPageReadActivity.java

示例12: playClick

import android.media.AudioManager; //导入依赖的package包/类
/**
 * Play sound on key press
 *
 * @param keyCode of pressed key
 */
private void playClick(int keyCode) {
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    switch (keyCode) {
        case Constants.KeyCode.SPACE:
            am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
            break;
        case Keyboard.KEYCODE_DONE:
            am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
            break;
        case Constants.KeyCode.RETURN:
            am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
            break;
        case Keyboard.KEYCODE_DELETE:
            am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
            break;
        default:
            am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
            break;
    }
}
 
开发者ID:Medeuz,项目名称:CustomAndroidKeyboard,代码行数:26,代码来源:SimpleIME.java

示例13: play

import android.media.AudioManager; //导入依赖的package包/类
/**
         * 播放
         */
        private void play(SurfaceHolder surfaceHolder,String videoPath){
            mediaPlayer = new MediaPlayer();
            // 设置多媒体流类型
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

            // 设置用于展示mediaPlayer的容器
            mediaPlayer.setSurface(surfaceHolder.getSurface());
//            mediaPlayer.setDisplay(surfaceHolder);//用这个方法会报 Wallpapers do not support keep screen on
            try {
                mediaPlayer.setDataSource(videoPath);
                mediaPlayer.prepare();
                mediaPlayer.start();
                mediaPlayer.setLooping(true);
            } catch (Exception e) {
                Log.i("通知", "播放过程中出现了错误哦");
            }
        }
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:21,代码来源:CameraLiveWallpaper.java

示例14: setButtonClickListener

import android.media.AudioManager; //导入依赖的package包/类
private void setButtonClickListener() {
	Button toggleButton = (Button) findViewById(R.id.toggleButton);
	toggleButton.setOnClickListener(new View.OnClickListener() {
		public void onClick(View v) {
			if (mPhoneIsSilent) {
				// Change back to normal mode
				mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
				mPhoneIsSilent = false;
			} else {
				// Change to silent mode
				mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
				mPhoneIsSilent = true;
			}

			// Now toggle the UI again
			toggleUi();
		}
	});
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:20,代码来源:MainActivity.java

示例15: checkAudioFocus

import android.media.AudioManager; //导入依赖的package包/类
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:MLNO,项目名称:airgram,代码行数:25,代码来源:MediaController.java


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