i have a crash with this code in my galaxy s but not in the simulator, where works fine
So, what is the possible cause of this error? thanks
package com.tct.soundTouch;
//imports ()
public class main extends Activity implements OnClickListener{
private MediaPlayer mp;
private MotionEvent event;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
开发者_StackOverflow社区this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
final ImageButton zero = (ImageButton) this.findViewById(R.id.button);
zero.setOnClickListener(this);
mp = MediaPlayer.create(this, R.raw.sound);
}
@Override
public void onClick(View v) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mp.setLooping(true);
mp.start();
break;
case MotionEvent.ACTION_UP:
mp.pause();
break;
}
}
}
If you don't have access to the system log, then surround your code with a try/catch block and spit out the exception in help of a dialog / text view.
My guess: The media format of your sound file isn't supported on the phone.
精彩评论