0

我有一个 res/raw 文件夹,里面有 5 个我希望能够在我的应用程序中播放的 wav 文件。这些文件应该在列表视图中播放。我有某种方式,但我几乎可以肯定有更好的方式来做到这一点。这就是我迄今为止所拥有的。

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"
};

}

4

1 回答 1

0

试试下面的代码:

     MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.apple);
        mp.start();
于 2012-10-07T04:13:00.933 回答