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:Main.java

public static String getMusicFolder() {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath();
}

From source file:Main.java

public static Pair<Boolean, Uri> isTrackExist(Context context, String artist, String track) {
    File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_MUSIC),
            artist + " - " + track + ".mp3");
    return new Pair<>(file.exists(), Uri.fromFile(file));
}

From source file:Main.java

public static File getArtworkStorageDir() {
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
            ARTWORKS_DIR_NAME);// w  w w . j  a  v  a2s .c  om
    if (!file.mkdirs()) {
        Log.e(TAG, "Directory not created");
    }
    return file;
}

From source file:Main.java

static String getDefaultMediaDirectory(int type) {
    String dirType = new String();
    switch (type) {
    case 0://w  w w .  j  a v  a  2 s .c o  m
        dirType = Environment.DIRECTORY_MUSIC;
        break;
    case 1:
        dirType = Environment.DIRECTORY_MOVIES;
        break;
    case 2:
        dirType = Environment.DIRECTORY_DCIM;
        break;
    default:
        break;
    }

    File path = new File("");
    if (type == 3) {
        // There is no API for knowing the standard location for sounds
        // such as voice recording. Though, it's typically in the 'Sounds'
        // directory at the root of the external storage
        path = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Sounds");
    } else {
        path = Environment.getExternalStoragePublicDirectory(dirType);
    }

    path.mkdirs(); // make sure the directory exists

    return path.getAbsolutePath();
}

From source file:com.exercise.AndroidClient.RecvFrom.java

RecvFrom(DownloadManager downloadMgr, String json, String remoteHost) throws JSONException {
    this.downloadMgr = downloadMgr;
    this.remoteHost = remoteHost;
    this.json = json;
    parseJson(json);/*from  www  . ja v  a 2s.c o m*/
    // setup map for getExternalStoragePublicDirectory values 
    destDirTypes = new HashMap<String, String>();
    destDirTypes.put("music", Environment.DIRECTORY_MUSIC);
    destDirTypes.put("downloads", Environment.DIRECTORY_DOWNLOADS);
    destDirTypes.put("pictures", Environment.DIRECTORY_PICTURES);
    destDirTypes.put("movies", Environment.DIRECTORY_MOVIES);
    valid = true;
}

From source file:my.extensions.app.AudioFileLister.java

private String listFiles() {
    if (musicDirectoryReadable()) {
        File audioDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);

        Iterator<File> fileIterator = FileUtils.iterateFiles(audioDir, FILE_EXTS, true);

        List<FileInfo> files = new ArrayList<FileInfo>();

        File f;/*from  w w w  .  j a  v a  2s.  co m*/
        while (fileIterator.hasNext()) {
            f = fileIterator.next();
            files.add(new FileInfo(f));
        }

        String filesJson = gson.toJson(files);

        return "{\"success\": true, \"files\": " + filesJson + "}";
    } else {
        return "{\"success\": false, \"error\":\"audio directory not readable\"}";
    }
}

From source file:de.qspool.clementineremote.ui.settings.DefaultDirChooser.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private LinkedList<String> getDirectories() {
    LinkedList<String> directories = new LinkedList<>();

    File[] defaultDirs = ContextCompat.getExternalFilesDirs(mContext, Environment.DIRECTORY_MUSIC);
    for (File f : defaultDirs) {
        if (f != null)
            directories.add(f.toString());
    }/*  ww w .  j av  a 2s.  c om*/

    String publicMusicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
            .toString();
    if (canWriteToExternalStorage(publicMusicDir)) {
        directories.add(publicMusicDir);
    }

    if (canWriteToExternalStorage(Environment.getExternalStorageDirectory().getAbsolutePath())) {
        directories.add(mContext.getString(R.string.file_dialog_custom_paths_available));
    }
    return directories;
}

From source file:com.melchor629.musicote.Utils.java

public static String getUrl(String archivo) {
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
            archivo.substring(archivo.lastIndexOf("/") + 1));
    if (file.exists())
        return file.getAbsolutePath();
    return String.format("http://%s%s%s", MainActivity.HOST, MainActivity.BASE_URL, archivo);
}

From source file:com.melchor629.musicote.Utils.java

public static boolean isDownloaded(String archivo) {
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
            archivo.substring(archivo.lastIndexOf("/") + 1));
    return file.exists();
}

From source file:com.app.swaedes.swaedes.OtherSitePage.java

public File getOutputAudioFile(int type) {

    //Create folder if it doesn't exist
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
            Config.APP_DIRECTORY_NAME);//from  w  w w .  j a  va 2 s.co m

    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d(Config.APP_DIRECTORY_NAME,
                    "Oops! Failed to create" + Config.APP_DIRECTORY_NAME + "directory");
            return null;
        }
    }

    //Audio title will be a timestamp to be unique
    audio_name = "REC_" + Config.timeStamp() + ".3gp";
    File audioFile;
    if (type == MEDIA_TYPE_AUDIO) {
        audioFile = new File(mediaStorageDir + File.separator + audio_name);
    } else {
        return null;
    }
    return audioFile;
}