Example usage for android.os Environment DIRECTORY_MUSIC

List of usage examples for android.os Environment DIRECTORY_MUSIC

Introduction

In this page you can find the example usage for android.os Environment DIRECTORY_MUSIC.

Prototype

String DIRECTORY_MUSIC

To view the source code for android.os Environment DIRECTORY_MUSIC.

Click Source Link

Document

Standard directory in which to place any audio files that should be in the regular list of music for the user.

Usage

From source file:com.juce.JuceAppActivity.java

public static final String getMusicFolder()      { return getFileLocation (Environment.DIRECTORY_MUSIC); }

From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java

public static void Download(Context context, RadioSong song, RadioEpisode episode) {
    String downloadURL = "";
    String title = "";
    String description = "radio reddit";

    String songTitle = context.getString(R.string.app_name);
    String songArtist = "";
    String filename = "";

    if (song != null && song.Download_url != null) {
        if (song.Title != null)
            songTitle = song.Title;//from  w ww.  j  a  v  a  2  s  .c  o m
        if (song.Artist != null && song.Redditor != null)
            songArtist = song.Artist + " (" + song.Redditor + ")";

        downloadURL = song.Download_url;
    } else if (episode != null && episode.Download_url != null) {
        if (episode.EpisodeTitle != null)
            songTitle = episode.EpisodeTitle;
        if (episode.ShowTitle != null)
            songArtist = episode.ShowTitle;

        downloadURL = episode.Download_url;
    }

    title = songTitle + " by " + songArtist;

    filename = songArtist + " " + songTitle + ".mp3";
    filename = filename.replace(" ", "_");

    if (!downloadURL.equals("")) {
        DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        Uri uri = Uri.parse(downloadURL);

        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        path = new File(path, "radioreddit");
        path.mkdirs();

        DownloadManager.Request request = new DownloadManager.Request(uri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }

        request.setTitle(title).setDescription(description).setMimeType("audio/mpeg")
                .setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, "/radioreddit/" + filename);

        long lastDownload = -1L;
        lastDownload = downloadManager.enqueue(request);
    }
}

From source file:com.juce.jucedemo.JuceDemo.java

public static final String getMusicFolder() {
    return getFileLocation(Environment.DIRECTORY_MUSIC);
}