十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
本地扫描音乐文件
网站的建设创新互联专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为成都石牌坊等企业提供专业服务。public class ScannerActivity extends Activity {
private ListView mlistview;
ArrayList
private MyAdapter myAdapter;
private MyReceiver myReceiver;
private ProgressBar progressbar;
private MyApplication myApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
myApplication = (MyApplication) getApplication();
myApplication.addActity(this);
progressbar = (ProgressBar) findViewById(R.id.scanner_progressbar);
mlistview = (ListView) findViewById(R.id.listView1);
myAdapter = new MyAdapter();
mlistview.setAdapter(myAdapter);
}
public void btnScanner(View v) {
Intent intent = new Intent(Intent.ACTION_MEDIA_MOUNTED);
Uri uri = Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath());
intent.setData(uri);
sendBroadcast(intent);
}
private void scannerMusic() {
list.clear();
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(Media.EXTERNAL_CONTENT_URI, null, null, null, null);
boolean first = cursor.moveToFirst();
while (first) {
String singer = cursor.getString(cursor.getColumnIndex(Media.ARTIST));
String musicname = cursor.getString(cursor.getColumnIndex(Media.DISPLAY_NAME));
String musicurl = cursor.getString(cursor.getColumnIndex(Media.DATA));
int musiclen = cursor.getInt(cursor.getColumnIndex(Media.DURATION));
list.add(new MusicInfo(singer, musicname, musiclen, musicurl, null));
first = cursor.moveToNext();
}
cursor.close();
myAdapter.notifyDataSetChanged();
}
class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View inflate = getLayoutInflater().inflate(R.layout.scanner_item, null);
TextView musicname = (TextView) inflate.findViewById(R.id.scanner_musicname);
TextView singer = (TextView) inflate.findViewById(R.id.scanner_singer);
MusicInfo musicInfo = list.get(position);
musicname.setText(musicInfo.getMusicName());
singer.setText(musicInfo.getSinger());
return inflate;
}
}
@Override
protected void onStart() {
myReceiver = new MyReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
filter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
filter.addDataScheme("file");
registerReceiver(myReceiver, filter);
super.onStart();
}
@Override
protected void onStop() {
unregisterReceiver(myReceiver);
super.onStop();
}
@Override
protected void onDestroy()
{
myApplication.removeActivity(this);
super.onDestroy();
}
class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case Intent.ACTION_MEDIA_SCANNER_STARTED:
Toast.makeText(ScannerActivity.this, "开始扫描", Toast.LENGTH_SHORT).show();
break;
case Intent.ACTION_MEDIA_SCANNER_FINISHED:
Toast.makeText(ScannerActivity.this, "结束扫描", Toast.LENGTH_SHORT).show();
mlistview.setVisibility(View.VISIBLE);
scannerMusic();
progressbar.setVisibility(View.GONE);
break;
default:
break;
}
}
}
}
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。