MediaPlayer出错 - setOnCompletionListener()

时间:2014-11-18 02:35:50

标签: android android-mediaplayer

我在setOnCompletionListener(这个)的一些android设备上收到错误。请告诉我哪一个是正确的。

  1. start()之前的setOnCompletionListener()。

    private void playBackGround() {
    // TODO Auto-generated method stub  
        backGround.reset();
        backGround.release();
        backGround = MediaPlayer.create(getApplicationContext(), R.raw.bgm);  
        backGround.setOnCompletionListener(this); 
        backGround.start(); 
    }
    
  2. setOnCompletionListener()之前的start()。

    private void playBackGround() {
    // TODO Auto-generated method stub  
        backGround.reset();
        backGround.release();
        backGround = MediaPlayer.create(getApplicationContext(), R.raw.bgm);  
        backGround.start(); 
        backGround.setOnCompletionListener(this); 
    }
    
  3. Log Cat:

    java.lang.NullPointerException
    at memory.game.collection.free.Start.playBackGround(Start.java:665)
    at memory.game.collection.free.Start.onCompletion(Start.java:679)
    at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2019)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:153)
    at android.app.ActivityThread.main(ActivityThread.java:5006)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
    at dalvik.system.NativeStart.main(Native Method)
    

0 个答案:

没有答案