8000 [WIP] [Extractor] :wrench: New module by JonathanMercandalli · Pull Request #4 · Mercandj/light-android-audio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[WIP] [Extractor] 🔧 New module #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ build/
obj/

gradle.properties
*.hprof
*.hprof

distribute
Binary file added app/src/main/assets/over_the_horizon_mono.mp3
Binary file not shown.
Binary file added app/src/main/assets/over_the_horizon_mono_2.mp3
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ public interface FileManager {
@StringDef({
FORMAT_AAC,
FORMAT_MP3,
FORMAT_MP3_MONO,
FORMAT_OGG,
FORMAT_WAV})
@interface TrackFormat {
}

String FORMAT_AAC = "FORMAT_AAC";
String FORMAT_MP3 = "FORMAT_MP3";
String FORMAT_MP3_MONO = "FORMAT_MP3_MONO";
String FORMAT_OGG = "FORMAT_OGG";
String FORMAT_WAV = "FORMAT_WAV";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

private static final String ASSET_FILE_NAME_AAC = "over_the_horizon.aac";
private static final String ASSET_FILE_NAME_MP3 = "over_the_horizon.mp3";
private static final String ASSET_FILE_NAME_MP3_MONO = "over_the_horizon_mono_2.mp3";
private static final String ASSET_FILE_NAME_OGG = "over_the_horizon.ogg";
private static final String ASSET_FILE_NAME_WAV = "over_the_horizon.wav";

private static final String FILE_NAME_AAC = "over_the_horizon.aac";
private static final String FILE_NAME_MP3 = "over_the_horizon.mp3";
private static final String FILE_NAME_MP3_MONO = "over_the_horizon_mono_2.mp3";
private static final String FILE_NAME_OGG = "over_the_horizon.ogg";
private static final String FILE_NAME_WAV = "over_the_horizon.wav";

Expand All @@ -28,6 +30,7 @@
private boolean initialized;
private File fileAAC;
private File fileMP3;
private File fileMp3Mono;
private File fileOGG;
private File fileWAV;
@TrackFormat
Expand All @@ -49,6 +52,7 @@ public void initialize() {
// Should be async...
initialized = extractAsset(fileDir, FORMAT_AAC);
initialized &= extractAsset(fileDir, FORMAT_MP3);
initialized &= extractAsset(fileDir, FORMAT_MP3_MONO);
initialized &= extractAsset(fileDir, FORMAT_OGG);
initialized &= extractAsset(fileDir, FORMAT_WAV);
if (!initialized) {
Expand Down Expand Up @@ -79,6 +83,8 @@ public File getFile() {
switch (trackFormat) {
case FORMAT_AAC:
return fileAAC;
case FORMAT_MP3_MONO:
return fileMp3Mono;
case FORMAT_OGG:
return fileOGG;
case FORMAT_WAV:
Expand Down Expand Up @@ -112,6 +118,10 @@ private boolean extractAsset(String outDir, @TrackFormat String format) {
in = assetManager.open(ASSET_FILE_NAME_AAC);
file = fileAAC = new File(outDir, FILE_NAME_AAC);
break;
case FORMAT_MP3_MONO:
in = assetManager.open(ASSET_FILE_NAME_MP3_MONO);
file = fileMp3Mono = new File(outDir, FILE_NAME_MP3_MONO);
break;
case FORMAT_OGG:
in = assetManager.open(ASSET_FILE_NAME_OGG);
file = fileOGG = new File(outDir, FILE_NAME_OGG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.media.MediaCodecList;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.StringDef;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
Expand All @@ -27,8 +28,11 @@
import com.mercandalli.android.apps.audio.file.FileManager;
import com.mercandalli.android.sdk.audio.SoundSystem;

import java.io.File;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;

/**
* Simple activity launching the sound system.
Expand All @@ -38,6 +42,7 @@ public class MainActivity extends AppCompatActivity {
@Retention(RetentionPolicy.SOURCE)
@StringDef({
ACTION_NO_ACTION,
ACTION_LOAD_FILE_VIA_EXTRACTION_WRAPPER,
ACTION_LOAD_FILE_OPEN_SL,
ACTION_LOAD_FILE_MEDIA_CODEC,
ACTION_LOAD_FILE_FFMPEG_JAVA_THREAD,
Expand All @@ -46,6 +51,7 @@ public class MainActivity extends AppCompatActivity {
}

private static final String ACTION_NO_ACTION = "ACTION_NO_ACTION";
private static final String ACTION_LOAD_FILE_VIA_EXTRACTION_WRAPPER = "ACTION_LOAD_FILE_VIA_EXTRACTION_WRAPPER";
private static final String ACTION_LOAD_FILE_OPEN_SL = "ACTION_LOAD_FILE_OPEN_SL";
private static final String ACTION_LOAD_FILE_MEDIA_CODEC = "ACTION_LOAD_FILE_MEDIA_CODEC";
private static final String ACTION_LOAD_FILE_FFMPEG_JAVA_THREAD = "ACTION_LOAD_FILE_FFMPEG_JAVA_THREAD";
Expand All @@ -54,6 +60,7 @@ public class MainActivity extends AppCompatActivity {
private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;

private Button toggleStop;
private Button btnExtractFileViaExtractionWrapper;
private Button btnExtractFileMediaCodecNativeThread;
private Button btnExtractFfmpegJavaThread;
private Button btnExtractFfmpegNativeThread;
Expand Down Expand Up @@ -120,6 +127,9 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
String path = fileManager.getFile().getAbsolutePath();
switch (action) {
case ACTION_LOAD_FILE_VIA_EXTRACTION_WRAPPER:
loadTrackViaExtractionWrapperAskPermission();
break;
case ACTION_LOAD_FILE_OPEN_SL:
soundSystem.loadFileOpenSl(path);
break;
Expand All @@ -143,6 +153,7 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in

private void findViews() {
btnExtractFileOpenSlNativeThread = (Button) findViewById(R.id.btn_extract_file_opensl_native_thread);
btnExtractFileViaExtractionWrapper = (Button) findViewById(R.id.btn_extract_file_extraction_wrapper_thread);
btnExtractFileMediaCodecNativeThread = (Button) findViewById(R.id.btn_extract_file_mediacodec_native_thread);
btnExtractFfmpegJavaThread = (Button) findViewById(R.id.btn_extract_file_ffmpeg_java_thread);
btnExtractFfmpegNativeThread = (Button) findViewById(R.id.btn_extract_file_ffmpeg_native_thread);
Expand All @@ -154,6 +165,7 @@ private void findViews() {

private void initUI() {
btnExtractFileOpenSlNativeThread.setOnClickListener(onClickListener);
btnExtractFileViaExtractionWrapper.setOnClickListener(onClickListener);
btnExtractFileMediaCodecNativeThread.setOnClickListener(onClickListener);
btnExtractFfmpegJavaThread.setOnClickListener(onClickListener);
btnExtractFfmpegNativeThread.setOnClickListener(onClickListener);
Expand Down Expand Up @@ -196,10 +208,12 @@ private int trackFormatToSpinnerPosition() {
return 0;
case FileManager.FORMAT_MP3:
return 1;
case FileManager.FORMAT_OGG:
case FileManager.FORMAT_MP3_MONO:
return 2;
case FileManager.FORMAT_WAV:
case FileManager.FORMAT_OGG:
return 3;
case FileManager.FORMAT_WAV:
return 4;
}
return 0;
}
Expand All @@ -212,8 +226,10 @@ private String spinnerPositionToTrackFormat(int position) {
case 1:
return FileManager.FORMAT_MP3;
case 2:
return FileManager.FORMAT_OGG;
return FileManager.FORMAT_MP3_MONO;
case 3:
return FileManager.FORMAT_OGG;
case 4:
return FileManager.FORMAT_WAV;
}
return FileManager.FORMAT_AAC;
Expand Down Expand Up @@ -335,6 +351,10 @@ public void onStopTrack() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_extract_file_extraction_wrapper_thread:
loadTrackViaExtractionWrapperAskPermission();
break;

case R.id.btn_extract_file_opensl_native_thread:
loadTrackOpenSlOrAskPermission();
break;
Expand All @@ -358,9 +378,33 @@ public void onClick(View v) {
}
};

private void loadTrackViaExtractionWrapperAskPermission() {
action = ACTION_LOAD_FILE_VIA_EXTRACTION_WRAPPER;
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
String folderPath = Environment.getExternalStorageDirectory() + "/pianomp3";
File directory = new File(folderPath);
if (!directory.exists()) {
log("No folder pianomp3 folderPath==" + folderPath);
return;
}
File[] files = directory.listFiles();
List<String> filePaths = new ArrayList<>();
for (File file : files) {
String absolutePath = file.getAbsolutePath();
if (absolutePath.toLowerCase().endsWith(".mp3")) {
filePaths.add(absolutePath);
}
}
soundSystem.loadViaExtractionWrapper(filePaths.toArray(new String[filePaths.size()]));
} else {
askForReadExternalStoragePermission();
}
}

private void loadTrackOpenSlOrAskPermission() {
action = ACTION_LOAD_FILE_OPEN_SL;
final int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
String path = fileManager.getFile().getAbsolutePath();
soundSystem.loadFileOpenSl(path);
Expand All @@ -371,7 +415,7 @@ private void loadTrackOpenSlOrAskPermission() {

private void loadTrackMediaCodecOrAskPermission() {
action = ACTION_LOAD_FILE_MEDIA_CODEC;
final int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
String path = fileManager.getFile().getAbsolutePath();
soundSystem.loadFileMediaCodec(path);
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
android:textSize="11sp"
tools:ignore="SmallSp" />

<Button
android:id="@+id/btn_extract_file_extraction_wrapper_thread"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Extraction wrapper"
android:textAllCaps="false"
android:textSize="11sp"
tools:ignore="SmallSp" />

<Button
android:id="@+id/btn_extract_file_opensl_native_thread"
style="?android:attr/buttonStyleSmall"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<string-array name="activity_main_file_spinner_arrays">
<item>AAC over_the_horizon (internal str.)</item>
<item>MP3 over_the_horizon (internal str.)</item>
<item>MP3 Mono over_the_horizon (internal str.)</item>
<item>OGG over_the_horizon (internal str.)</item>
<item>WAV over_the_horizon (internal str.)</item>
</string-array>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ task clean(type: Delete) {
ext {
compileSdkVersion = 26
buildToolsVersion = "26.0.2"
minSdkVersion = 21
minSdkVersion = 16
targetSdkVersion = 26
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':soundsystemnative', ':soundsystem'
include ':app', ':soundsystemnative', ':soundsystem', ':soundextractornative'
1 change: 1 addition & 0 deletions soundextractornative/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading
0