我正在 2 部手机上进行测试。在一台设备中,媒体播放器的 isPlaying() 始终返回 false,即使它正在播放。但在其他设备(lg optimusgingerbread)中,如果正在播放,则 isPlaying() 返回 true,否则返回 false。
谁能告诉我为什么会发生这种情况?我的一些代码取决于 isPlaying() 部分,我想让它在所有设备上工作。
public void addSoundMedia(Context context, int resId){
MediaPlayer mp = MediaPlayer.create(context, resId);
mp.setVolume(1.0f, 1.0f);
try{
mPlayerList.add(mp);
}
catch(Exception e){}
}
public void playSoundMedia(int index){
try{
mPlayerList.get(index).start();
}
catch(Exception e){}
}
public MediaPlayer getPlayer(int index){
return mPlayerList.get(index);
}
现在我打电话
mPlayer.getPlayer(currentPlayingPhraseIndex).isPlaying();
//which is now returning false. Previously i was returning true but now it always return false
而且我也匹配了这个对象,
这是现在的代码场景:
int phraseIndexToBePlayed = getRandomInteger(0, numberOfPhrasesSelected-1, randomPhraseGen); //get random index from 0 to (size of arraylist where i added my media) -1
currentPlayingPhraseIndex = phraseIndexToBePlayed; //for later use in another function scope
mPlayer.playSoundMedia(phraseIndexToBePlayed);
我还验证了两者是否是相同的媒体
mPlayer.getPlayer(currentPlayingPhraseIndex).equals(mPlayer.getPlayer(phraseIndexToBePlayed)); //it returns true so they are both same media
Thanks.