출처 : http://www.cyworld.com/kenur/3732812

SoundPool(int maxStreams, int streamType, int srcQuality)

 

첫번째 = 동시에 재생가능한 최대 스트림수

두번째 = 오디오 스트림 STREAM_MUSIC 고정

세번째 = 샘플링 품질

 

객체를 생성후에  사운드를 아래와같이로드함

 

int load(Context context, int resld, int priority)

int load(String path, int priority)

 

리로스나 파일로부터 사운드를 로드 한다

 

 

재생메소드

int play(int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)

 

첫번째 = 재생할사운드

두번째 = 좌 볼륨

세번째 = 우 볼륨

네번째 = 재생우선순위

다섯 = 반복설정

여섯 = 재생속도

 


 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
<Button
	android:id="@+id/play1"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="보통재생"
/>
<Button
	android:id="@+id/play2"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="볼륨 절반 재생"
/>
<Button
	android:id="@+id/play3"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="3회 재생"
/>			
<Button
	android:id="@+id/play4"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="0.5배속 재생"
/>
<Button
	android:id="@+id/play5"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="2배속 재생"
/>
<Button
	android:id="@+id/play6"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="3배속 재생"
/>			
</LinearLayout>


 

package test.Layout;

import android.app.*;
import android.content.*;
import android.media.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class Layout extends Activity 
{
	SoundPool pool;
	int ddok;
	
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        pool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
		ddok = pool.load(this, R.raw.ddok, 1);
        
        findViewById(R.id.play1).setOnClickListener(mClickListener);
        findViewById(R.id.play2).setOnClickListener(mClickListener);
        findViewById(R.id.play3).setOnClickListener(mClickListener);
        findViewById(R.id.play4).setOnClickListener(mClickListener);
        findViewById(R.id.play5).setOnClickListener(mClickListener);
        findViewById(R.id.play6).setOnClickListener(mClickListener);
    }
    
    Button.OnClickListener mClickListener = new Button.OnClickListener()
    {
    	public void onClick(View v)
    	{
    		MediaPlayer player;
			switch (v.getId()) 
			{
			case R.id.play1:
				pool.play(ddok, 1, 1, 0, 0, 1);
				break;
			case R.id.play2:
				pool.play(ddok, 0.5f, 0.5f, 0, 0, 1);
				break;
			case R.id.play3:
				pool.play(ddok, 1, 1, 0, 2, 1);
				break;
			case R.id.play4:
				pool.play(ddok, 1, 1, 0, 0, 0.5f);
				break;
			case R.id.play5:
				pool.play(ddok, 1, 1, 0, 0, 2);
				break;
				
			case R.id.play6:
				pool.play(ddok, 1, 1, 0, 0, 3);
				break;
			}

    	}
    };
}

+ Recent posts