MediaPlayer.create()始终返回null [英] MediaPlayer.create() always returns null

查看:1206
本文介绍了MediaPlayer.create()始终返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用媒体播放器之前,我从未有过这个问题。每当我尝试使用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在我的原始文件夹中,这是我摆在那里draging我的声音文件夹中的日食。请帮助,因为我之前打了声,这实在是烦我:(

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 :(

推荐答案

的<一个href="http://developer.android.com/reference/android/media/MediaPlayer.html#create%28android.content.Context,%20int%29"相对=nofollow>创建(),如果它以某种方式失败 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆