uniapp中调用震动、系统铃声以及自定义铃声
uniapp中调用震动、系统铃声以及自定义铃声
·
1、震动
uni.vibrate({
success: function () {
console.log('success');
}
});
2、uniapp调用手机系统铃声
let main = plus.android.runtimeMainActivity();
let RingtoneManager = plus.android.importClass("android.media.RingtoneManager");
let uri = RingtoneManager.getActualDefaultRingtoneUri(main, RingtoneManager
.TYPE_NOTIFICATION);
let MediaPlayer = plus.android.importClass("android.media.MediaPlayer");
let player = MediaPlayer.create(main, uri);
player.setLooping(false);
player.prepare();
player.start();
3、uniapp中自定义铃声
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = '/static/y974.mp3'; //铃声文件的路径
innerAudioContext.onPlay(() => {
console.log('开始播放');
});
innerAudioContext.onError((res) => {
console.log(res.errMsg);
console.log(res.errCode);
});
更多推荐
已为社区贡献5条内容
所有评论(0)