我在列表视图中收到错误?

时间:2013-07-18 04:13:03

标签: view methods android-listview android-mediaplayer onclicklistener

Onclicklistener error 我实现了播放歌曲的列表视图。当我点击列表视图中的项目时,它将强制关闭。如果我在列表视图中调用媒体播放器。工作gud。但是在方法上,它的力量会越来越近。请帮我解决。

     public class ListMobileActivity extends ListActivity {
MediaPlayer mp;
boolean playing=false;
View preView;
 ImageView imageView;
 int itemno;

static final String[] MOBILE_OS = new String[] { "Songs1", "Songs2",
        "Songs3", "Songs4","SOngs5","Songs6","songs7","songs8","Songs9","Songs10"};
private static final String TAG = "LIstMobileActivity";
int songs []= {R.raw.lazy,R.raw.tamil,R.raw.turn,R.raw.lazy,R.raw.tamil,R.raw.lazy,R.raw.turn,R.raw.tamil,R.raw.turn};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //setListAdapter(new ArrayAdapter<String>(this, R.layout.list_mobile,
    //R.id.label, MOBILE_OS));

    setListAdapter(new MobileArrayAdapter(this, MOBILE_OS));


}

@Override
protected void onListItemClick(ListView l, View v, int pos, long id) {

    ListMobileActivity.this.playSample(pos);

    }

           private void playSample( int position)
        {

        AssetFileDescriptor afd = getApplicationContext().getResources().openRawResourceFd(songs[position]);


           try{
              if(this.mp.isPlaying())
            {
                this.mp.stop();


                this.mp.reset();}
                this.mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
                this.mp.prepare();
             this.   mp.start();
                afd.close();



        }
        catch (IllegalArgumentException e)
        {
            Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
        }
        catch (IllegalStateException e)
        {
            Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
        }
        catch (IOException e)
        {
            Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
        }
}}

0 个答案:

没有答案