0
我有一個帶有5個wav文件的res/raw文件夾,我希望能夠在我的應用程序中播放。這些文件應該在列表視圖中播放。我有一定的方式,但我幾乎肯定有一個更好的方法來做到這一點。這是我到目前爲止。從文件夾中插入音頻剪輯
package churchapp.acosta;
import android.app.ListActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class Services extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,R.layout.single_item, clips));
ListView list = getListView();
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
//what do i put here in order for user to play clip when
//a list choice is selected?
//i tried the above code below but there has to be a better way?
/*MediaPlayer mPlayer2;
if(position==0)
{
mPlayer2= MediaPlayer.create(Services.this, R.raw.clip1);
mPlayer2.start();
}*/
}
});
}
static final String[] clips= new String[]{
"This Weeks service","Last Weeks Service","3 Weeks Ago Service","4 Weeks ago Service ","5 Weeks Ago Service"
};
}