0

我正在尝试使用循环播放原始媒体文件。我写了一个同步的方法来播放媒体文件。这适用于模拟器,但不适用于真实设备。

我为需要播放声音的问题创建了一个简单的 bean。

public class Question {
private String mQuestionString;
private int mSoundFile;
private int mAnswer;
private int mQuestionNo;

public Question() {

    mQuestionNo = 0;
    mQuestionString = "";
    mSoundFile = 0;
    mAnswer = 0;
}

public Question(int mQuestionNo, String mQuestionString, int mSoundFile,
        int mAnswer) {
    super();
    this.mQuestionNo = mQuestionNo;
    this.mQuestionString = mQuestionString;
    this.mSoundFile = mSoundFile;
    this.mAnswer = mAnswer;
}

public String getQuestionString() {
    return mQuestionString;
}

public void setQuestionString(String mQuestionString) {
    this.mQuestionString = mQuestionString;
}

public int getSoundFile() {
    return mSoundFile;
}

public void setSoundFile(int mSoundFile) {
    this.mSoundFile = mSoundFile;
}

public int getAnswer() {
    return mAnswer;
}

public void setAnswer(int mAnswer) {
    this.mAnswer = mAnswer;
}

public int getQuestionNo() {
    return mQuestionNo;
}

public void setQuestionNo(int mQuestionNo) {
    this.mQuestionNo = mQuestionNo;
}

@Override
public String toString() {
    return "Question " + mQuestionNo + ". " + mQuestionString;
}

}

这是我在活动中的代码

public class LQActivity extends Activity{

    private Vector<Question> mQuestions = null;
private TextView tvQuestion = null;
private Button btnSubmit = null;
private Button btnNext = null;
    ...

  private void prepareQuestions() {
    // TODO Auto-generated method stub
    mQuestions = new Vector<Question>();
    mQuestions.add(new Question(1, "Count the number of the Tabala played",
            R.raw.q1, 5));
    mQuestions.add(new Question(2,
            "Count the number of the persons visited temple", R.raw.q2, 3));
    mQuestions
            .add(new Question(3, "Count the number of frogs", R.raw.q3, 6));
    mQuestions.add(new Question(4,
            "Count the number of the cuckoo on the tree", R.raw.q4, 8));
    mQuestions.add(new Question(5, "Count the number of the flute played",
            R.raw.q5, 7));

}

private synchronized void playQuestion(Question question) {


    mMediaPlayer = MediaPlayer.create(this, question.getSoundFile());

    mMediaPlayer.start();
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        if (mMediaPlayer != null) {
            mMediaPlayer.release();
        }
    }
            mMediaPlayer.release();
        }

}

问题mMediaPlyer.create()是返回 null

我没有得到确切的问题。感谢您的帮助。提前致谢...

4

1 回答 1

0
mMediaPlyer.create() is returning null

原因是由于 mp3 文件损坏或使用了不支持的文件,请检查链接 android 支持的媒体格式

于 2013-03-20T06:45:09.217 回答