android音乐播放器问题

包包是大帅 发布于 2014/06/07 15:28
阅读 71
收藏 0
package com.example.clock;


import java.io.File;
import java.io.IOException;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;










import android.R.string;
import android.app.Activity;
import android.app.ListActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;


public class Naoling extends ListActivity implements OnClickListener{
private TextView txt1;

private Button btn7;
private List<String> musiclist = new ArrayList<String>();
private static final String mp3Path="/mnt/sdcard/";
private int number=0;
private String abc;
private SQLiteDatabase db;
private MyHelp myhelp;
private Cursor cur1;
private MediaPlayer med;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);

musiclist();

btn7=(Button)findViewById(R.id.btn7);
btn7.setOnClickListener(this);

}


private void musiclist() {
// TODO Auto-generated method stub

File fl=new File(mp3Path);
if (fl.listFiles(new MusicFilter()).length>0) {
for (File file : fl.listFiles(new MusicFilter())) {
musiclist.add(file.getName());
}
ArrayAdapter<String> ada=new ArrayAdapter<String>(Naoling.this, android.R.layout.simple_list_item_1, musiclist);
setListAdapter(ada);
}
}


@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
myhelp=new MyHelp(Naoling.this);
db = myhelp.getWritableDatabase();
ContentValues con=new ContentValues();
con.put("name", abc);
db.insert("user1", null, con);
db.close();
myhelp.close();
Toast.makeText(getApplicationContext(), "你成功保存", Toast.LENGTH_SHORT).show();
}
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
number=position;
abc=mp3Path+musiclist.get(number);

System.out.println(abc);
Toast.makeText(getApplicationContext(), abc, Toast.LENGTH_SHORT).show();



try {


med.setDataSource(abc);
med.prepare();
med.start();
med.setOnCompletionListener(new OnCompletionListener() {


public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();


}
});
} catch (Exception e) {
e.printStackTrace();
}

}
}

这是我的代码,有点乱,主要请大家帮我看看listview的listItemclick方法里,我通过点击listview的view得到SD卡的音乐位置,然后设置mp3播放,但没反应,这样有错嘛?急求大神哇
加载中
返回顶部
顶部