2012-06-29 56 views
0

我是Android開發的新手,並試圖開發一個簡單的應用程序,其中使用按鈕來播放聲音。我想使用的Soundpool並發現每個教程提供製作的Soundpool對象之後,再加入這樣的代碼:使用soundpool獲取聲音

soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { 
      @Override 
      public void onLoadComplete(SoundPool soundPool, int sampleId, 
        int status) { 
       loaded = true; 
      } 
     }); 

但是當我嘗試在Eclipse中使用此代碼,它說

的方法new SoundPool.OnLoadCompleteListener(){}的onLoadComplete(SoundPool,int,int)必須重寫超類方法。 並建議刪除@override表示法。這應該發生,如果沒有這樣的方法??爲什麼我得到這個錯誤?

當我把soundID = soundPool.load(this,R.raw.mysound,1);

上述代碼之後,蝕說,在類型的Soundpool的方法負載(上下文,INT,INT)是不適用的參數(新View.OnClickListener(){},INT,INT)

此是我的全部代碼: public class FirstActivity extends Activity活動第一次創建時調用。 */

private SoundPool soundPool; 
int soundID; 
boolean loaded = false; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Button bPlay = (Button) findViewById(R.id.bPlay); 
    final TextView aRing = (TextView)findViewById(R.id.tAlarmRinging); 

    bPlay.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      aRing.setVisibility(View.VISIBLE); 

      soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { 
       @Override 
       public void onLoadComplete(SoundPool soundPool, int sampleId, 
         int status) { 
        loaded = true; 
       } 
      }); 
      soundID = soundPool.load(this, R.raw.mysound, 1); 
     } 

     }); 
} 

}

+0

編譯它時編譯它? – JMelnik

+0

即使在刪除了ovverride表示法之後,它也給了我更多的錯誤 – tanvi

+0

您的項目在屬性中有8個API級別嗎? – sandrstar

回答

0

你應該嘗試設置項目的合規性水平爲Java 1.7或類似這樣的東西。

右鍵單擊該項目,轉到Properties-> Java Compiler->選中Enable project specific settings->然後選擇最高的編譯器合規性級別。

如果這不起作用,那麼右鍵單擊項目,AndroidTools->修復項目屬性。

+0

非常感謝:) – tanvi

+0

但對於soundPool.load,它仍然說在類型SoundPool中的方法load(Context,int,int)不適用於參數(new View.OnClickListener( ){},int,int) – tanvi

+0

沒問題。總是歡迎.. –