中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

本地掃描音樂文件

發布時間:2020-04-07 00:06:21 來源:網絡 閱讀:441 作者:鷺明 欄目:開發技術

本地掃描音樂文件


public class ScannerActivity extends Activity {


private ListView mlistview;

ArrayList<MusicInfo> list = new ArrayList<MusicInfo>();

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;

}

}


}


}




向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

尉氏县| 台安县| 镶黄旗| 修水县| 诸暨市| 文安县| 五指山市| 延川县| 应城市| 东光县| 镇坪县| 定南县| 门源| 平和县| 舟曲县| 大连市| 江西省| 西和县| 抚远县| 南靖县| 茌平县| 当雄县| 讷河市| 泗阳县| 靖江市| 磐石市| 麻阳| 文化| 黔江区| 庆云县| 延寿县| 新竹市| 聂荣县| 怀化市| 泰来县| 南皮县| 西充县| 漯河市| 三都| 许昌市| 偏关县|