5

デフォルトのTICKサウンドを使用したいのですが、このコードをどこにどのように配置するかわかりません

view.playSoundEffect(SoundEffectConstants.CLICK);

このコードは別の投稿で見つかりました。

これは私が持っているコードです:

        protected void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final MediaPlayer mp = MediaPlayer.create(this, R.raw.blah);

        Button Button01 = (Button)this.findViewById(R.id.Button01);
        Button01.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                mp.start();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void onClick(View v){}

    public void disclaimerBTN (View v){
        Toast.makeText(this, "FAILED:      The remote object is " +
                            "not responding to this command",Toast.LENGTH_LONG).show();
    }
}

view.playでは、 .....コードをどこに配置しますか?とても有難い。

4

2 に答える 2

8

ボタンクリックイベントでAudioManager.playSoundEffectを使用するには、次のように試すことができます。

AudioManager audioManager = 
            (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

 Button01.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                 audioManager.playSoundEffect(SoundEffectConstants.CLICK);   
                 //mp.start();
            }
        });

参考までに、Googleのソースコードでこの例を見ることができます。

http://code.google.com/p/android-traditional-chinese-ime/source/browse/trunk/src/com/googlecode/tcime/SoundMotionEffect.java?r=13

于 2012-12-03T09:52:11.403 に答える