简体   繁体   English

MediaPlayer.create()始终返回null

[英]MediaPlayer.create() always returns null

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. 每当我尝试使用MediaPlayer.create()时,该方法都会为null,而我无法播放我的声音。 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);
    }
}

my sound.mp3 is in my raw folder, which I placed in there by draging my sound to the folder in eclipse. 我的sound.mp3在我的原始文件夹中,我把声音放到eclipse中的文件夹中。 Please help, since I have played sound before, this is really bugging me :( 请帮助,因为我之前播放过声音,这真是烦我:(

The create() API returns null if it somehow failed. 如果以某种方式失败, create() API将返回null。

The reason in this case is due to a corrupt mp3 file. 在这种情况下的原因是由于损坏的mp3文件。

In my case, it was the emulator (AVD) 就我而言,它是模拟器(AVD)

Make sure that you also test it using a real Android device 确保您还使用真正的Android设备进行测试

or, create a new AVD profile with better spec and newer Android version 或者,使用更好的规格和更新的Android版本创建新的AVD配置文件

What seems to always work regardless of which AVD is using 128kbps mp3 audio file 无论哪个AVD使用128kbps mp3音频文件,似乎始终有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM