展会信息港展会大全

Android: How to play Tone sound 播放音乐代码
来源:互联网   发布日期:2015-09-29 10:27:39   浏览:2238次  

导读:/* Tone play sample code */ private void playTone() { ToneGenerator tg = mToneGenerator; if (tg != null) { tg.sta......

/* Tone play sample code */

private void playTone() {

ToneGenerator tg = mToneGenerator;

if (tg != null) {

tg.startTone(ToneGenerator.TONE_PROP_BEEP2);

}

}

@Override

public void onResume() {

initializeTone();

}

@Override

public void onPause() {

releaseTone();

}

private void initializeTone() {

// Initialize tone generator.

try {

mToneGenerator = new ToneGenerator(

AudioManager.STREAM_SYSTEM, 50);

} catch (Throwable ex) {

Log.w(TAG, "Exception caught while creating tone generator: ", ex);

mToneGenerator = null;

}

}

private void releaseTone() {

if (mToneGenerator != null) {

mToneGenerator.release();

mToneGenerator = null;

}

}

赞助本站

人工智能实验室

相关热词: 播放音乐

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港