In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.