사운드 보드 앱을 만들려고하고 있지만 사운드 파일을 처리하는 데 문제가 있습니다. 좀 더 구체적으로 말하자면 버튼을 눌렀을 때 해당 사운드를 재생할 수있는 방법을 모릅니다.Android 버튼 사운드 보드
나는 각각의 사운드 파일 및 버튼 만 시작까지의 응용 프로그램 충돌을위한 미디어 플레이어를 구현하는 노력이 방법 Play sound on button click android
를 사용하여 시도했습니다.
I가/
그것이 작동하는 방법에 어떤 생각 원시 (10)는 SRC/고해상도의 원시 파일에있는 사운드 파일을 해당하는 10 개 버튼 /?
//this is a breaking bad soundboard app, so please excuse the language. Sorry if you find it offensive
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
whatup = (Button)this.findViewById(R.id.button);
haveatit = (Button)this.findViewById(R.id.button2);
hello = (Button)this.findViewById(R.id.button3);
whining = (Button)this.findViewById(R.id.button7);
money = (Button)this.findViewById(R.id.button4);
yeah= (Button)this.findViewById(R.id.button8);
miserable = (Button)this.findViewById(R.id.button5);
mother = (Button)this.findViewById(R.id.button9);
gatorade = (Button)this.findViewById(R.id.button6);
science = (Button)this.findViewById(R.id.button10);
whatup.setOnClickListener(this);
haveatit.setOnClickListener(this);
hello.setOnClickListener(this);
whining.setOnClickListener(this);
money.setOnClickListener(this);
yeah.setOnClickListener(this);
miserable.setOnClickListener(this);
mother.setOnClickListener(this);
gatorade.setOnClickListener(this);
science.setOnClickListener(this);
WhatUp = MediaPlayer.create(MainActivity.this, R.raw.whatupb);
HaveAtIt = MediaPlayer.create(MainActivity.this, R.raw.haveatit);
Hello = MediaPlayer.create(MainActivity.this, R.raw.hello);
Whining = MediaPlayer.create(MainActivity.this, R.raw.stopwhining);
Money = MediaPlayer.create(MainActivity.this, R.raw.wheresmymoney);
Yeah = MediaPlayer.create(MainActivity.this, R.raw.yeahb);
Miserable = MediaPlayer.create(MainActivity.this, R.raw.miserableb);
Mother = MediaPlayer.create(MainActivity.this, R.raw.motherofgod);
Gatorade = MediaPlayer.create(MainActivity.this, R.raw.gatorade);
Science = MediaPlayer.create(MainActivity.this, R.raw.yeahscience);
}
이 버튼을 누르면 처리됩니다. 분명히 더 있어야 할 필요가 있지만 버튼을 테스트하는 중이었고 시작하려고 할 때 충돌이 발생합니다.
@Override
public void onClick(View view) {
if(view==whatup)
{
WhatUp.start();
}
}
로그 고양이 오류 : http://imgur.com/ZWYsLl7
도움이 될 것 같습니다. 방금 미디어 플레이어 대신 사운드 풀을 사용해야한다는 기사를 발견했습니다. 차이점을 알고 있습니까? – Programatic
저는 방금 반대 의견을 읽었습니다 : http://www.stealthcopter.com/blog/2010/08/android-soundpool-vs-mediaplayer-focus-on-soundboards-and-memory-problems/ -Awesome! ^^ – Fllo
나는 그것을 뒤집었고 시작시 여전히 충돌이 난다. 다음은 onCreate에 대한 코드입니다. – Programatic