첫 번째 앱 여행에서 다른 오류가 발생했습니다. 앱이로드 될 때 소리를 내고 싶습니다. .wav 파일은 무엇입니까? 2 초 정도 지속되지만 이전 삼성 S4에서 앱을 실행하면 재생되지 않습니다. IDE 또는 아무 것도 볼 수있는 오류가 없습니다. 'mp'에 값이 있는지 확인했습니다. 게시물을 둘러 보면서 대부분의 사람들은 'mp'가 null이라는 문제가 있습니다. 광산에는 가치가 있지만 전화에서 소리가 나오지 않습니다 ... 다시 말하지만, 어떤 도움도 인정됩니다!android에서 사운드 재생
public class OpeningScreen extends Activity {
@Override
// create the screen state
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// connect the xml layout file
setContentView(R.layout.activity_opening_screen);
final MediaPlayer mp = new MediaPlayer();
mp.create(this, R.raw.welcome_message);
mp.start();
// create the on touch listener
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.opening_layout);
layout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// change the screen to a new state
Intent intent = new Intent(OpeningScreen.this, GameScreen.class);
// start the new activity
startActivity(intent);
// stop welcome sound (if still playing)
mp.stop();
return true;
}
});
}
}
내가 처음으로 그렇게했습니다. 그러나 mp는이 코드를 통과 한 후에도 여전히 null입니다. –
방금 다시했는데 이번에는 효과가있었습니다. 어쩌면 내가 파일 이름이나 일종의 일을 어지럽 혔을 수도 있습니다. 고맙습니다! –