English 中文(简体)
向日圆的Android SDK发射慢速按钮
原标题:Slow Button firing in Android SDK for Eclipse

获得一些日蚀的音频文件没有问题: 当按下机器屏幕上的按钮和机器屏幕上的按钮时, java 要正确播放一些音频文件: java 。 但是, 我试图做的程序是一个制动器工作室, 您只能如此快速地按下按钮 。 在紧接前( 大约 5 秒) 按下同一按钮之后, 您可以按下按钮来点音频样本, 时间稍有延迟 。 显然, 这在能够按下指定时间的按钮时会给音乐程序带来问题 。 任何关于我如何用应用程序快速按下按钮的建议都非常重要?

package studio.music;

import android.app.Activity;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class StudioActivity extends Activity implements OnClickListener{

MediaPlayer mp1,mp2;
Button button_one,button_two;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { //The activity is being Created   Create any threads/streams here
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mp1 = MediaPlayer.create(this, R.raw.bassfifteen);
    mp2 = MediaPlayer.create(this, R.raw.snarenine);
        button_one = (Button) findViewById(R.id.buttonOne);
            button_one.setOnClickListener(this);            
        button_two = (Button) findViewById(R.id.buttonTwo);
            button_two.setOnClickListener(this);        
时 时

@Override
protected void onStart(){ //The activity is about to become visible
    super.onStart();    
    //TODO set state for program start
时 时

@Override
protected void onResume(){ //The activity has become visible(it is now "resumed")
    super.onResume();
    //TODO set state for program resume
时 时

@Override
protected void onPause(){ // Another activity is taking focus (this activity will be "paused")
    super.onPause();
    //TODO set state for program hang
时 时

@Override
protected void onStop(){ // This activity is no longer visibled (it is "stopped")
    super.onStop();
    //TODO set state for program drop back
时 时

@Override
protected void onDestroy(){ // The Activity is about too be destoryed (exiting)  Destroy all threads and streams here
    super.onDestroy();
    //TODO set state for program exit
时 时

@Override
public void onClick(View v) {

//Where the audio is fired  
if(v == button_one){    mp1.start();时 时
if(v == button_two){    mp2.start();时 时
时 时

时 时

问题回答

使用 < a href=> "http:// developmenter.android.com/ reference/android/media/SoundPool.html" rel="nofol"\\ code >SoundPool 提供低长重播。

可在“http://www.androidsnippets.com/playing-sound-fx-for-a-game” rel=“nofollow”>Android Snippets 上查阅可供使用的样本。您很容易根据您的需要调整样本。





相关问题
Playing a Sound With Monotouch

No matter what I try (build -> content, NSUrl, filename) I get a null exception : file not found when I try to play a .caf sound file in monotouch. //var path = NSBundle.MainBundle.PathForResource("...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

Play sound in iPhone web app with Javascript?

I m currently creating an iPhone web application for piano chords, and I wanted to add an option that would let the user press a Play button and play the selected chord. However, I m not sure how to ...

热门标签