我的公共类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()");
}
}
CrackedScreenBehavior
package com.amax.crackedscreen;
public interface CrackedScreenBehaviour {
public void start();
public void cancel();
public void startCrack();
}
答案 0 :(得分:0)
尝试在
中调用您的Mediaplayer方法@Override
public void start() {
Log.d(Tag, "DummyCrackedScreenBehaviour/2 start");
Toast.makeText(context, "OnStart", Toast.LENGTH_LONG).show();
startCrack();
}