Android版的MediaPlayer不播放声音在某些设备上 [英] Android MediaPlayer not playing sound on some devices
问题描述
我做了一个简单的警报蜂鸣我的应用程序。但问题是,声音在有些设备和其他一些未播放
I have made a simple alert beep for my application. But the problem is that the sound is played on some devices and in some others not.
样品code如下:
public void audioPlayer() { // leshon tingull kur ka kolision //Armando 8/7/2013
MediaPlayer beep_alert = MediaPlayer.create(Maps.this,R.raw.double_beep);
try {
beep_alert.start();
} catch (Exception e) {
e.printStackTrace();
}
}
有显示,它只是不例如打不出误差的Nexus 4
,但它起着确定在的Nexus 7
。
There is no error shown, it just don play for example nexus 4
, but it plays ok in nexus 7
.
这是怎么回事了?
该double_beep是一个MP3文件。
The double_beep is a mp3 file.
在此先感谢...
推荐答案
请确保该卷起来,否则你不会听到任何声音。
Make sure the volume is up, otherwise you won't hear anything.
通常它不是真的建议编程调高音量,无需任何用户输入 - 如果量下来它通常是通过在首位用户行为
Generally it's not really advised to turn the volume up programmatically without any user input - if the volume is down it's usually through user action in the first place.
但这里是你如何能做到这一点:
But here's how you can do it:
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
这将最大输出 STREAM_MUSIC
。还有许多其他的方式来控制/音量变化
This will max out STREAM_MUSIC
. There are many other ways to control/change volume.
有一个读通过这个问题,以及以熟悉控制卷: http://developer.android.com/training/managing-audio/volume-playback.html
Have a read through this as well to familiarise yourself with controlling volumes: http://developer.android.com/training/managing-audio/volume-playback.html
这篇关于Android版的MediaPlayer不播放声音在某些设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!