问题描述
我以前用过媒体播放器,从来没有遇到过这个问题.每当我尝试使用 MediaPlayer.create() 时,该方法都会给我空值,并且我无法播放我的声音.有什么我遗漏的吗?
I have used the mediaplayer before, and I have never had this problem. Whenever I try to use MediaPlayer.create(), the method gives me null, and I can't play my sounds. Is there anything that I am missing?
public class Game extends Activity
{
private MediaPlayer mp = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
mp = MediaPlayer.create(getBaseContext(), R.raw.sound);
}
}
我的 sound.mp3 位于我的原始文件夹中,我通过将我的声音拖动到 eclipse 中的文件夹来放置在那里.请帮忙,因为我以前玩过声音,这真的让我很烦恼:(
my sound.mp3 is in my raw folder, which I placed in there by draging my sound to the folder in eclipse. Please help, since I have played sound before, this is really bugging me :(
推荐答案
create() API 返回 null 如果它以某种方式失败.
The create() API returns null if it somehow failed.
这种情况下的原因是 mp3 文件损坏.
The reason in this case is due to a corrupt mp3 file.
这篇关于MediaPlayer.create() 总是返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!