这是我的代码,用soundpool输出音频,button=(button)findViewById(R.id.start);这一句说无法解析为类型。packagecom.example.soundpoolmusic;importandroid.media.AudioManager;impo...
这是我的代码,用soundpool输出音频,button =(button)findViewById(R.id.start);这一句说无法解析为类型。
package com.example.soundpoolmusic;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private SoundPool soundpool;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button =(button)findViewById(R.id.start);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
soundpool = new SoundPool(20,AudioManager.STREAM_MUSIC,0);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
try{
AssetManager assetmanger = getAssets();
AssetFileDescriptor descriptor = assetmanger.openFd("QQ");
int musicid = soundpool.load(descriptor, 1);
soundpool.play(musicid, 1, 1, 0, -1, 1);
}catch(Exception e){
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
展开