--基础版,此为lua代码
require "import"
import "android.media.*"
import "android.content.*"
--声音类型,可取为STREAM_VOICE_CALL(通话)、STREAM_SYSTEM(系统声音)、STREAM_RING(铃声)、STREAM_MUSIC(音乐)、STREAM_ALARM(闹铃声)
seek = i:gvs(拖动条id)
am = activity:getSystemService(Context.AUDIO_SERVICE)
local maxVolume = am:getStreamMaxVolume(AudioManager.STREAM_MUSIC)
seek:setMax(maxVolume)
currentv = am:getStreamVolume(AudioManager.STREAM_MUSIC)
seek:setProgress(currentv)
--以上代码放载入事件
--以下代码放拖动条事件
am:setStreamVolume(AudioManager.STREAM_MUSIC,zh,0)
local cv = am:getStreamVolume(AudioManager.STREAM_MUSIC)
seek:setProgress(cv)
//进阶版
//以下代码放在载入事件『
fn AudioManager.init()
//』以上代码放载入事件
//以下代码放在AudioManager.myu『
//重要提示:千万不要改模块名字,否则会报错
//认真看注释,错了别怪作者没写详细
//使用之前一定一定一定要调用init()方法!
//初始化音频管理器,第一次使用前调用它一次,否则会错误
//默认控制媒体音量
fn init()
javags(sign,null,"android.content.Context","AUDIO_SERVICE")
java(sss.AudioManager,activity,"android.app.Activity.getSystemService","String",sign)
fn AudioManager.type(0)
end fn
//重新设置要控制的音量的类型
//0:媒体音量
//1:系统音量
//2:铃声音量
//输入其他等于控制媒体音量
fn type(type)
cls("android.media.AudioManager",class)
f(type==0)
{
javags(sss.type,null,class,"STREAM_MUSIC")
}
else f(type==1)
{
javags(sss.type,null,class,"STREAM_SYSTEM")
}
else f(type==2)
{
javags(sss.type,null,class,"STREAM_RING")
}
else
{
javags(sss.type,null,class,"STREAM_MUSIC")
}
end fn
//显示系统当前的xx音量(弹窗音量更改弹窗,但不会增加/减小音量)
fn show()
cls("android.media.AudioManager",class)
javags(sign1,null,class,"ADJUST_SAME")
javags(sign2,null,class,"FLAG_SHOW_UI")
javax(null,sss.AudioManager,class,"adjustStreamVolume","int",sss.type,"int",sign1,"int",sign2)
end fn
//增加系统当前的xx音量(相当于按一下音量+键)
fn up()
cls("android.media.AudioManager",class)
javags(sign1,null,class,"ADJUST_RAISE")
javags(sign2,null,class,"FLAG_SHOW_UI")
javax(null,sss.AudioManager,class,"adjustStreamVolume","int",sss.type,"int",sign1,"int",sign2)
end fn
//减小系统当前的xx音量(相当于按一下音量-键)
fn down()
cls("android.media.AudioManager",class)
javags(sign1,null,class,"ADJUST_LOWER")
javags(sign2,null,class,"FLAG_SHOW_UI")
javax(null,sss.AudioManager,class,"adjustStreamVolume","int",sss.type,"int",sign1,"int",sign2)
end fn
//设置系统当前xx音量(传入数值)
fn set(vol)
cls("android.media.AudioManager",class)
javags(sign1,null,class,"FLAG_SHOW_UI")
javax(null,sss.AudioManager,class,"setStreamVolume","int",sss.type,"int",vol,"int",sign1)
end fn
//获取系统当前xx音量
//结果在变量sss.return里面
fn get()
cls("android.media.AudioManager",class)
javax(vol,sss.AudioManager,class,"getStreamVolume","int",sss.type)
sss return=vol
end fn
//获取系统最大xx音量
//结果在sss.return里面
//强烈建议你们这些直接用set()的人先获取最大音量在好好算算应该传入什么值
//我用set(25)的时候带着耳机特么都吓尿了,声音那么大
fn getMax()
cls("android.media.AudioManager",class)
javax(vol,sss.AudioManager,class,"getStreamMaxVolume","int",sss.type)
sss return=vol
end fn
/.
关于我:
作者:Rose
百度贴吧:@eqfrdryrt
./
//』以上代码放AudioManager.myu
//『各个功能的调用
//显示音量
fn AudioManager.show()
//增加/减小音量
fn AudioManager.up()
fn AudioManager.down()
//设置音量(15)
fn AudioManager.set(15)
//获取音量
fn AudioManager.get()
tw(sss.return)
//获取最大音量
fn AudioManager.getMax()
tw(sss.return)
//修改控制的音量类型并且增加音量
fn AudioManager.type(1)
fn AudioManager.up()
iApp一本通