qq_38813780
清水鼻涕泡
2018-05-01 07:10

安卓按钮播放本地音频

5
  • android
  • arraylist
  • hashmap
  • url
  • 音乐

实现点击按钮播放本地WAV音乐,我现在是这样写的
先获取本地WAV音乐的路径到List里,(直接显示文件路径)然后设置一个SimpleAdapter显示 现在我不知道怎么点击播放按钮能放相应的WAV图片说明
List> listitem = new ArrayList>();
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/Music");
File[] files = file.listFiles();
if (files != null) {
for (File file2 : files) {
String s = file2.getPath();
if (s.endsWith("wav")) {
Map showitem = new HashMap();
showitem.put("url", s);
listitem.add(showitem);
} else {
continue;
}
}
}
SimpleAdapter myAdapter = new SimpleAdapter(getApplicationContext(), listitem, R.layout.music_choice2
, new String[]{"url"}, new int[]{R.id.wavurl});

    MyListView.setAdapter(myAdapter);
    MyListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            HashMap<String, String> map = (HashMap<String, String>) adapterView.getItemAtPosition(i);
            //String content= (String) adapterView.getItemAtPosition(i);
            String content = map.get("url");
            Toast.makeText(MusicChoiceActivity.this, "点击内容" + i + "   " + content, Toast.LENGTH_SHORT).show();
            System.out.println("点击内容" + i + "   " + content);
            Intent intent = new Intent(MusicChoiceActivity.this, localtestActivity.class);
            intent.setData(Uri.parse(content));
            setResult(Activity.RESULT_OK, intent);
            System.out.println("开始跳转");
            finish();
        }
    });
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐