Android Multimedia Analytics-get audio information via Mediastore

Source: Internet
Author: User

[Java]View Plaincopy
  1. public void Getalldata () {
  2. Contentresolver CR = Getapplication (). Getcontentresolver ();
  3. if (cr = = null) {
  4. return;
  5. }
  6. //Get All songs
  7. cursor cursor = cr.query (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
  8. NULL, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
  9. if (null = = cursor) {
  10. return;
  11. }
  12. Music Music;
  13. list<music> list = new arraylist<mainactivity.music> ();
  14. if (Cursor.movetofirst ()) {
  15. Do {
  16. //Song name
  17. String title = cursor.getstring (cursor
  18. . Getcolumnindex (MediaStore.Audio.Media.TITLE));
  19. //singer
  20. String singer = cursor.getstring (cursor
  21. . Getcolumnindex (MediaStore.Audio.Media.ARTIST));
  22. //albums
  23. String album = cursor.getstring (cursor
  24. . Getcolumnindex (MediaStore.Audio.Media.ALBUM));
  25. //Length
  26. Long size = Cursor.getlong (cursor
  27. . Getcolumnindex (MediaStore.Audio.Media.SIZE));
  28. //Time length
  29. int duration = cursor.getint (cursor
  30. . Getcolumnindex (MediaStore.Audio.Media.DURATION));
  31. //Path
  32. String URL = cursor.getstring (cursor
  33. . Getcolumnindex (MediaStore.Audio.Media.DATA));
  34. //display filename
  35. String _display_name = cursor.getstring (cursor
  36. . Getcolumnindex (MediaStore.Audio.Media.DISPLAY_NAME));
  37. //Type
  38. String Mime_type = cursor.getstring (cursor
  39. . Getcolumnindex (MediaStore.Audio.Media.MIME_TYPE));
  40. Music = new Music ();
  41. Music.setalbum (album);
  42. Music.setduration (duration);
  43. Music.setsinger (singer);
  44. Music.setsize (size);
  45. Music.settitle (title);
  46. Music.seturl (URL);
  47. Music.set_display_name (_display_name);
  48. Music.setmime_type (Mime_type);
  49. List.add (music);
  50. } while (Cursor.movetonext ());
  51. }
  52. System.out.println (List.size ());
  53. }
  54. class Music
  55. {
  56. private String title;
  57. private String singer;
  58. Private String album;
  59. private long size;
  60. private int duration;
  61. private String URL;
  62. private String _display_name;
  63. private String Mime_type;
  64. Public String Get_display_name () {
  65. return _display_name;
  66. }
  67. public void Set_display_name (String _display_name) {
  68. this._display_name = _display_name;
  69. }
  70. Public String Getmime_type () {
  71. return mime_type;
  72. }
  73. public void Setmime_type (String mime_type) {
  74. this.mime_type = Mime_type;
  75. }
  76. Public String GetTitle () {
  77. return title;
  78. }
  79. public void Settitle (String title) {
  80. this.title = title;
  81. }
  82. Public String Getsinger () {
  83. return singer;
  84. }
  85. public void Setsinger (String singer) {
  86. This.singer = singer;
  87. }
  88. Public String Getalbum () {
  89. return album;
  90. }
  91. public void Setalbum (String album) {
  92. this.album = album;
  93. }
  94. public Long GetSize () {
  95. return size;
  96. }
  97. public void SetSize (long size) {
  98. this.size = size;
  99. }
  100. public int getduration () {
  101. return duration;
  102. }
  103. public void Setduration (int duration) {
  104. this.duration = Duration;
  105. }
  106. Public String GetUrl () {
  107. return URL;
  108. }
  109. public void SetUrl (String url) {
  110. this.url = URL;
  111. }
  112. @Override
  113. Public String toString () {
  114. return "Music [title=] + title + ", singer= "+ singer + ", album= "
  115. + album + ", size=" + size + ", duration=" + Duration
  116. + ", url=" + URL + ", _display_name=" + _display_name
  117. + ", mime_type=" + Mime_type + "]";
  118. }
  119. }

http://blog.csdn.net/lzh7752/article/details/45131539

Android Multimedia Analytics-get audio information via Mediastore

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.