android内置歌曲

package com.android.music;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.util.EncodingUtils;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class SystemAudioPlayer extends Activity{
 
 private String songName;
 private List<Map<String,Object>> data;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      songName = this.getResources().getString(R.string.song_name);
     data = getFiles("/system/media");
  
        this.setContentView(R.layout.system_audio_list); 
       
     ListView listView2 = (ListView)findViewById(R.id.setbuttonlist);
     SimpleAdapter simpleAdapter = new SimpleAdapter(this,data,R.layout.list_items2,new String[]{"subImage","subTitle"},new int[]{R.id.subImage,R.id.subTitle});
     listView2.setAdapter(simpleAdapter);
     
     listView2.setOnItemClickListener(new OnItemClickListener() {

   public void onItemClick(AdapterView<?> parent, View view, int position,
     long id) {
    // TODO Auto-generated method stub
    Map<String,Object> map = data.get(position);
    Intent it = new Intent(Intent.ACTION_VIEW);
    it.setDataAndType(Uri.parse("file://"+map.get("url").toString()), "audio/mp3");
    it.setComponent(new ComponentName("com.android.music","com.android.music.MediaPlaybackActivity"));
    startActivity(it);

    
   }
  });
 }
 
 public List<Map<String,Object>> getFiles(String path)
 {
  Log.v("LEIYONGHUI", path);
  Log.d("SystemAudioPlayer", "@@@@@@@@@@@@@@@@@@@@@@ song_name : "+songName);
  List<Map<String,Object>> fileList = new ArrayList<Map<String,Object>>();
  File rootFile = new File(path);
  File[] file_array = rootFile.listFiles();
  Map<String,Object> map3 = null;
  
  if(null != file_array && file_array.length > 0)
  {
   for(File file : file_array)
   {
    if(file.isFile())
    {
     String filePath = file.getPath();    
     String fileName = file.getName();
   
     Log.v("LEIYONGHUI", filePath);
     Log.v("LEIYONGHUI", fileName);
     
     if((fileName.endsWith(".MP3") || fileName.endsWith(".mp3")) && !fileName.startsWith("bootaudio") && !fileName.startsWith("shutaudio"))
     {
      
      map3 = new HashMap<String,Object>();
      map3.put("subImage", R.drawable.ic_mp_song_playback);
      map3.put("subTitle", songName);
         map3.put("url", filePath);
         fileList.add(map3);
     }
    }

   }
  }

  return fileList;
 }
}

布局文件:system_audio_list.xml

<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <ListView android:id="@+id/setbuttonlist" android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>

list_items2.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 android:id="@+id/RelativeLayout01"
 android:layout_width="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content"
 android:paddingBottom="4dip"
 android:paddingLeft="12dip"
 android:paddingRight="12dip">
<ImageView
 android:id="@+id/subImage"
 android:layout_height="40dip"
 android:layout_width="40dip"
 android:layout_gravity="center_vertical"
 />
<TextView
 android:paddingLeft="10dip"
    android:id="@+id/subTitle"
    android:textSize="25dip"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
 />
</LinearLayout>

 

转载于:https://my.oschina.net/poineer/blog/162518

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值