Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read all the music in the memory of the phone by Android

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to read all the music in the memory of the mobile phone by Android, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.

To read the music information in the phone's memory, you need to do the following steps:

1) create a XML file, store the obtained information, and use the ListView control

2) create a new XML file to lay out the item objects in LIstView

3) you need to create a Music class to store the main information of the Music you need to obtain.

4) you need to create a help class to get the music information on the phone, and pass the information through a collection class.

5) create a custom adapter to load each child Item of ListView

6) load the data and return to the user interface

The main code implementation is as follows:

1. Helper module

Public ArrayList getMusic (Context context) {arrayList = new ArrayList (); resolver = context.getContentResolver (); cursor = resolver.query (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if (cursor! = null) {while (cursor.moveToNext ()) {musicInfo = new MusicInfo (); musicInfo.setSinger_Name (cursor.getString (cursor. GetColumnIndex (MediaStore.Audio.Media.ARTIST) / / singer name musicInfo.setSong_Name (cursor.getString (cursor. GetColumnIndex (MediaStore.Audio.Media.TITLE); / / song name musicInfo.setSong_size (FormatChange.formatSize (cursor.getInt (cursor. GetColumnIndex (MediaStore.Audio.Media.SIZE); / / size of the song musicInfo.setSong_ time (FormatChange.toTime (cursor. GetColumnIndexOrThrow (MediaStore.Audio.Media.DURATION) / / Song time musicInfo.setUrl (cursor.getString (cursor .getColumnIndex (MediaStore.Audio.Media.DATA)); arrayList.add (musicInfo);}} cursor.close (); return arrayList;}

I do it in a normal way, or I can use a static implementation.

II. Adapter module

Private ArrayList arrayList; private Context context; private TextView music_singer,music_name,music_size; private MusicInfo musicInfo; public Music_adapter (Context context,ArrayList arrayList) {this.context=context; this.arrayList=arrayList;} @ Override public int getCount () {return arrayList.size ();} @ Override public Object getItem (int position) {return arrayList.get (position);} @ Override public long getItemId (int id) {return id } @ Override public View getView (int position, View view, ViewGroup arg2) {if (view==null) {view=LayoutInflater.from (context) .comparate (R.layout.musicFormlNull);} music_name= (TextView) view.findViewById (R.id.music_name); music_singer= (TextView) view.findViewById (R.id.music_singer); music_size= (TextView) view.findViewById (R.id.music_size); musicInfo= (MusicInfo) arrayList.get (position) Music_name.setText (musicInfo.getSong_Name ()); music_singer.setText (musicInfo.getSinger_Name () + "|" + musicInfo.getSong_time ()); music_size.setText (musicInfo.getSong_size ()); / / you must convert return view to string type here. } Thank you for reading this article carefully. I hope the article "how to read all the music in the memory of your mobile phone" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report