마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

SoundPool 함수 사용해서 피아노를 만들었는데 버튼을 눌러도 소리가 나지 않습니다. [closed]

0 추천

xml은 스크롤뷰, 프레임 레이아웃, 리니어 레이아웃, 버튼 이용해서 만들었습니다.

아무리 해결해보려해도 어디가 문제인지 모르겠습니다..

<?xml version="1.0" encoding="utf-8"?>

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <Button
                    android:id="@+id/do1"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:background="@android:drawable/editbox_background_normal"
                    android:onClick="mOnClick" />

                <Button
                    android:id="@+id/re1"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:background="@android:drawable/editbox_background_normal"
                    android:onClick="mOnClick" />

                ////////////////////////////////////생략////////////////////////////////////

                <Button
                    android:id="@+id/do5"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:background="@android:drawable/editbox_background_normal"
                    android:onClick="mOnClick" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <Button
                    android:id="@+id/doShap1"
                    android:layout_width="200dp"
                    android:layout_height="40dp"
                    android:layout_gravity="end"
                    android:layout_marginTop="40dp"
                    android:background="@android:drawable/screen_background_dark"
                    android:onClick="mOnClick" />

                <Button
                    android:id="@+id/reShap1"
                    android:layout_width="200dp"
                    android:layout_height="40dp"
                    android:layout_gravity="end"
                    android:layout_marginTop="20dp"
                    android:background="@android:drawable/screen_background_dark"
                    android:onClick="mOnClick" />

                /////////////////////////////////////////생략/////////////////////////////////////////////////

                <Button
                    android:id="@+id/doShap5"
                    android:layout_width="200dp"
                    android:layout_height="40dp"
                    android:layout_gravity="end"
                    android:layout_marginTop="80dp"
                    android:background="@android:drawable/screen_background_dark"
                    android:onClick="mOnClick" />

            </LinearLayout>
        </FrameLayout>
    </ScrollView>

 

자바 코드입니다

package com.example.pianoex2;

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;

public class MainActivity extends AppCompatActivity {

SoundPool pool;

    //백건
    int do1, re1, mi1, pa1, sol1, ra1, si1;
    int do2, re2, mi2, pa2, sol2, ra2, si2;
    int do3, re3, mi3, pa3, sol3, ra3, si3;
    int do4, re4, mi4, pa4, sol4, ra4, si4;
    int do5;
    //백건
    int doShap1, reShap1, paShap1, solShap1, raShap1;
    int doShap2, reShap2, paShap2, solShap2, raShap2;
    int doShap3, reShap3, paShap3, solShap3, raShap3;
    int doShap4, reShap4, paShap4, solShap4, raShap4;
    int doShap5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window win=getWindow();
        win.requestFeature(Window.FEATURE_NO_TITLE);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_main);

        pool=new SoundPool(4, AudioManager.STREAM_MUSIC,0);
        do1=pool.load(this,R.raw.do1,1);
        re1=pool.load(this,R.raw.re1,1);
        mi1=pool.load(this,R.raw.mi1,1);
        pa1=pool.load(this,R.raw.pa1,1);
        sol1=pool.load(this,R.raw.sol1,1);
        ra1=pool.load(this,R.raw.ra1,1);
        si1=pool.load(this,R.raw.si1,1);
        //////////////////////////////////////////////////
        do2=pool.load(this,R.raw.do2,1);
        re2=pool.load(this,R.raw.re2,1);
        mi2=pool.load(this,R.raw.mi2,1);
        pa2=pool.load(this,R.raw.pa2,1);
        sol2=pool.load(this,R.raw.sol2,1);
        ra2=pool.load(this,R.raw.ra2,1);
        si2=pool.load(this,R.raw.si2,1);
        ////////////////////////////////////////////////////
        do3=pool.load(this,R.raw.do3,1);
        re3=pool.load(this,R.raw.re3,1);
        mi3=pool.load(this,R.raw.mi3,1);
        pa3=pool.load(this,R.raw.pa3,1);
        sol3=pool.load(this,R.raw.sol3,1);
        ra3=pool.load(this,R.raw.ra3,1);
        si3=pool.load(this,R.raw.si3,1);
        ////////////////////////////////////////////////
        do4=pool.load(this,R.raw.do4,1);
        re4=pool.load(this,R.raw.re4,1);
        mi4=pool.load(this,R.raw.mi4,1);
        pa4=pool.load(this,R.raw.pa4,1);
        sol4=pool.load(this,R.raw.sol4,1);
        ra4=pool.load(this,R.raw.ra4,1);
        si4=pool.load(this,R.raw.si4,1);
        //////////////////////////////////////////////////
        do5=pool.load(this,R.raw.do5,1);

        ///////////////////흑건//////////////////////////
        doShap1=pool.load(this,R.raw.doshap1,1);
        reShap1=pool.load(this,R.raw.reshap1,1);
        
////////////////////////////////////////////생략///////////////////////////////////////

        reShap4=pool.load(this,R.raw.rashap4,1);
        ////////////////////////////////////////////////////
        doShap5=pool.load(this,R.raw.doshap5,1);

    }
    public void mOnClick(View v){

        switch(v.getId()) {
            case R.id.do1:
                pool.play(do1, 1, 1, 0, 0, 1);
                break;
            case R.id.re1:
                pool.play(re1, 1, 1, 0, 0, 1);
                break;
           
/////////////////////////////////////////////////생략/////////////////////////////////////////

                break;
            case R.id.si4:
                pool.play(si4, 1, 1, 0, 0, 1);
                break;
            /////////////////////////////////////////////////////////////
            case R.id.do5:
                pool.play(do5, 1, 1, 0, 0, 1);


                /////////////////흑건//////////////////////////////////////////
            case R.id.doShap1:
                pool.play(doShap1, 1, 1, 0, 0, 1);
                break;
            case R.id.reShap1:
                pool.play(reShap1, 1, 1, 0, 0, 1);
                break;
          
///////////////////////////////////////////////생략//////////////////////////////////////////////

                break;
            case R.id.raShap4:
                pool.play(raShap4, 1, 1, 0, 0, 1);
                break;
                /////////////////////////////////////////////////////////////
            case R.id.doShap5:
                pool.play(doShap5, 1, 1, 0, 0, 1);
                break;
        }
    }
}

 

질문을 종료한 이유: 코드에는 문제가 없고 에뮬레이터가 문제였음
익명사용자 님이 6월 12일 질문
6월 12일 closed
...