本文介绍了Android SDK中Mediaplayer.create随机返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个问题,即偶尔MediaPlayer.create方法将返回null,即使音频文件肯定是存在的。事实上,如果我把调用创建成一个while循环,媒体播放器最终将成功创建。这似乎只发生在我的手机(HTC Hero的运行2.1),从来没有在模拟器。

I am having an issue where occasionally the MediaPlayer.create method will return null, even though the audio file is definitely there. In fact, if I put the call to create into a while loop, the media player will eventually be created successfully. This only seems to happen on my phone (HTC Hero running 2.1) and never in the emulator.

这只是一个问题的手机?还是有不同的方式,我应该扮演这些音频文件?

Is this just an issue with the phone? Or is there a different way I should be playing these audio files?

请注意,我要动态地加载它们是让我做调用getIndentifer。如果有玩这些有更好的方式动态地请让我知道。

Note that I want to be loading them dynamically which is get I am making the call to getIndentifer. If there is a better way of playing these dynamically please let me know.

public void playAudio(String audioFile){

    //instance variable of type MediaPlayer
    _player = null;
    while(_player == null){
         _player = MediaPlayer.create(_context, getResources().getIdentifier(audioFile, "raw", _context.getPackageName()));
    }
    _player.start();

}



感谢。

推荐答案

一个的Soundpool(的)可能是值得考虑的。

A SoundPool (Docs) might be something to consider.

这篇关于Android SDK中Mediaplayer.create随机返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:47