j2me播放音效 怎么暂停音效

I have tried the changes found at the link below but with no avail.
I tried both
AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC,false);
// disable sound for recording.
// disable sound when recording.
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_ALARM,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_DTMF,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_MUSIC,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_RING,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_VOICE_CALL,true);
But I still get the sound when I start the media recorder. I have tried putting this code both at the start of the app and directly before the:
mediaRecorder.start();
Are there any other suggestions?
解决方案 SetStreamMute works only for SYSTEM and MUSIC. For all the other you should use SetStreamVolume.
Try the following code:
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC,true);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
For sanity check:
Log.d(TAG, String.format("%d,
%d, %d, %d, %d, %d, %d",
audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM),
audioManager.getStreamVolume(AudioManager.STREAM_MUSIC),
audioManager.getStreamVolume(AudioManager.STREAM_ALARM),
audioManager.getStreamVolume(AudioManager.STREAM_DTMF),
audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION),
audioManager.getStreamVolume(AudioManager.STREAM_RING)
The result should give: 0, 0, 0, 0, 0, 0
Keep in mind that the games with volume (exclude setStreamMute) won't reset the previous values after activity dies, so you probably want to store them to restore in onDestroy() or earlier.
本文地址: &
我曾尝试在链路发现以下但无济于事的变化。 How状态发生变化时,关闭MediaRecorder播放声音 我都尝试
AudioManager audioManager =(AudioManager)getApplicationContext()getSystemService(Context.AUDIO_SERVICE)。audioManager.setStreamMute(AudioManager.STREAM_SYSTEM,FALSE);audioManager.setStreamMute(AudioManager.STREAM_MUSIC,FALSE); 和
//禁用声音录制。//记录时禁用声音。((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_ALARM,true);((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_DTMF,true);((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_MUSIC,true);((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_RING,true);((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM,true);((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_VOICE_CALL,true); 但我仍然得到的声音时,我开始媒体记录器。我试图把这个code无论是在应用程序的启动和直接前:
mediaRecorder.start(); 还有没有其他的建议?解决方案
SetStreamMute仅用于系统和音乐。对于所有其他的你应该使用SetStreamVolume。请尝试以下code:
AudioManager audioManager =(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM,真);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC,真);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM,0,0);
audioManager.setStreamVolume(AudioManager.STREAM_DTMF,0,0);
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,0,0);
audioManager.setStreamVolume(AudioManager.STREAM_RING,0,0); 有关完整性检查:
Log.d(TAG,的String.format(“%D,%D,%D,%D,%D,%D,%D”
audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM)
audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
audioManager.getStreamVolume(AudioManager.STREAM_ALARM)
audioManager.getStreamVolume(AudioManager.STREAM_DTMF)
audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION)
audioManager.getStreamVolume(AudioManager.STREAM_RING)
)); 结果应该得到:0,0,0,0,0,0 请记住,使用量(不包括setStreamMute)游戏不会复位previous值活动死后,所以你可能要存储它们的onDestroy()来恢复或更早版本。
本文地址: &
扫一扫关注官方微信本帖子已过去太久远了,不再提供回复功能。tank_war J2ME的坦克大战游戏,包含所有音效,以及过关界面,测试通过。欢 载 Shot Game 射击
238万源代码下载-
&文件名称: tank_war
& & & & &&]
&&所属分类:
&&开发工具: Java
&&文件大小: 2564 KB
&&上传时间:
&&下载次数: 21
&&提 供 者:
&详细说明:J2ME的坦克大战游戏,包含所有音效,以及过关界面,测试通过。欢迎下载-J2ME in the Battle City game, including all audio, as well as clearance interface test. Welcome to download
文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):
&&tank_war完整版-(包括声音,过关效果)\.classpath&&...................................\.eclipseme&&...................................\...........tmp\emulation\tank_war_hd.jad&&...................................\..............\.........\tank_war_hd.jar&&...................................\..............\verified\classes\com\hd\tankwar\canvas\NextLevelsTip.class&&...................................\..............\........\.......\...\..\.......\......\StartGameCanvas.class&&...................................\..............\........\.......\...\..\.......\......\TankGameCanvas.class&&...................................\..............\........\.......\...\..\.......\entity\Bullet.class&&...................................\..............\........\.......\...\..\.......\......\Enemy.class&&...................................\..............\........\.......\...\..\.......\......\Map.class&&...................................\..............\........\.......\...\..\.......\......\Props.class&&...................................\..............\........\.......\...\..\.......\......\Tank.class&&...................................\..............\........\.......\...\..\.......\main\tankwar_hd.class&&...................................\..............\........\.......\...\..\.......\.idea\GameMedia.class&&...................................\..............\........\.......\...\..\.......\thread\MediaThread.class&&...................................\..............\........\.......\...\..\.......\......\TankWarThread.class&&...................................\.project&&...................................\.settings\org.eclipse.jdt.core.prefs&&...................................\bin\barricade.png&&...................................\...\bomb.png&&...................................\...\bomb.wav&&...................................\...\bomb_t.wav&&...................................\...\com\hd\tankwar\canvas\NextLevelsTip.class&&...................................\...\...\..\.......\......\StartGameCanvas.class&&...................................\...\...\..\.......\......\TankGameCanvas.class&&...................................\...\...\..\.......\entity\Bullet.class&&...................................\...\...\..\.......\......\Enemy.class&&...................................\...\...\..\.......\......\Map.class&&...................................\...\...\..\.......\......\Props.class&&...................................\...\...\..\.......\......\Tank.class&&...................................\...\...\..\.......\main\tankwar_hd.class&&...................................\...\...\..\.......\.idea\GameMedia.class&&...................................\...\...\..\.......\thread\MediaThread.class&&...................................\...\...\..\.......\......\TankWarThread.class&&...................................\...\enemy_num.png&&...................................\...\exit.png&&...................................\...\fire.wav&&...................................\...\gameOver.wav&&...................................\...\game_over.png&&...................................\...\home.png&&...................................\...\home_over.png&&...................................\...\Level.png&&...................................\...\map1&&...................................\...\missile.png&&...................................\...\move.wav&&...................................\...\player.png&&...................................\...\player_home.png&&...................................\...\player_life.png&&...................................\...\props.png&&...................................\...\props.wav&&...................................\...\protect.png&&...................................\...\reborn.wav&&...................................\...\start.png&&...................................\...\start.wav&&...................................\...\start_Image.png&&...................................\...\start_Image_2.png&&...................................\...\tank_1.png&&...................................\...\tank_2.png&&...................................\...\tank_3.png&&...................................\...\tank_4.png&&...................................\...\tank_5.png&&...................................\...\tank_6.png&&...................................\...\tank_player.png&&...................................\...\tank_start.png&&...................................\res\barricade.png&&...................................\...\bomb.png&&...................................\...\bomb.wav&&...................................\...\bomb_t.wav&&...................................\...\enemy_num.png&&...................................\...\exit.png&&...................................\...\fire.wav&&...................................\...\gameOver.wav&&...................................\...\game_over.png&&...................................\...\home.png&&...................................\...\home_over.png&&...................................\...\Level.png&&...................................\...\map1&&...................................\...\missile.png&&...................................\...\move.wav&&...................................\...\player.png&&...................................\...\player_home.png&&...................................\...\player_life.png&&...................................\...\props.png&&...................................\...\props.wav&&...................................\...\protect.png&&...................................\...\reborn.wav&&...................................\...\start.png&&...................................\...\start.wav&&...................................\...\start_Image.png&&...................................\...\start_Image_2.png&&...................................\...\tank_1.png&&...................................\...\tank_2.png&&...................................\...\tank_3.png&&...................................\...\tank_4.png&&...................................\...\tank_5.png&&...................................\...\tank_6.png&&...................................\...\tank_player.png&&...................................\...\tank_start.png&&...................................\src\com\hd\tankwar\canvas\NextLevelsTip.java&&...................................\...\...\..\.......\......\StartGameCanvas.java
&相关搜索:
&输入关键字,在本站238万海量源码库中尽情搜索:
&[] - 此游戏为射击类游戏,用j2me编写的。按左右上下键,就会射击目标,走动。
&[] - J2ME版的坦克游戏,内有源程序和编译好的JAR文件,可下载到手机娱乐
&[] - 我的毕业设计经典的模拟1990坦克,代码全部自己写的,非常有参考价值,想学习做简单游戏的可以从这学起~~~鄙视抄袭。。。源代码仅仅做参考用~~~
&[] - j2me polish学习的经典代码,包括UI的使用,build.xml文件的编写等

参考资料

 

随机推荐