activitymain.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SoundPool" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AudioManager" />
</LinearLayout>
MainActibity.java
package com.example.testex16;
import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
AudioManager audioManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn1 = (Button)findViewById(R.id.btn1);
Button btn2 = (Button)findViewById(R.id.btn2);
audioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
int soundId = soundPool.load(MainActivity.this, R.raw.ddok, 1);
soundPool.play(soundId, 1, 1, 0, 0, 1);
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
audioManager.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
'Android' 카테고리의 다른 글
이벤트 처리 - 콜백 메서드 재정의 (0) | 2013.03.27 |
---|---|
출력 - 진동(vibrate) (0) | 2013.03.27 |
출력 - 토스트(Toast) (0) | 2013.03.27 |
레이아웃 파리미터(Layoutparameter) 변경 (0) | 2013.03.27 |
레이아웃 파라미터(layoutparmeter) (0) | 2013.03.27 |