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
我沒有得到確切的問題代碼。你的幫助表示讚賞。在此先感謝...
沒有文件格式爲MP3只是,即使我給直接來自原始文件夾的資源仍然繼續存在。順便說一句,謝謝你的回覆 – Chaitanya 2013-03-20 06:57:35
@chaitanya你有Create()null,所以會發生腐敗文件! – Janmejoy 2013-03-20 07:01:31
嗨,我錯過了那個角度。 :(再次感謝。順便說一句,在什麼情況下文件被損壞?可以避免嗎? – Chaitanya 2013-03-20 08:39:51