android 语音发送功能,Android:应设置什么音频模式以在设备之间发送接收语音

可以将您想要播放的声音处理为闹钟.

创建一个名为AlarmController的新类并尝试此代码.

这适用于Android 4.4.2(华为登上P7),每个系统音量(媒体,铃声,闹钟)设置为0.

Context context;

MediaPlayer mp;

AudioManager mAudioManager;

int userVolume;

public AlarmController(Context c) { // constructor for my alarm controller class

this.context = c;

mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

//remeber what the user's volume was set to before we change it.

userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);

mp = new MediaPlayer();

}

public void playSound(String soundURI){

Uri alarmSound = null;

Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

try{

alarmSound = Uri.parse(soundURI);

}catch(Exception e){

alarmSound = ringtoneUri;

}

finally{

if(alarmSound == null){

alarmSound = ringtoneUri;

}

}

try {

if(!mp.isPlaying()){

mp.setDataSource(context, alarmSound);

mp.setAudioStreamType(AudioManager.STREAM_ALARM);

mp.setLooping(true);

mp.prepare();

mp.start();

}

} catch (IOException e) {

Toast.makeText(context, "Your alarm sound was unavailable.", Toast.LENGTH_LONG).show();

}

// set the volume to what we want it to be. In this case it's max volume for the alarm stream.

mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), AudioManager.FLAG_PLAY_SOUND);

}

public void stopSound(){

// reset the volume to what it was before we changed it.

mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, userVolume, AudioManager.FLAG_PLAY_SOUND);

mp.stop();

mp.reset();

}

public void releasePlayer(){

mp.release();

}

我希望这适合你. 🙂

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值