List of usage examples for android.os Environment DIRECTORY_MUSIC
String DIRECTORY_MUSIC
To view the source code for android.os Environment DIRECTORY_MUSIC.
Click Source Link
From source file:zlyh.dmitry.recaller.services.RecordService.java
private File getDir() { File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), getString(R.string.recaller)); if (!storageDir.mkdirs()) { if (!storageDir.exists()) { storageDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), getString(R.string.recaller)); if (!storageDir.mkdirs()) { if (!storageDir.exists()) { //some low-end devices has no access no external storage storageDir = new File(RecallerApp.getAppContext().getExternalFilesDir(null), getString(R.string.recaller)); if (!storageDir.mkdirs()) { if (!storageDir.exists()) { storageDir = new File(RecallerApp.getAppContext().getFilesDir(), getString(R.string.recaller)); if (!storageDir.mkdirs()) { if (!storageDir.exists()) { return null; }// ww w . j a v a 2 s . c o m } } } } } } } return storageDir; }
From source file:de.qspool.clementineremote.backend.downloader.DownloadManager.java
public boolean addJob(ClementineMessage clementineMessage) { ClementineSongDownloader songDownloader = new ClementineSongDownloader(); songDownloader.setId(mIds);/* w w w. java 2 s.c o m*/ songDownloader.setSongDownloaderListener(new SongDownloaderListener() { @Override public void onProgress(DownloadStatus progress) { DownloadManager.this.onProgress(progress); } @SuppressLint("InlinedApi") @Override public void onDownloadResult(DownloaderResult result) { int id = result.getId(); // Move the download to the finished list mFinishedDownloads.append(id, mActiveDownloads.get(id)); mActiveDownloads.remove(id); // Remove the notification if this was the last download if (mActiveDownloads.size() == 0) { mNotifyManager.cancel(NOTIFICATION_ID_DOWNLOADS); } else { // Build a new active notification as the old one might be // expanded and looks now strange createNewActiveNotification(); } //download_noti_n_finished String title = mContext.getResources().getQuantityString(R.plurals.download_noti_n_finished, mFinishedDownloads.size(), mFinishedDownloads.size()); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext) .setContentTitle(title).setContentText(mContext.getString(result.getMessageStringId())) .setSmallIcon(R.drawable.ic_launcher).setPriority(NotificationCompat.PRIORITY_MIN) .setAutoCancel(true).setContentIntent(buildNotificationIntent()) .setVisibility(Notification.VISIBILITY_PUBLIC); // Displays the progress bar for the first time. mNotifyManager.notify(NOTIFICATION_ID_DOWNLOADS_FINISHED, notificationBuilder.build()); } }); mSharedPref = PreferenceManager.getDefaultSharedPreferences(mContext); // Get preferences and set download settings String defaultPath; if (mContext.getExternalFilesDir(Environment.DIRECTORY_MUSIC) == null && !mSharedPref.contains(SharedPreferencesKeys.SP_DOWNLOAD_DIR)) { Toast.makeText(mContext, R.string.download_noti_not_mounted, Toast.LENGTH_LONG).show(); return false; } else { File defaultFile = mContext.getExternalFilesDir(Environment.DIRECTORY_MUSIC); if (defaultFile != null) defaultPath = defaultFile.getAbsolutePath(); else defaultPath = ""; } songDownloader.setDownloadPath(mSharedPref.getString(SharedPreferencesKeys.SP_DOWNLOAD_DIR, defaultPath)); songDownloader.setDownloadOnWifiOnly(mSharedPref.getBoolean(SharedPreferencesKeys.SP_WIFI_ONLY, false)); songDownloader.setCreatePlaylistDir( mSharedPref.getBoolean(SharedPreferencesKeys.SP_DOWNLOAD_SAVE_OWN_DIR, false)); songDownloader.setCreateArtistDir( mSharedPref.getBoolean(SharedPreferencesKeys.SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR, true)); songDownloader.setCreateAlbumDir( mSharedPref.getBoolean(SharedPreferencesKeys.SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR, true)); songDownloader.setOverrideExistingFiles( mSharedPref.getBoolean(SharedPreferencesKeys.SP_DOWNLOAD_OVERRIDE, false)); // Show a toast that the download is starting Toast.makeText(mContext, R.string.player_download_started, Toast.LENGTH_SHORT).show(); mActiveDownloads.append(mIds, songDownloader); mIds++; songDownloader.startDownload(clementineMessage); return true; }
From source file:com.app.swaedes.swaedes.ConstructionSitePage.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 v a2s . c om*/ if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d(Config.APP_DIRECTORY_NAME, "Oops! Failed 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; }
From source file:com.intervigil.micdroid.MainActivity.java
@Override public void onExport(Recording r) { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Log.w(TAG, "onExport: External media is not available"); Toast.makeText(mContext, R.string.recording_options_export_external_media_unavailable, Toast.LENGTH_SHORT).show(); return;// w ww . j a v a 2 s .c o m } File externalMusicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); if (!externalMusicDir.exists() && !externalMusicDir.mkdirs()) { Log.e(TAG, "onExport: Failed to create external music directory"); Toast.makeText(mContext, R.string.recording_options_export_external_music_dir_unavailable, Toast.LENGTH_SHORT).show(); return; } File exported = new File(externalMusicDir, r.getName()); FileChannel srcChannel = null; FileChannel dstChannel = null; try { srcChannel = mContext.openFileInput(r.getName()).getChannel(); dstChannel = new FileOutputStream(exported).getChannel(); srcChannel.transferTo(0, srcChannel.size(), dstChannel); Toast.makeText(mContext, R.string.recording_options_export_complete, Toast.LENGTH_SHORT).show(); } catch (IOException e) { Log.e(TAG, "onExport: Failed to export file: " + r.getName()); e.printStackTrace(); Toast.makeText(mContext, R.string.recording_options_export_copy_error, Toast.LENGTH_SHORT).show(); } finally { try { if (srcChannel != null) { srcChannel.close(); } if (dstChannel != null) { dstChannel.close(); } } catch (IOException e) { // Do nothing } } }
From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java
private String getDirectoryName(String name) { switch (name) { case "ALARMS": return Environment.DIRECTORY_ALARMS; case "DCIM": return Environment.DIRECTORY_DCIM; case "DOCUMENTS": return Environment.DIRECTORY_DOCUMENTS; case "DOWNLOADS": return Environment.DIRECTORY_DOWNLOADS; case "MOVIES": return Environment.DIRECTORY_MOVIES; case "MUSIC": return Environment.DIRECTORY_MUSIC; case "NOTIFICATIONS": return Environment.DIRECTORY_NOTIFICATIONS; case "PICTURES": return Environment.DIRECTORY_PICTURES; case "PODCASTS": return Environment.DIRECTORY_PODCASTS; case "RINGTONES": return Environment.DIRECTORY_RINGTONES; default://from w ww .j av a 2 s. co m throw new IllegalArgumentException("Invalid directory representation: " + name); } }
From source file:link.kjr.file_manager.MainActivity.java
public void clickMusic(View view) { String path = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)) .getAbsolutePath();/* www.ja v a 2 s . c o m*/ setDirectoryView(path); }
From source file:com.eggwall.SoundSleep.AudioService.java
/** * [sdcard]/music in SDK >= 8/*from w ww .ja v a 2 s . c om*/ * @return the [sdcard]/music path in sdk version >= 8 */ private static File getMusicDirAfterV8() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); }
From source file:com.retroteam.studio.retrostudio.EditorLandscape.java
/** * Write the 8bit PCM audio to the wav file format to the public music dir. * http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html * @param proj/*from w ww.j a v a 2s. c o m*/ * @param filename */ private void exportAsWav(Project proj, String filename) { try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), filename + ".wav"); DataOutputStream os = new DataOutputStream(new FileOutputStream(file)); // get project length int pLength = proj.export().getBytes().length; os.writeBytes("RIFF"); // Chunk ID 'RIFF' os.write(intToByteArray(36 + pLength), 0, 4); //file size os.writeBytes("WAVE"); // Wave ID os.writeBytes("fmt "); // Chunk ID 'fmt ' os.write(intToByteArray(16), 0, 4); // chunk size os.write(intToByteArray(1), 0, 2); // pcm audio os.write(intToByteArray(1), 0, 2); // mono os.write(intToByteArray(8000), 0, 4); // samples/sec os.write(intToByteArray(pLength), 0, 4); // bytes/sec os.write(intToByteArray(1), 0, 2); // 1 byte/sample os.write(intToByteArray(8), 0, 2); // 8 bits/sample os.writeBytes("data"); // Chunk ID 'data' os.write(intToByteArray(pLength), 0, 4); // size of data chunk os.write(proj.export().getBytes()); // write the data os.close(); Toast.makeText(this, "Saved file to: " + file.getPath(), Toast.LENGTH_SHORT).show(); } catch (IOException e) { Toast.makeText(this, "IOException while saving project.", Toast.LENGTH_SHORT).show(); } }
From source file:com.rks.musicx.misc.utils.Helper.java
/** * Return Storage Path//from ww w. j a va2 s . c om * * @return */ public static String getStoragePath() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String musicfolderpath = Environment.getExternalStorageDirectory().getAbsolutePath(); Log.d("Helper", musicfolderpath); return musicfolderpath; } else { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath(); } }
From source file:uk.org.ngo.squeezer.service.SqueezeService.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) private void downloadSong(@NonNull Uri url, String title, @NonNull Uri serverUrl) { if (url.equals(Uri.EMPTY)) { return;//from w ww .j a v a 2s . co m } // If running on Gingerbread or greater use the Download Manager if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); DownloadDatabase downloadDatabase = new DownloadDatabase(this); String localPath = getLocalFile(serverUrl); String tempFile = UUID.randomUUID().toString(); String credentials = mUsername + ":" + mPassword; String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); DownloadManager.Request request = new DownloadManager.Request(url).setTitle(title) .setDestinationInExternalFilesDir(this, Environment.DIRECTORY_MUSIC, tempFile) .setVisibleInDownloadsUi(false) .addRequestHeader("Authorization", "Basic " + base64EncodedCredentials); long downloadId = downloadManager.enqueue(request); Crashlytics.log("Registering new download"); Crashlytics.log("downloadId: " + downloadId); Crashlytics.log("tempFile: " + tempFile); Crashlytics.log("localPath: " + localPath); if (!downloadDatabase.registerDownload(downloadId, tempFile, localPath)) { Crashlytics.log(Log.WARN, TAG, "Could not register download entry for: " + downloadId); downloadManager.remove(downloadId); } } }