0

コードにエラーがない場合、パブリッククラス DummyCrackedScreenBehaviour に MediaPlayer がありますが、サウンドはまだ聞こえません。電話の音は機能しています。
何が問題でしょうか?私は何を修正しないのですか?

public class DummyCrackedScreenBehaviour implements CrackedScreenBehaviour {
    String Tag="States";
    private final Context context;
    Activity activity;

    //старое исправить
    MediaPlayer mPlayer;
    ImageView image;
    int currentTime;
    int startTime;
    int count=0;
    int exit=0;
    int widthScreen;
    int heightScreen;
    int x;
    int y;


    public DummyCrackedScreenBehaviour(Context context, Activity crackActivity) {
        Log.d(Tag, "DummyCrackedScreenBehaviour/1 DummyCrackedScreenBehaviour");
        this.context = context;
        activity = crackActivity;
    }

    @Override
    public void start() {
        Log.d(Tag, "DummyCrackedScreenBehaviour/2 start");
        Toast.makeText(context, "OnStart", Toast.LENGTH_LONG).show();
    }

    @Override
    public void cancel() {
        Log.d(Tag, "DummyCrackedScreenBehaviour/3 cancel");
        Toast.makeText(context, "Cancel", Toast.LENGTH_LONG).show();
    }


    public void startCrack() {
        mPlayer = MediaPlayer.create(context, R.raw.glass);
        //  ((Button) findViewById(R.id.button1)).setOnClickListener(this);
        image = (ImageView) activity.findViewById(R.id.imageView1); 
        Log.d(Tag, "DummyCrackedScreenBehaviour/4 StartCrack");
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        activity.setContentView(R.layout.activity_crack);
        crack();   
    }

    private void crack() {
        Log.d(Tag, "DummyCrackedScreenBehaviour/5 crack");
        brightnessScreen();
        //Call audio method
        audibleFX();
        //Call visual effects
        setBackGround();
    //  visualFX();
        //Call vibrate method
        //  touchFX();
    //  startTime=getTime();


    }

    private int[] sizeScreen() {
        Log.d(Tag, "DummyCrackedScreenBehaviour/6 sizeScreen");
        Display display = activity.getWindowManager().getDefaultDisplay(); 
        widthScreen = display.getWidth();  // deprecated
        heightScreen = display.getHeight();
        int sizeScreen[]={widthScreen,heightScreen};
        return  sizeScreen;
    }


    private void setBackGround() {
        Log.d(Tag, "DummyCrackedScreenBehaviour/7 setBackGround");
        View mlayout= activity.findViewById(R.id.LL);
        mlayout.setBackgroundColor(Color.BLACK);
    }

    private void brightnessScreen() {
        Log.d(Tag, "DummyCrackedScreenBehaviour/8 brightnessScreen");
        WindowManager.LayoutParams layout = activity.getWindow().getAttributes();
        layout.screenBrightness = 1F;
        activity.getWindow().setAttributes(layout);
    }
    private void audibleFX() {
        Log.d(Tag, "DummyCrackedScreenBehaviour/9 audibleFX");
        //Play sound file
        mPlayer.start();
        Log.d(Tag, "audibleFX()");
    }
}

ひびの入った画面の動作

package com.amax.crackedscreen;


public interface CrackedScreenBehaviour {

    public void start();

    public void cancel();

    public void startCrack();

}
4

1 に答える 1

0

内部で Mediaplayer メソッドを呼び出してみてください

@Override
public void start() {
    Log.d(Tag, "DummyCrackedScreenBehaviour/2 start");
    Toast.makeText(context, "OnStart", Toast.LENGTH_LONG).show();
    startCrack();
}
于 2013-07-02T11:59:08.230 に答える