Здравствуйте, сообщество StackOverFlow. В последнее время у меня возникла такая проблема, что я создал игру Whack A Mole, а затем иногда звук перестает воспроизводиться сам по себе, и он отображает только эту ошибку. MediaPlayer, пока не знаю, как это работает
E / MediaPlayerNative: остановка вызова в состоянии 0, mPlayer (0x7897fe1440) \
или
E / MediaPlayerNative: ошибка (-38, 0)
Это моя игровая активность
public class Game extends AppCompatActivity {
public MediaPlayer mPlayerShot;
public MediaPlayer mPlayerMiss;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
setContentView(R.layout.activity_game);
mTimeView = (TextView) findViewById(R.id.textTimeVal);
mScoreView = (TextView) findViewById(R.id.textScoreVal);
// Get saved difficulty, default to Medium if no pref exists
final SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
currentDiff = sharedPref.getString("saved_difficulty", "Medium");
// Start the game!
mTimer.start();
handler.post(moleLoop);
varClose = false;
mPlayerShot = MediaPlayer.create(getApplicationContext(), R.raw.playerlaser);
mPlayerMiss = MediaPlayer.create(getApplicationContext(), R.raw.enemylaser);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// Scale mole translation based on device dimensions
int sHeight = metrics.heightPixels;
yValue = (sHeight/8)*-1;
}
@Override
public void onPause(){
super.onPause();
varClose = true;
mTimer.cancel();
mPlayerShot.stop();
mPlayerMiss.stop();
}
@Override
public void onStop() {
super.onStop();
varClose = true;
mTimer.cancel();
mPlayerShot.stop();
mPlayerMiss.stop();
}
public Runnable moleLoop = new Runnable() {
int varPrevRandMole = 10;
@Override
public void run () {
// Pick a mole at random, if you get the same twice, re-roll until it's different
varRandMole = new Random().nextInt(8);
if (varRandMole == varPrevRandMole){
do
varRandMole = new Random().nextInt(8);
while (varRandMole == varPrevRandMole);
}
varPrevRandMole = varRandMole;
// Pop the mole up
molesClick[varRandMole].animate().translationY(yValue).setDuration(moleUpTime);
// Timer to pop our mole back down if player fails to hit it
new Timer().schedule(new TimerTask() {
public void run() {
if (!varClose) {
for (int i = 0; i < 9; i++) {
if (molesClick[i].getTranslationY() == yValue) {
final int j = i;
// Sets the mole back to its beginning position
// run this update on the UI thread as we need a "looper" thread
runOnUiThread(new Runnable() {
@Override
public void run() {
molesClick[j].animate().translationY(0).setDuration(5);
}
});
if (mPlayerMiss.isPlaying() && mPlayerMiss != null) {
mPlayerMiss.stop();
mPlayerMiss.reset();
mPlayerMiss.release();
}
mPlayerMiss.start();
// Deduct a life if we miss a mole
varLives -= 1;
updateLives(varLives);
}
}
}
}
}, timeInterval);
if (!varClose) {
handler.postDelayed(moleLoop, timeInterval);
}
}
};
public void directHit(){
if (mPlayerShot != null && mPlayerShot.isPlaying()){
mPlayerShot.stop();
mPlayerShot.reset();
mPlayerShot.release();
}
mPlayerShot = MediaPlayer.create(getApplicationContext(), R.raw.playerlaser);
mPlayerShot.start();
// Award points, update score
varScore += 250;
updateScore(varScore);
}
}