如何以编程方式向Android手机的扬声器发出一声短促的哔哔声 [英] How to play a short beep to Android Phone's loudspeaker programmatically

查看:106
本文介绍了如何以编程方式向Android手机的扬声器发出一声短促的哔哔声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在扬声器上接收到唯一的短哔声,我想直接向扬声器发送一位.类似于LED闪烁.没有任何媒体播放器,是否有可能发出短促的提示音?

In order to receive the only short beep sound on loudspeaker I want to send single bit to the loudspeaker directly. Similarly to the LED blink. Is there any possibility to do short beep without any kind of Media Players?

推荐答案

我建议您使用 ToneGenerator 类.它不需要音频文件,不需要媒体播放器,并且您可以自定义提示音的音量,持续时间(以毫秒为单位)和提示音类型.我喜欢这个:

I recommend you use the ToneGenerator class. It requires no audio files, no media player, and you can customize the beep's volume, duration (in milliseconds) and Tone type. I like this one:

ToneGenerator toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);             
toneGen1.startTone(ToneGenerator.TONE_CDMA_PIP,150);  

您可以查看ToneGenerator对象(在Mac中单击CMD,然后单击ToneGenerator.),然后选择除 TONE_CDMA_PIP 之外的另一种蜂鸣类型, 150 是持续时间(以毫秒为单位),然后 100 音量.

You can see into the ToneGenerator object (CMD + click over ToneGenerator. , in Mac), and choose another beep type besides TONE_CDMA_PIP, 150 is the duration in milliseconds, and 100 the volume.

这篇关于如何以编程方式向Android手机的扬声器发出一声短促的哔哔声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆