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);
});

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐