Created
September 3, 2018 10:50
-
-
Save trustidkid/1a81c511f665951acaf3bb59f645f6f4 to your computer and use it in GitHub Desktop.
Music App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.truvp; | |
import android.content.ContentResolver; | |
import android.content.Context; | |
import android.database.Cursor; | |
import android.media.Image; | |
import android.media.ImageReader; | |
import android.net.Uri; | |
import android.provider.MediaStore; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.GridView; | |
import android.widget.ImageView; | |
import android.widget.ListView; | |
import android.widget.VideoView; | |
import java.io.File; | |
import java.util.ArrayList; | |
public class music_list extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_music_list); | |
String currTitle ; | |
String currentArtist; | |
String currentDuration; | |
//declare array for the list of music to display | |
ArrayList<Music> musicList = new ArrayList<>(); | |
ContentResolver contentResolver = getContentResolver(); | |
Uri videoUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; | |
Cursor videoCursor = contentResolver.query(videoUri,null,null,null); | |
if(videoCursor == null || videoCursor.moveToNext()) | |
{ | |
int videotitle = videoCursor.getColumnIndex(MediaStore.Video.Media.MINI_THUMB_MAGIC); | |
int videoArtist = videoCursor.getColumnIndex(MediaStore.Video.Media.DATA); | |
int videoDuration = videoCursor.getColumnIndex(MediaStore.Video.Media.DURATION); | |
while(videoCursor.moveToNext()){ | |
currTitle = videoCursor.getString(videotitle); | |
currentArtist = videoCursor.getString(videoArtist); | |
currentDuration= videoCursor.getString(videoDuration); | |
musicList.add(new Music(currTitle,currentArtist, currentDuration)); | |
} | |
videoCursor.close(); | |
} | |
MusicAdapter adapter = new MusicAdapter(this,musicList); | |
//GridView gridview = (GridView)findViewById(R.id.gridview); | |
ListView listView = (ListView)findViewById(R.id.list); | |
//gridview.setAdapter(adapter); | |
listView.setAdapter(adapter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment