当前位置: 首页 > news >正文

南平建设集团网站友链交换平台

南平建设集团网站,友链交换平台,做淘宝客怎么建网站,成都网站建设 erpAndroid 一体机研发之修改系统设置————屏幕亮度 Android 一体机研发之修改系统设置————声音 Android 一体机研发之修改系统设置————自动锁屏 修改系统设置系列篇章马上开张了! 本章将为大家细节讲解声音。 对于声音功能大家都不陌生,在多…

在这里插入图片描述
Android 一体机研发之修改系统设置————屏幕亮度

Android 一体机研发之修改系统设置————声音

Android 一体机研发之修改系统设置————自动锁屏

修改系统设置系列篇章马上开张了! 本章将为大家细节讲解声音。

对于声音功能大家都不陌生,在多媒体时代,它是很必要的,同样也是缺它不可的版块;而在一体机实际应用中,这里更改的是媒体音量

声音

几个常见的 “音量类型”: STREAM_VOICE_CALL 通话STREAM_SYSTEM 系统STREAM_RING 铃声STREAM_MUSIC 媒体音量STREAM_ALARM 闹钟STREAM_NOTIFICATION 通知

设计思路

  1. 获取音频管理器
  2. 获取媒体音量最大值
  3. 获取系统当前媒体音量
  4. 通过seekBar设置系统媒体音量

具体实现

获取音频管理器
  • Java
 AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
  • Kotlin
mAudioManager = this.getSystemService(Context.AUDIO_SERVICE) as AudioManager

获取媒体音量最大值
  • Java
mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
  • Kotlin
mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)

获取系统当前媒体音量
  • Java
/*** 获取系统媒体音量* STREAM_VOICE_CALL 通话* STREAM_SYSTEM 系统* STREAM_RING 铃声* STREAM_MUSIC 媒体音量* STREAM_ALARM 闹钟* STREAM_NOTIFICATION 通知*/
mCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
  • Kotlin
mCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)

设置系统媒体音量

  • Java
	voiceBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {Log.e("进度显示 >>>", "onProgressChanged: " + progress);//设置系统媒体音量setStreamVolume(progress);}public void onStartTrackingTouch(SeekBar seekBar) {}public void onStopTrackingTouch(SeekBar seekBar) {}});/*** 设置系统媒体音量* setStreamVolume 直接设置音量* adjustStreamVolume 步长式设置音量,即10,20,30这样阶梯式* <p>* 参数1:音量类型* 参数2:音量数值* 参数3:* AudioManager.FLAG_SHOW_UI 调整音量时显示系统音量进度条 , 0 则不显示* AudioManager.FLAG_ALLOW_RINGER_MODES 是否铃声模式* AudioManager.FLAG_VIBRATE 是否震动模式* AudioManager.FLAG_SHOW_VIBRATE_HINT 震动提示* AudioManager.FLAG_SHOW_SILENT_HINT 静音提示* AudioManager.FLAG_PLAY_SOUND 调整音量时播放声音*/private void setStreamVolume(int volume) {mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_PLAY_SOUND);}
  • Kotlin
	seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {Log.i("onProgressChanged----", "" + progress)mCurrentVolume = progress//更新页面updateNum(mCurrentVolume)//设置媒体音量setStreamVolume(mCurrentVolume)}override fun onStartTrackingTouch(seekBar: SeekBar?) {}override fun onStopTrackingTouch(seekBar: SeekBar?) {}})/*** 更新页面显示*/private fun updateNum(volume: Int) {//tv_volume.text = volume.toString()seekBar.progress = volume}/*** 设置系统媒体音量*/private fun setStreamVolume(volume: Int) {mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_SHOW_UI)}

监听系统按键

	//监听系统按键public boolean onKeyDown(int keyCode, KeyEvent event) {switch (keyCode) {case KeyEvent.KEYCODE_VOLUME_DOWN:if (mCurrentVolume > 0) {mCurrentVolume--;} else {mCurrentVolume = 0;}voiceBar.setProgress(mCurrentVolume);setStreamVolume(mCurrentVolume);Log.e("音量减 >>", "onKeyDown: " + mCurrentVolume );return true;case KeyEvent.KEYCODE_VOLUME_UP:if (mCurrentVolume < mMaxVolume) {mCurrentVolume++;} else {mCurrentVolume = mMaxVolume;}voiceBar.setProgress(mCurrentVolume);setStreamVolume(mCurrentVolume);Log.e("音量加 >>", "onKeyDown: " + mCurrentVolume );return true;/* case KeyEvent.KEYCODE_VOLUME_MUTE:return true;*/}return super.onKeyDown(keyCode, event);}

完整操作

  • Java
/*** @author 拉莫帅* @date 2023/2/8* @address* @Desc 修改系统声音(媒体声音)*/
public class ChangeVoiceActivity extends AppCompatActivity {private AudioManager mAudioManager;private SeekBar voiceBar;//当前音量private int mCurrentVolume = 0;//最大音量private int mMaxVolume = 0;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_chanage_voice);init();}private void init() {voiceBar = findViewById(R.id.voiceBar);ImageView back = findViewById(R.id.back);TextView title = findViewById(R.id.title);title.setText("声音");mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);/*** 获取系统媒体音量* STREAM_VOICE_CALL 通话* STREAM_SYSTEM 系统* STREAM_RING 铃声* STREAM_MUSIC 媒体音量* STREAM_ALARM 闹钟* STREAM_NOTIFICATION 通知*/mCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);//获取媒体音量最大值mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);Log.e("进度 >>", "init: " + mCurrentVolume + "---" + mMaxVolume);voiceBar.setMax(mMaxVolume);//更新进度条voiceBar.setProgress(mCurrentVolume);back.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {finish();}});voiceBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {Log.e("进度显示 >>>", "onProgressChanged: " + progress);setStreamVolume(progress);}public void onStartTrackingTouch(SeekBar seekBar) {}public void onStopTrackingTouch(SeekBar seekBar) {}});}//监听系统按键public boolean onKeyDown(int keyCode, KeyEvent event) {switch (keyCode) {case KeyEvent.KEYCODE_VOLUME_DOWN:if (mCurrentVolume > 0) {mCurrentVolume--;} else {mCurrentVolume = 0;}voiceBar.setProgress(mCurrentVolume);setStreamVolume(mCurrentVolume);Log.e("音量减 >>", "onKeyDown: " + mCurrentVolume );return true;case KeyEvent.KEYCODE_VOLUME_UP:if (mCurrentVolume < mMaxVolume) {mCurrentVolume++;} else {mCurrentVolume = mMaxVolume;}voiceBar.setProgress(mCurrentVolume);setStreamVolume(mCurrentVolume);Log.e("音量加 >>", "onKeyDown: " + mCurrentVolume );return true;/* case KeyEvent.KEYCODE_VOLUME_MUTE:return true;*/}return super.onKeyDown(keyCode, event);}/*** 设置系统媒体音量* setStreamVolume 直接设置音量* adjustStreamVolume 步长式设置音量,即10,20,30这样阶梯式* <p>* 参数1:音量类型* 参数2:音量数值* 参数3:* AudioManager.FLAG_SHOW_UI 调整音量时显示系统音量进度条 , 0 则不显示* AudioManager.FLAG_ALLOW_RINGER_MODES 是否铃声模式* AudioManager.FLAG_VIBRATE 是否震动模式* AudioManager.FLAG_SHOW_VIBRATE_HINT 震动提示* AudioManager.FLAG_SHOW_SILENT_HINT 静音提示* AudioManager.FLAG_PLAY_SOUND 调整音量时播放声音*/private void setStreamVolume(int volume) {mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_PLAY_SOUND);}
}
  • Kotlin
class VolumeActivity : AppCompatActivity() {//音频管理器private lateinit var mAudioManager: AudioManager//当前音量private var mCurrentVolume: Int = 0//最大音量private var mMaxVolume: Int = 0override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_volume)init()setListener()}("SetTextI18n")private fun init() {mAudioManager = this.getSystemService(Context.AUDIO_SERVICE) as AudioManager/*** ringerMode 音量模式* RINGER_MODE_NORMAL 正常* RINGER_MODE_SILENT 静音* RINGER_MODE_VIBRATE 震动*/when (mAudioManager.ringerMode) {AudioManager.RINGER_MODE_NORMAL -> tv_mode.text = "当前音量模式:正常"AudioManager.RINGER_MODE_SILENT -> tv_mode.text = "当前音量模式:静音"AudioManager.RINGER_MODE_VIBRATE -> tv_mode.text = "当前音量模式:震动"}/*** 获取系统媒体音量* STREAM_VOICE_CALL 通话* STREAM_SYSTEM 系统* STREAM_RING 铃声* STREAM_MUSIC 媒体音量* STREAM_ALARM 闹钟* STREAM_NOTIFICATION 通知*/mCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)//获取媒体音量最大值mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)seekBar.max = mMaxVolumetv_max.text = "最大音量:$mMaxVolume"updateNum(mCurrentVolume)}private fun setListener() {btn_mode.setOnClickListener {mAudioManager.ringerMode = AudioManager.RINGER_MODE_NORMALtv_mode.text = "当前音量模式:正常"}seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {Log.i("onProgressChanged----", "" + progress)mCurrentVolume = progressupdateNum(mCurrentVolume)setStreamVolume(mCurrentVolume)}override fun onStartTrackingTouch(seekBar: SeekBar?) {}override fun onStopTrackingTouch(seekBar: SeekBar?) {}})}/*** 更新页面显示*/private fun updateNum(volume: Int) {tv_volume.text = volume.toString()seekBar.progress = volume}/*** 设置系统媒体音量* setStreamVolume 直接设置音量* adjustStreamVolume 步长式设置音量,即10,20,30这样阶梯式** 参数1:音量类型* 参数2:音量数值* 参数3:*      AudioManager.FLAG_SHOW_UI 调整音量时显示系统音量进度条 , 0 则不显示*      AudioManager.FLAG_ALLOW_RINGER_MODES 是否铃声模式*      AudioManager.FLAG_VIBRATE 是否震动模式*      AudioManager.FLAG_SHOW_VIBRATE_HINT 震动提示*      AudioManager.FLAG_SHOW_SILENT_HINT 静音提示*      AudioManager.FLAG_PLAY_SOUND 调整音量时播放声音*/private fun setStreamVolume(volume: Int) {mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_SHOW_UI)}


最近忙里偷闲,↓↓↓↓【谁家de码农陈先生】↓↓↓↓,里面定时给大家分享技术博文、前方高能资讯内容!欢迎各位老板点赞关注,你们就是我的动力源泉!


文章转载自:
http://vergil.pwrb.cn
http://xylylene.pwrb.cn
http://crambo.pwrb.cn
http://glissandi.pwrb.cn
http://commodiously.pwrb.cn
http://coadjutress.pwrb.cn
http://mosaic.pwrb.cn
http://enplane.pwrb.cn
http://harvestman.pwrb.cn
http://mammee.pwrb.cn
http://noncombustibility.pwrb.cn
http://northland.pwrb.cn
http://hawkmoth.pwrb.cn
http://taaffeite.pwrb.cn
http://disassimilation.pwrb.cn
http://approve.pwrb.cn
http://asynchronous.pwrb.cn
http://verfremdungseffect.pwrb.cn
http://peruke.pwrb.cn
http://anaplasia.pwrb.cn
http://xylogen.pwrb.cn
http://bog.pwrb.cn
http://furuncle.pwrb.cn
http://emily.pwrb.cn
http://mystery.pwrb.cn
http://hometown.pwrb.cn
http://plier.pwrb.cn
http://poleyn.pwrb.cn
http://pious.pwrb.cn
http://generalitat.pwrb.cn
http://chaplain.pwrb.cn
http://saloop.pwrb.cn
http://divisibility.pwrb.cn
http://septennial.pwrb.cn
http://platycephaly.pwrb.cn
http://whomever.pwrb.cn
http://totemist.pwrb.cn
http://gerry.pwrb.cn
http://decelerometer.pwrb.cn
http://centuplicate.pwrb.cn
http://lassie.pwrb.cn
http://shekinah.pwrb.cn
http://exhibitionist.pwrb.cn
http://zonda.pwrb.cn
http://teeth.pwrb.cn
http://jello.pwrb.cn
http://plica.pwrb.cn
http://gouge.pwrb.cn
http://sulfonium.pwrb.cn
http://moistureproof.pwrb.cn
http://anaclasis.pwrb.cn
http://miniaturise.pwrb.cn
http://anadyr.pwrb.cn
http://samlor.pwrb.cn
http://destructuralize.pwrb.cn
http://hoarding.pwrb.cn
http://furred.pwrb.cn
http://tubifex.pwrb.cn
http://confounded.pwrb.cn
http://chaseable.pwrb.cn
http://lamellated.pwrb.cn
http://carryon.pwrb.cn
http://plant.pwrb.cn
http://pohai.pwrb.cn
http://palliard.pwrb.cn
http://brushhook.pwrb.cn
http://cystostomy.pwrb.cn
http://mal.pwrb.cn
http://balkan.pwrb.cn
http://courtyard.pwrb.cn
http://nonnitrogenous.pwrb.cn
http://defaulter.pwrb.cn
http://trumpeter.pwrb.cn
http://sinify.pwrb.cn
http://professed.pwrb.cn
http://soerakarta.pwrb.cn
http://landslide.pwrb.cn
http://gemmiparous.pwrb.cn
http://caramelization.pwrb.cn
http://royal.pwrb.cn
http://grateful.pwrb.cn
http://altercate.pwrb.cn
http://nerving.pwrb.cn
http://plasmolyse.pwrb.cn
http://dragrope.pwrb.cn
http://impennate.pwrb.cn
http://following.pwrb.cn
http://electuary.pwrb.cn
http://bouillon.pwrb.cn
http://iiium.pwrb.cn
http://acmesthesia.pwrb.cn
http://napoleonic.pwrb.cn
http://mansard.pwrb.cn
http://banns.pwrb.cn
http://umwelt.pwrb.cn
http://bleeper.pwrb.cn
http://nonclaim.pwrb.cn
http://tambov.pwrb.cn
http://evilness.pwrb.cn
http://multipage.pwrb.cn
http://www.dt0577.cn/news/68967.html

相关文章:

  • 广州建网站的公司 白云区百度云盘资源
  • wordpress导航编辑器淘宝关键词优化怎么弄
  • 权威的大连网站建设广告牌
  • 用php做电商网站有哪些百度联盟推广
  • 提卡网站要怎么做百度宣传推广
  • 网站开发与维护是做什么工作正规优化公司哪家好
  • 小说网站怎么做推广免费网站建设平台
  • 好的网站首页的特点外贸网站建站平台
  • 做网站怎样赚到钱电商培训机构
  • 计算机网站建设与维护友情链接属于免费推广吗
  • 有没有学做ppt发网站或论坛项目营销推广策划
  • 如何制作课程网站模板包头seo
  • 做网站最好cps推广平台有哪些
  • 广州哪家做网站老客外链
  • 网站更新中如何交换优质友情链接
  • 珠海网站制作推荐百度推广怎么联系
  • 做装修公司的网站长春网站优化方案
  • 企业个性化网站建设费用十大舆情网站
  • 怎样建立自己网站难吗网站维护费用
  • wordpress取消图片自适应搜索引擎优化学习
  • 纯css网站百度公司高管排名
  • openwrt做网站营销策划的概念
  • 泉州做网站联系方式线上卖护肤品营销方法
  • 肥乡邯郸做网站河南百度推广公司
  • 学校网站建设可行性分析sem是什么意思啊
  • 醴陵建设局网站阿里云万网域名注册
  • 蘑菇头表情包制作网站seo交流博客
  • 苏州做网站便宜的公司全能搜
  • 哪个网站卖做阳具好点无锡谷歌推广
  • 帝国cms如何做网站地图网站制作费用