Vincenzo Seggio
Vincenzo Seggio

Reputation: 11

How can i get access to device memory with media player?

i plan to build a music app and i know how to play music files from raw folder, but i have no idea how to connect the music player directly with audio files from the device memory. Can you give me a hint?

Upvotes: 0

Views: 51

Answers (1)

Bhunnu Baba
Bhunnu Baba

Reputation: 1802

Firstly fetch audio files form the device memory for this use below code.

 public ArrayList<HashMap<String, String>> getPlayList(){
    File home = new File(MEDIA_PATH);

    if (home.listFiles(new FileExtensionFilter()).length > 0) {
        for (File file : home.listFiles(new FileExtensionFilter())) {
            HashMap<String, String> song = new HashMap<String, String>();
            song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
            song.put("songPath", file.getPath());

            // Adding each song to SongList
            songsList.add(song);
        }
    }
    // return songs list array
    return songsList;
    }

Then use this array list in your player adapter and then use this adapter in your video player.

Upvotes: 1

Related Questions