mirror of
https://github.com/olgamiller/SSTVEncoder2.git
synced 2025-12-06 06:52:01 +01:00
WaveFileOutputContext: Moved content of init-method into constuctor,
create mFile for Version>=Q only if deleteFile-method is called
This commit is contained in:
parent
7de496bb69
commit
e0ca7e9eff
|
|
@ -36,6 +36,11 @@ public class WaveFileOutputContext {
|
||||||
public WaveFileOutputContext(ContentResolver contentResolver, String fileName) {
|
public WaveFileOutputContext(ContentResolver contentResolver, String fileName) {
|
||||||
mContentResolver = contentResolver;
|
mContentResolver = contentResolver;
|
||||||
mFileName = fileName;
|
mFileName = fileName;
|
||||||
|
mValues = getContentValues(fileName);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||||
|
mUri = mContentResolver.insert(MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY), mValues);
|
||||||
|
else
|
||||||
|
mFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), mFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
|
|
@ -43,7 +48,6 @@ public class WaveFileOutputContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutputStream createWaveOutputStream() {
|
public OutputStream createWaveOutputStream() {
|
||||||
if (init()) {
|
|
||||||
try {
|
try {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||||
return mContentResolver.openOutputStream(mUri);
|
return mContentResolver.openOutputStream(mUri);
|
||||||
|
|
@ -51,25 +55,9 @@ public class WaveFileOutputContext {
|
||||||
return new FileOutputStream(mFile);
|
return new FileOutputStream(mFile);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean init() {
|
|
||||||
mValues = getContentValues(mFileName);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
mUri = mContentResolver.insert(MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY), mValues);
|
|
||||||
if (mUri != null) {
|
|
||||||
String path = mUri.getPath();
|
|
||||||
if (path != null)
|
|
||||||
mFile = new File(path);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), mFileName);
|
|
||||||
}
|
|
||||||
return mUri != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ContentValues getContentValues(String fileName) {
|
private ContentValues getContentValues(String fileName) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/wav");
|
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/wav");
|
||||||
|
|
@ -102,7 +90,8 @@ public class WaveFileOutputContext {
|
||||||
|
|
||||||
public void deleteFile() {
|
public void deleteFile() {
|
||||||
try {
|
try {
|
||||||
if (mFile != null)
|
if (mFile == null)
|
||||||
|
mFile = new File(mUri.getPath());
|
||||||
mFile.delete();
|
mFile.delete();
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue