Skip to content

Commit

Permalink
Merge pull request #25 from brarcher/internal-storage
Browse files Browse the repository at this point in the history
Internal storage
  • Loading branch information
brarcher authored Aug 31, 2016
2 parents 6420da3 + 235eccc commit 4395d78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ public void onPeriodicNotification(AudioTrack track)
}
finally
{
if(audioTrack.getState() != AudioTrack.STATE_UNINITIALIZED)
{
audioTrack.stop();
}
audioTrack.release();

try
{
Expand Down
41 changes: 21 additions & 20 deletions app/src/main/java/protect/babysleepsounds/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -49,6 +48,9 @@ public class MainActivity extends AppCompatActivity
{
private final static String TAG = "BabySleepSounds";

private static final String ORIGINAL_MP3_FILE = "original.mp3";
private static final String PROCESSED_RAW_FILE = "processed.raw";

private Map<String, Integer> _soundMap;
private Map<String, Integer> _timeMap;

Expand Down Expand Up @@ -244,27 +246,12 @@ private void startPlayback()

try
{
File dir = getExternalFilesDir (Environment.DIRECTORY_MUSIC);
if(dir == null)
{
throw new IOException("No external files dir available, cannot prepare file");
}

if(dir.exists() == false)
{
boolean result = dir.mkdirs();
if(result == false)
{
throw new IOException("Unable to create folder in external file dir, cannot prepare file");
}
}

File originalFile = new File(dir, "original.mp3");
File originalFile = new File(getFilesDir(), ORIGINAL_MP3_FILE);

Log.i(TAG, "Writing file out prior to WAV conversion");
writeToFile(id, originalFile);

final File processed = new File(dir, "processed.raw");
final File processed = new File(getFilesDir(), PROCESSED_RAW_FILE);
if(processed.exists())
{
boolean result = processed.delete();
Expand Down Expand Up @@ -383,8 +370,12 @@ private void writeToFile(int resource, File output) throws IOException
*/
private void reportPlaybackFailure()
{
_encodingProgress.hide();
_encodingProgress = null;
if(_encodingProgress != null)
{
_encodingProgress.dismiss();
_encodingProgress = null;
}

Toast.makeText(this, R.string.playbackFailure, Toast.LENGTH_LONG).show();
}

Expand Down Expand Up @@ -468,6 +459,16 @@ protected void onDestroy()
_mediaPlayer.stop();
}

for(String toDelete : new String[]{ORIGINAL_MP3_FILE, PROCESSED_RAW_FILE})
{
File file = new File(getFilesDir(), toDelete);
boolean result = file.delete();
if(result == false)
{
Log.w(TAG, "Failed to delete file on exit: " + file.getAbsolutePath());
}
}

super.onDestroy();
}

Expand Down

0 comments on commit 4395d78

Please sign in to comment.