2

我正在开发带有多点触控的鼓垫。我使用了一个扩展按钮的内部类:

package dubstep.brendan;

import android.content.Context;
import android.media.MediaPlayer;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;

public class TestButton extends Button {
private MediaPlayer mpButtonClick =MediaPlayer.create(getContext(),R.raw.firework);


public TestButton(final Context context, final AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

@Override
public boolean onTouchEvent(final MotionEvent event) {

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mpButtonClick.start();



    }
    if (event.getAction()==MotionEvent.ACTION_UP){
        mpButtonClick.pause();
        mpButtonClick.reset();
        mpButtonClick = MediaPlayer.create(getContext(), R.raw.firework);

    }
    return super.onTouchEvent(event);
}
}

我还有其他十二个扩展按钮和使用媒体播放器的类,但其中只有七个有效。其余的都没有。虽然如果我从 7 个工作类中的任何一个中删除 mediaplayer 对象,其中一个不工作的类开始工作。

此外,我的日志中出现以下错误:

MediaPlayer(226):   info/warning (1, 26)
PlayerDriver(30):   Command PLAYER_PREPARE completed with an error or info             PVMFErrResource
MediaPlayer(226):   error (1, -17)
PlayerDriver(30):   PVMFInfoErrorHandlingComplete
MediaPlayer(226):   create failed:
MediaPlayer(226):   java.io.IOException: Prepare failed.: status=0x1
MediaPlayer(226):   at android.media.MediaPlayer.prepare(Native Method)
MediaPlayer(226):   at android.media.MediaPlayer.create(MediaPlayer.java:644)
MediaPlayer(226):   at dubstep.brendan.TestButton8.<init>(TestButton8.java:11)
MediaPlayer(226):   at java.lang.reflect.Constructor.constructNative(Native Method)
MediaPlayer(226):   at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
MediaPlayer(226):   at android.view.LayoutInflater.createView(LayoutInflater.java:500)
MediaPlayer(226):   at  android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
MediaPlayer(226):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
MediaPlayer(226):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
MediaPlayer(226):   at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
MediaPlayer(226):   at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
MediaPlayer(226):   at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
MediaPlayer(226):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
MediaPlayer(226):   at android.app.Activity.setContentView(Activity.java:1622)
MediaPlayer(226):   at      dubstep.brendan.MultitouchtestActivity.onCreate(MultitouchtestActivity.java:33)
MediaPlayer(226):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
MediaPlayer(226):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
MediaPlayer(226):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
MediaPlayer(226):   at android.app.ActivityThread.access$2200(ActivityThread.java:119)
MediaPlayer(226):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
MediaPlayer(226):   at android.os.Handler.dispatchMessage(Handler.java:99)
MediaPlayer(226):   at android.os.Looper.loop(Looper.java:123)
MediaPlayer(226):   at android.app.ActivityThread.main(ActivityThread.java:4363)
MediaPlayer(226):   at java.lang.reflect.Method.invokeNative(Native Method)
MediaPlayer(226):   at java.lang.reflect.Method.invoke(Method.java:521)
MediaPlayer(226):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
MediaPlayer(226):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
MediaPlayer(226):   at dalvik.system.NativeStart.main(Native Method)

请注意,这是我的第 8 个按钮的“TestButton8”类有错误,并且后面的所有类也有同样的问题,正如我上面提到的,如果我删除 mediaplayer 对象,例如,如果我从 TestButton 中删除 mediaplayer上面的类,“TestButton8”类将开始工作。为什么会这样?

4

0 回答 0