【发布时间】:2011-04-04 23:43:44
【问题描述】:
我正在使用地图构建一个包含大约 40 种声音的音板。 (Previous thread)
如果应用程序移到后台(来电或类似情况),是否有人知道暂停重启 Mediaplayer 的好方法?我对此还是很陌生,所以这可能是超级简单的事情。感谢任何可以提供帮助的人。
地图地图=新
HashMap();
map.put(R.id.button1, R.raw.sound1);
map.put(R.id.button2, R.raw.sound2);
...
然后迭代:
for (Map.Entry entry : map.entrySet()) {
final MediaPlayer sound = MediaPlayer.create(entry.getValue()); Button button = (ImageButton) findViewById(entry.getKey()); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sound.start(); } });}
【问题讨论】:
标签: android map media-player