Commit 8af68448 authored by qiujianhui's avatar qiujianhui

create gsai audio demo

parent 46974502
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
# Default ignored files
/shelf/
/workspace.xml
roiencodedemo
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Android Studio default JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ASMIdeaPluginConfiguration">
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
<groovy codeStyle="LEGACY" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
/build
\ No newline at end of file
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.mediademo"
minSdk 31
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'gsai.sdk:audio-client:1.0.0-SNAPSHOT'
compileOnly 'gsai.sdk:audiostub:1.0.0-SNAPSHOT'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'com.google.code.gson:gson:2.9.0'
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mediademo">
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.oplus.ocs.permission.third"/>
<queries>
<package android:name="com.coloros.karaoke"></package>
<package android:name="com.coloros.ocs.opencapabilityservice"></package>
<package android:name="com.oplus.ocs"></package>
</queries>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Itgsa">
<meta-data
android:name="com.oplus.ocs.media.AUTH_CODE"
android:value="ATBGAiEAvSb8HVBi9iPd85D9ytWzXOFbEylfv62G32VQcmWXCQ0CIQCNEzypKeRlIM2aKlT4MJC9YoYpHIg60pBWaykj8b/ZXWxT3ZyAAAAA">
</meta-data>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".KTVActivity"
android:label="@string/title_KTV"
android:screenOrientation="portrait">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.KTVActivity" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- </intent-filter>-->
</activity>
</application>
</manifest>
\ No newline at end of file
package com.example.mediademo;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.example.mediademo.util.AudioParamBean;
import com.example.mediademo.util.AudioPlayer;
import com.google.gson.Gson;
import com.itgsa.opensdk.common.OnConnectionSucceedListener;
import com.itgsa.opensdk.media.MediaClient;
import com.itgsa.opensdk.media.extensions.KtvSupportInfo;
import com.itgsa.opensdk.media.extensions.MediaClientUtil;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
//import android.support.v4.app.ActivityCompat;
//import android.support.v4.content.ContextCompat;
public class KTVActivity extends Activity implements
OnClickListener,
OnItemSelectedListener,
OnSeekBarChangeListener {
private static final String TAG = "KTVTest";
private static final String SING_TAG = "KTVSING";
// private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 101;
// private static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 102;
private boolean isListGot = false;
private static final int MSG_REPORT_RECORD_COST = 100;
private static final int MSG_REPORT_READ_COST = 101;
private static final int MSG_REPORT_TOTAL_COST = 102;
private static final int MSG_REPORT_SING_START = 103;
private static final int MSG_REPORT_SING_FINISH = 104;
private static final int MSG_KTV_MODE_ENABLE = 200;
private static final int MSG_RECORD_START = 201;
private static final int MSG_PLAYBACK_START = 202;
private static final int MSG_SLIENT_START = 203;
private ToggleButton mKTVMode;
private Button mBtnRecord;
private Button mBtnRecPlay;
private Button mBtnSelint;
private Button mBtnSing;
private Spinner mSpinnerMusicSelector;
private Button mBtnStop;
private TextView mReport;
private Button mBtnDoSing;
private Button mBtnSingPlay;
private Context mContext;
private Spinner mSpinnerPresetModeReverb;
private Spinner mSpinnerPresetModeEq;
private Spinner mSpinnerPresetModeTone;
private ToggleButton mPlaySource;
private TextView mTextVolMic;
private SeekBar mVolMic;
private RadioGroup mOutSelect;
private RadioButton mHeadOut, mExtSpkr;
private RadioGroup mRecSource;
private RadioButton mRBMic, mRBMixed, mRBProcessMic;
// default reverb type ( 0:无、1:KTV、2:剧场、3:音乐厅、4:录音棚 )
private static final int DEFAULT_COUNT_REVERB = 4;
// For VIVO extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: 老唱片
private final String ReverbPresetMode[] = {"无", "KTV", "剧场", "音乐厅", "录音棚",
"温暖", "空灵", "3D迷幻", "老唱片"};
private final Map<String, Integer> mPresetModeMapReverb = new HashMap<>();
private static final int DEFAULT_MAX_COUNT_REVERB_EQ = 5; // include no effect
// default EQ type ( 0:无、1:标准、2:浑厚、3:清脆、4:明亮 )
private static final int DEFAULT_COUNT_EQ = 4;
// For VIVO extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: KTV
private final String EqPresetMode[] = {"无", "标准", "浑厚", "清脆", "明亮",
"温暖", "空灵", "3D迷幻", "KTV"};
private final Map<String, Integer> mPresetModeMapEq = new HashMap<>();
// for OPPO setToneMode to set magic voice [-12, 12]
private static final int DEFAULT_COUNT_TONE = 0;
private final String TonePresetMode[] = {"男(-12)", "男(-11)", "男(-10)", "男(-9)", "男(-8)",
"男(-7)", "男(-6)", "男(-5)", "男(-4)", "男(-3)", "男(-2)", "男(-1)", "原声(0)",
"女(1)", "女(2)", "女(3)", "女(4)", "女(5)", "女(6)", "女(7)", "女(8)", "女(9)", "女(10)",
"女(11)", "女(12)"};
private final Map<String, Integer> mPresetModeMapTone = new HashMap<>();
private AudioManager mAM;
private AudioPlayer mAudioPlayer = null;
private AudioRecord mRecord = null;
private final Object mRecordLock = new Object();
private boolean isRecording = false;
private static final String WORKPATH = "/storage/emulated/0/Android/data/com.example.mediademo/KTV/";
private ArrayAdapter<String> mMusicListAdapter;
private ArrayAdapter<String> mMusicPathAdapter;
private static final int MSG_UPDATE_MIC_VOCAL = 100;
private static final boolean DefaultKTVMode = false;
private static final boolean DefaultPlaySource = false;
private static final int DelaySlientStart = 0;
private static final int DelayKTVEnable = 100;
private static final int DelayRecordStart = 200;
private static final int DelayPlayStart = 400;
private static final int LatencyPlay = 560;
private static final int RecBufSize = 2205;
private static final int SampleRateInHz = 44100;
// private static final String AudioPCM = "/sdcard/KTV/ktvrec.pcm";
// private static final String RecordWAV = "/sdcard/KTV/ktvrec.wav";
// private static final String SINGWAV = "/sdcard/KTV/ktvsing.wav";
private static final String AudioPCM = WORKPATH + "ktvrec.pcm";
private static final String RecordWAV = WORKPATH + "ktvrec.wav";
private static final String SINGWAV = WORKPATH + "ktvsing.wav";
private final int STATE_IDLE = 0;
private final int STATE_RECORDING = 1;
private final int STATE_PLAYING = 2;
private int mState = STATE_IDLE;
private int mCurPresetReverb = 1;
private int mCurPresetEq = 1;
private int mCurPresetTone = 0;
private long mRecStartTime;
private int mSingDelay;
private int mRecDelay;
private MediaClient mMediaClient;
@Nullable
private KtvSupportInfo mKtvSupportInfo;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ktv);
mMediaClient = MediaClient.initialize(getApplicationContext());
if (mMediaClient.isSupported()) {
Log.d(TAG, "KTV is supported for the new architecture of KTV APIs, you can use them");
Toast.makeText(this, "Anything you can do with KTV new API", Toast.LENGTH_SHORT).show();
if (MediaClientUtil.isOsOppo()) {
mMediaClient.addOnConnectionSucceedListener(new OnConnectionSucceedListener() {
@Override
public void onConnectionSucceed() {
Log.i(TAG, "connectionSucceed");
onKtvNewApiSupported();
}
});
} else {
onKtvNewApiSupported();
}
} else {
Log.w(TAG, "KTV is not supported for the new architecture of KTV APIs, " +
"you CAN NOT use them");
// do something
// Other alternatives or prompts for your APP
Log.w(TAG, "new APIs of KTV is not supported for your APP!");
Toast.makeText(this, "KTV is not supported for the new architecture of KTV APIs, " +
"you CAN NOT use them", Toast.LENGTH_LONG).show();
}
}
private void onKtvNewApiSupported() {
String ktvSupportInfoJson = mMediaClient.getKaraokeSupportParameters();
Log.d(TAG, "KTV ktvSupportInfoJson: " + ktvSupportInfoJson);
KtvSupportInfo supportInfo = new Gson().fromJson(ktvSupportInfoJson, KtvSupportInfo.class);
mKtvSupportInfo = supportInfo;
Log.d(TAG, "KTV isSupportListenRecordSame: " + supportInfo.isSupportListenRecordSame);
Log.d(TAG, "KTV isSupportExtSpeakerParam: " + supportInfo.isSupportExtSpeakerParam);
Log.d(TAG, "KTV isSupportToneMode: " + supportInfo.isSupportToneMode);
KtvSupportInfo.TrackSupportInfo targetTrackInfo =
new KtvSupportInfo.TrackSupportInfo("3", "48000", "2", "8");
Log.d(TAG, "KTV targetTrackInfo: " + targetTrackInfo.toString());
// Whether the parameters of target client AudioRecord or AudioTrack
// using KTV new API compatibility supports
if (!MediaClientUtil.isTargetAudioSupported(supportInfo, targetTrackInfo)) {
Toast.makeText(this, "NOT Supported! Something you can do quietly without " +
"AudioTrack of KTV", Toast.LENGTH_SHORT).show();
return;
}
// track equals
KtvSupportInfo.RecordSupportInfo targetRecordInfo =
new KtvSupportInfo.RecordSupportInfo("3", "48000", "2", "8", "1");
Log.d(TAG, "KTV targetRecordInfo: " + targetRecordInfo.toString());
if (!MediaClientUtil.isTargetAudioSupported(supportInfo, targetRecordInfo)) {
Toast.makeText(this, "NOT Supported! Something you can do quietly without " +
"AudioRecord of KTV", Toast.LENGTH_SHORT).show();
return;
}
// record equals
mContext = this;
mAM = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mAudioPlayer = new AudioPlayer(null);
mBtnRecord = (Button) findViewById(R.id.btn_record);
mBtnRecord.setText(R.string.text_record);
mBtnRecord.setOnClickListener(this);
mBtnRecPlay = (Button) findViewById(R.id.btn_record_play);
mBtnRecPlay.setOnClickListener(this);
mBtnSelint = (Button) findViewById(R.id.btn_silent);
mBtnSelint.setOnClickListener(this);
mBtnSing = (Button) findViewById(R.id.btn_selected);
mBtnSing.setText(R.string.text_sing);
mBtnSing.setOnClickListener(this);
mBtnStop = (Button) findViewById(R.id.btn_stop);
mBtnStop.setOnClickListener(this);
mBtnDoSing = (Button) findViewById(R.id.btn_sing);
mBtnDoSing.setOnClickListener(this);
mBtnSingPlay = (Button) findViewById(R.id.btn_sing_play);
mBtnSingPlay.setOnClickListener(this);
mSpinnerMusicSelector = (Spinner) findViewById(R.id.spinner_music);
mMusicListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
mMusicListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mMusicPathAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
// Log.d(TAG, "find wav files START");
// prepareList(Environment.getExternalStorageDirectory(), 0);
// Log.d(TAG, "find wav files END");
mSpinnerMusicSelector.setAdapter(mMusicListAdapter);
mSpinnerMusicSelector.setOnItemSelectedListener(this);
// Sets the type of sound effects for reverberation and gets additional types of reverb sound effects
// init for reverb
initReverb();
// Sets the type of sound effects for EQ and gets additional types of EQ sound effects
// init for EQ
initEq();
//init for OPPO magic voice
initToneMode();
mPlaySource = (ToggleButton) findViewById(R.id.tb_play_source);
mPlaySource.setOnClickListener(this);
mPlaySource.setChecked(DefaultPlaySource);
mVolMic = (SeekBar) findViewById(R.id.skb_vol_mic);
mVolMic.setMax(15);
mVolMic.setProgress(mMediaClient.getMicVolParam());
mVolMic.setOnSeekBarChangeListener(this);
mTextVolMic = (TextView) findViewById(R.id.text_vol_mic);
mTextVolMic.setText(Integer.toString(mMediaClient.getMicVolParam()));
mOutSelect = (RadioGroup) findViewById(R.id.rg_ext_spkr);
mHeadOut = (RadioButton) findViewById(R.id.rb_head_out);
mExtSpkr = (RadioButton) findViewById(R.id.rb_ext_spkr);
mOutSelect.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (checkedId == mHeadOut.getId()) {
setExtSpeakerParam(0);
} else if (checkedId == mExtSpkr.getId()) {
setExtSpeakerParam(1);
}
}
});
mRecSource = (RadioGroup) findViewById(R.id.rg_rec_source);
mRBMic = (RadioButton) findViewById(R.id.rb_mic_direct);
mRBMixed = (RadioButton) findViewById(R.id.rb_mixed_out);
mRBProcessMic = (RadioButton) findViewById(R.id.rb_process_mic);
mRecSource.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
Log.d(TAG, "setListenRecordSame onCheckedChanged, called.");
if (checkedId == mRBMic.getId()) {
// TODO NOTE: for oppo and vivo
setListenRecordSame(0);
} else if (checkedId == mRBMixed.getId()) {
// TODO NOTE: only for oppo
if (!MediaClientUtil.isOsOppo()) {
Toast.makeText(KTVActivity.this, "Only support for oppo!", Toast.LENGTH_SHORT).show();
return;
}
setListenRecordSame(1);
} else if (checkedId == mRBProcessMic.getId()) {
// TODO NOTE: only for vivo
if (!MediaClientUtil.isOsVivo()) {
Toast.makeText(KTVActivity.this, "Only support for vivo!", Toast.LENGTH_SHORT).show();
return;
}
setListenRecordSame(2);
}
}
});
// TODO NOTE: only working for oppo, not for vivo and xiaomi
setToneMode(0);
mReport = (TextView) findViewById(R.id.report);
mReport.setText(mReport.getText(), TextView.BufferType.EDITABLE);
requestPermissionIfNeed();
mKTVMode = (ToggleButton) findViewById(R.id.tb_ktv_mode);
mKTVMode.setOnClickListener(this);
closeKTVDevice(true);
// device status closed by default
mKTVMode.setChecked(DefaultKTVMode);
}
@Override
protected void onResume() {
//mKTVMode.setChecked(isKTVMode());
super.onResume();
// requestPermissionIfNeed();
if (mPlaySource != null) {
mPlaySource.setChecked(mMediaClient.getPlayFeedbackParam() == 1);
}
}
@Override
protected void onStop() {
super.onStop();
Log.e(TAG, "onStop");
}
@Override
protected void onPause() {
super.onPause();
Log.e(TAG, "onPause");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e(TAG, "onDestroy");
stopMusic();
stopRecord();
if (mAudioPlayer != null) {
mAudioPlayer.stop();
mAudioPlayer.release();
}
mAudioPlayer = null;
// mSlientPlayer = null;
// TODO NOTE: Maybe we should and MUST DO this if we do not use KTV functions!
closeKTVDevice(true);
}
// private boolean mCachedCurPlayFeedbackParam = false;
// private boolean mCachedLastPlayFeedbackParam = false;
// private int mCachedCurListenRecordSame = 0;
// private int mCachedLastListenRecordSame = 0;
// private int mCachedCurExtSpeakerParam = 0;
// private int mCachedLastExtSpeakerParam = 0;
/**
* Close KTV
*/
public void closeKTVDevice() {
closeKTVDevice(false);
}
public void closeKTVDevice(boolean release) {
if (mMediaClient.isSupported()) {
Log.d(TAG, "KTV is supported for the new architecture of KTV APIs, you can use them");
if (release) {
// TODO NOTE: Maybe we should and MUST DO these after we do not use KTV functions!
setPlayFeedbackParam(false);
setListenRecordSame(0);
setExtSpeakerParam(0);
// TODO: 2022/8/2 FIXME????
// setToneMode(0);
}
mMediaClient.closeKTVDevice();
} else {
Log.w(TAG, "KTV is not supported for the new architecture of KTV APIs, " +
"you CAN NOT use them");
// do something
// Other alternatives or prompts for your APP
Log.w(TAG, "new APIs of KTV is not supported for your APP!");
}
}
public void setExtSpeakerParam(int param) {
if (!mMediaClient.isSupported()) {
Log.w(TAG, "KTV is not supported for the new architecture of KTV APIs, " +
"you CAN NOT use them");
// do something
// Other alternatives or prompts for your APP
Log.w(TAG, "new APIs of KTV is not supported for your APP!");
return;
}
Log.d(TAG, "KTV is supported for the new architecture of KTV APIs, you can use them");
// TODO NOTE: only working for vivo, not for xiaomi and oppo
// TODO NOTE: Must use the field supported to check API!!! NOT directly use [MediaClientUtil.isOsVivo()]
if (mKtvSupportInfo != null && mKtvSupportInfo.isSupportExtSpeakerParam) {
// mCachedLastExtSpeakerParam = mCachedCurExtSpeakerParam;
// Or use this API
// mCachedLastExtSpeakerParam = mMediaClient.getExtSpeakerParam();
mMediaClient.setExtSpeakerParam(param);
// mCachedCurExtSpeakerParam = param;
if (mHeadOut == null) {
return;
}
if (param == 0 && !mHeadOut.isChecked()) {
mHeadOut.setChecked(true);
mExtSpkr.setChecked(false);
} else if (param == 1 && !mExtSpkr.isChecked()) {
mHeadOut.setChecked(false);
mExtSpkr.setChecked(true);
}
} else {
Log.d(TAG, "setExtSpeakerParam of KTV is NOT supported for this phone, " +
"only working for vivo and oppo, not for xiaomi");
Toast.makeText(this, "setExtSpeakerParam of KTV is NOT supported for this phone, " +
"only working for vivo and oppo, not for xiaomi", Toast.LENGTH_SHORT).show();
}
}
public void setListenRecordSame(int param) {
if (!mMediaClient.isSupported()) {
Log.w(TAG, "KTV is not supported for the new architecture of KTV APIs, " +
"you CAN NOT use them");
// do something
// Other alternatives or prompts for your APP
Log.w(TAG, "new APIs of KTV is not supported for your APP!");
return;
}
Log.d(TAG, "KTV is supported for the new architecture of KTV APIs, you can use them");
// TODO NOTE: only working for vivo and oppo, not for xiaomi
// TODO NOTE: Must use the field supported to check API!!! NOT directly use [MediaClientUtil.isOsXiaoMi()]
if (mKtvSupportInfo != null && mKtvSupportInfo.isSupportListenRecordSame) {
// Log.d(TAG, "setListenRecordSame START, mCachedLastListenRecordSame: "
// + mCachedLastListenRecordSame + ", mCachedCurListenRecordSame: " +
// mCachedCurListenRecordSame + ", param: " + param);
// mCachedLastListenRecordSame = mCachedCurListenRecordSame;
// Or use this API
// mCachedLastListenRecordSame = mMediaClient.getListenRecordSame();
mMediaClient.setListenRecordSame(param);
// mCachedCurListenRecordSame = param;
// Log.d(TAG, "setListenRecordSame END, mCachedLastListenRecordSame: "
// + mCachedLastListenRecordSame + ", mCachedCurListenRecordSame: " +
// mCachedCurListenRecordSame + ", param: " + param);
if (mRBMic == null) {
return;
}
if (param == 0 && !mRBMic.isChecked()) {
mRBMic.setChecked(true);
mRBMixed.setChecked(false);
mRBProcessMic.setChecked(false);
} else if (MediaClientUtil.isOsOppo() && param == 1 && !mRBMixed.isChecked()) {
mRBMic.setChecked(false);
mRBMixed.setChecked(true);
mRBProcessMic.setChecked(false);
} else if (MediaClientUtil.isOsVivo() && param == 2 && !mRBProcessMic.isChecked()) {
mRBMic.setChecked(false);
mRBMixed.setChecked(false);
mRBProcessMic.setChecked(true);
}
} else {
Log.d(TAG, "setListenRecordSame of KTV is NOT supported for this phone, " +
"only working for vivo and oppo, not for xiaomi");
Toast.makeText(this, "setListenRecordSame of KTV is NOT supported for this phone, " +
"only working for vivo and oppo, not for xiaomi", Toast.LENGTH_SHORT).show();
}
}
public void setToneMode(int toneValue) {
if (!mMediaClient.isSupported()) {
Log.w(TAG, "KTV is not supported for the new architecture of KTV APIs, " +
"you CAN NOT use them");
// do something
// Other alternatives or prompts for your APP
Log.w(TAG, "new APIs of KTV is not supported for your APP!");
return;
}
Log.d(TAG, "KTV is supported for the new architecture of KTV APIs, you can use them");
// TODO NOTE: only working for oppo, not for vivo and xiaomi
// TODO NOTE: Must use the field supported to check API!!! NOT directly use [MediaClientUtil.isOsOppo()]
if (mKtvSupportInfo != null && mKtvSupportInfo.isSupportToneMode) {
mMediaClient.setToneMode(toneValue);
} else {
Log.d(TAG, "setToneMode of KTV is NOT supported for this phone, " +
"only working for vivo and oppo, not for xiaomi");
Toast.makeText(this, "setToneMode of KTV is NOT supported for this phone, " +
"only working for vivo and oppo, not for xiaomi", Toast.LENGTH_SHORT).show();
}
}
private void presetExt(@NonNull Map<String, Integer> map, @NonNull String[] soundList,
@NonNull Supplier<int[]> provider) {
int[] extSoundTypes = provider.get();
if (extSoundTypes != null) {
for (int extSoundType : extSoundTypes) {
Log.d(TAG, "presetExt KTV extSoundTypes: " + extSoundType);
String typeName = convertSoundEffectName(extSoundType, soundList);
if (typeName == null) {
continue;
}
map.put(typeName, extSoundType);
// You can use it
// mMediaClient.setMixerSoundType(extSoundType);
// or
// mMediaClient.setEqualizerType(extSoundType);
}
}
}
private void presetDefaultSoundEffect(@NonNull Map<String, Integer> map,
@NonNull SoundEffectConvert<Integer, String> sec) {
for (int i = 0; i < DEFAULT_MAX_COUNT_REVERB_EQ; i++) {
// String typeName = convertMixerSoundName(i);
String typeName = sec.convert(i);
if (typeName == null) {
continue;
}
map.put(typeName, i);
}
}
private void initSpinnerSoundEffectView(@NonNull Spinner spinner, @NonNull Map<String, Integer> soundList,
int curPresetSoundEffect) {
ArrayAdapter<String> reverbPresets = new ArrayAdapter<String>(this,
R.layout.spinner_item);
reverbPresets.setDropDownViewResource(R.layout.dropdown_style);
soundList.forEach((k, v) -> {
reverbPresets.add(k);
});
spinner.setAdapter(reverbPresets);
spinner.setOnItemSelectedListener(this);
spinner.setSelection(curPresetSoundEffect, true);
}
public interface SoundEffectConvert<In, Out> {
Out convert(In in);
}
private void initReverb() {
presetReverb();
}
private void presetReverb() {
// reverb default type ( 0:无、1:KTV、2:剧场、3:音乐厅、4:录音棚 )
// preset default to reverb sound effect mapping
presetDefaultReverb();
// For VIVO reverb extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: 老唱片
presetExtReverb();
// init reverb view
initSpinnerReverb();
}
private void presetDefaultReverb() {
presetDefaultSoundEffect(mPresetModeMapReverb, this::convertMixerSoundName);
}
private String convertMixerSoundName(int soundType) {
return convertSoundEffectName(soundType, ReverbPresetMode);
}
private void presetExtReverb() {
presetExt(mPresetModeMapReverb, ReverbPresetMode, () -> mMediaClient.getExtMixerSoundType());
}
private void initSpinnerReverb() {
mSpinnerPresetModeReverb = (Spinner) findViewById(R.id.spinner_preset_reverb);
initSpinnerSoundEffectView(mSpinnerPresetModeReverb, mPresetModeMapReverb, mCurPresetReverb);
}
private void setReverbSoundType(int soundIdx) {
mMediaClient.setMixerSoundType(convertSoundTypeByIdx(soundIdx, ReverbPresetMode, mPresetModeMapReverb));
}
private void initEq() {
presetEq();
}
private void presetEq() {
// EQ default type ( 0:无、1:标准、2:浑厚、3:清脆、4:明亮 )
// preset default to EQ sound effect mapping
presetDefaultEq();
// For VIVO EQ extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: KTV
presetExtEq();
// init reverb view
initSpinnerEq();
}
private void presetDefaultEq() {
presetDefaultSoundEffect(mPresetModeMapEq, this::convertEqName);
}
private String convertEqName(int soundType) {
return convertSoundEffectName(soundType, EqPresetMode);
}
private void presetExtEq() {
presetExt(mPresetModeMapEq, EqPresetMode, () -> mMediaClient.getExtEqualizerType());
}
private void initSpinnerEq() {
mSpinnerPresetModeEq = (Spinner) findViewById(R.id.spinner_preset_eq);
initSpinnerSoundEffectView(mSpinnerPresetModeEq, mPresetModeMapEq, mCurPresetEq);
}
private void setEqSoundType(int soundIdx) {
mMediaClient.setMixerSoundType(convertSoundTypeByIdx(soundIdx, EqPresetMode, mPresetModeMapEq));
}
private String convertSoundEffectName(int soundType, @NonNull String[] soundList) {
// reverb type ( 0:无、1:KTV、2:剧场、3:音乐厅、4:录音棚 )
// For VIVO reverb extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: 老唱片
// EQ type ( 0:无、1:标准、2:浑厚、3:清脆、4:明亮 )
// preset default to sound effect mapping
// For VIVO EQ extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: KTV
String typeName = null;
int soundIdx = -1;
switch (soundType) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 10:
case 11:
case 12:
case 13:
soundIdx = soundType;
if (soundType > DEFAULT_MAX_COUNT_REVERB_EQ) {
soundIdx = soundType - 5;
}
// TODO check out of index ???
typeName = soundList[soundIdx];
break;
default:
break;
}
Log.d(TAG, "convertSoundEffectName: " + typeName + ", soundIdx: " + soundIdx +
", soundType: " + soundType);
return typeName;
}
private int convertSoundTypeByIdx(int soundIdx, @NonNull String[] soundList, @NonNull Map<String, Integer> map) {
if (soundIdx < 0 || soundIdx >= soundList.length) {
return -1;
}
// TODO check out of index and NullException ???
return map.get(soundList[soundIdx]);
// return convertSoundEffectType(soundList[soundIdx], soundList);
}
@Deprecated
private int convertSoundTypeByIdx_1(int soundIdx, @NonNull String[] soundList) {
// TODO check out of index ???
if (soundIdx < 0 || soundIdx >= soundList.length) {
return -1;
}
return convertSoundEffectType(soundList[soundIdx], soundList);
}
@Deprecated
private int convertSoundEffectType(String typeName, @NonNull String[] soundList) {
// reverb type ( 0:无、1:KTV、2:剧场、3:音乐厅、4:录音棚 )
// For VIVO reverb extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: 老唱片
// EQ type ( 0:无、1:标准、2:浑厚、3:清脆、4:明亮 )
// preset default to sound effect mapping
// For VIVO EQ extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: KTV
int soundType = -1;
int soundIdx = -1;
for (int i = 0; i < soundList.length; i++) {
String mode = soundList[i];
if (mode != null && mode.equals(typeName)) {
soundIdx = i;
break;
}
}
if (soundIdx == -1) {
return soundType;
}
soundType = soundIdx;
if (soundIdx > DEFAULT_MAX_COUNT_REVERB_EQ) {
soundType = soundIdx + 5;
}
Log.d(TAG, "convertSoundEffectType: " + typeName + ", soundIdx: " + soundIdx +
", soundType: " + soundType);
return soundType;
}
// setToneMode, to set magic voice
private void initToneMode() {
presetToneMode();
}
private void presetToneMode() {
// magic voice type [-12, 12]
presetDefaultTone();
// init magic voice view
initSpinnerTone();
}
private void presetDefaultTone() {
presetDefaultToneMode(mPresetModeMapTone, this::convertToneModeName);
}
private void presetDefaultToneMode(@NonNull Map<String, Integer> map,
@NonNull SoundEffectConvert<Integer, String> sec) {
for (int i = 0; i < 25; i++) {
// String typeName = convertMixerSoundName(i);
String typeName = sec.convert(i);
if (typeName == null) {
continue;
}
map.put(typeName, i);
}
}
private String convertToneModeName(int toneMode) {
return convertToneModeNames(toneMode, TonePresetMode);
}
private void initSpinnerTone() {
mSpinnerPresetModeTone = (Spinner) findViewById(R.id.spinner_preset_tone);
initSpinnerToneModeView(mSpinnerPresetModeTone, TonePresetMode, mCurPresetTone);
}
private void setMagicVoice(int toneMode) {
int tone = convertSoundTypeByIdx(toneMode, TonePresetMode, mPresetModeMapTone) - 12;
Log.d(TAG, "setToneMode " + tone);
setToneMode(tone);
}
private void initSpinnerToneModeView(@NonNull Spinner spinner, @NonNull String[] soundList,
int curPresetSoundEffect) {
ArrayAdapter<String> reverbPresets = new ArrayAdapter<String>(this,
R.layout.spinner_item);
reverbPresets.setDropDownViewResource(R.layout.dropdown_style);
for (String s : soundList) {
reverbPresets.add(s);
}
spinner.setAdapter(reverbPresets);
spinner.setOnItemSelectedListener(this);
spinner.setSelection(curPresetSoundEffect, true);
}
private String convertToneModeNames(int soundType, @NonNull String[] soundList) {
// magic voice type [-12,12]
String typeName = null;
int soundIdx = -1;
switch (soundType - 12) {
case -12:
case -11:
case -10:
case -9:
case -8:
case -7:
case -6:
case -5:
case -4:
case -3:
case -2:
case -1:
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
soundIdx = soundType;
// TODO check out of index ???
typeName = soundList[soundIdx];
break;
default:
break;
}
Log.d(TAG, "convertSoundEffectName: " + typeName + ", soundIdx: " + soundIdx +
", soundType: " + soundType);
return typeName;
}
@Override
public void onClick(View arg0) {
if (arg0 == mKTVMode) {
enableKTVMode();
} else if (arg0 == mBtnSelint) {
Toast.makeText(this, "Silent audio data does not need to be played", Toast.LENGTH_SHORT).show();
playSilent();
} else if (arg0 == mBtnStop) {
stopMusic();
} else if (arg0 == mBtnSing) {
if (isRecording) {
Log.v(SING_TAG, "stop ktv sing");
stopRecord();
stopMusic();
closeKTVDevice();
mBtnSing.setText(R.string.text_sing);
} else {
if (mMusicPathAdapter.getCount() <= 0) {
Toast.makeText(this, "Music wav file under sdcard is empty", Toast.LENGTH_SHORT).show();
return;
}
Log.v(SING_TAG, "start ktv sing");
sendMsg(mKTVHandler, MSG_SLIENT_START, 0, 0, DelaySlientStart);
sendMsg(mKTVHandler, MSG_KTV_MODE_ENABLE, 0, 0, DelayKTVEnable);
sendMsg(mKTVHandler, MSG_RECORD_START, 0, 0, DelayRecordStart);
sendMsg(mKTVHandler, MSG_PLAYBACK_START, 0, 0, DelayPlayStart);
mBtnSing.setText(R.string.text_stop_playing);
}
} else if (arg0 == mBtnRecord) {
if (isRecording) {
stopRecord();
stopMusic();
closeKTVDevice();
mBtnRecord.setText(R.string.text_record);
} else {
if (!mAudioPlayer.isPlaying())
playSilent();
startRecord();
// TODO: 2022/7/20 NOTE: Maybe we DO NOT use this code to change the logical of function!
// This is a standalone feature test in here!
// enableKTVMode(true);
enableKTVMode();
mBtnRecord.setText(R.string.text_stop_playing);
}
} else if (arg0 == mBtnRecPlay) {
playMusic(RecordWAV);
} else if (arg0 == mPlaySource) {
setPlayFeedbackParam();
} else if (arg0 == mBtnDoSing) {
if (mMusicPathAdapter.getCount() <= 0) {
Toast.makeText(this, "Music wav file under sdcard is empty", Toast.LENGTH_SHORT).show();
return;
}
new Thread(new CompondSingThread()).start();
} else if (arg0 == mBtnSingPlay) {
playMusic(SINGWAV);
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (mVolMic == seekBar) {
mMediaClient.setMicVolParam(progress);
mTextVolMic.setText(Integer.toString(progress));
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if (arg0 == mSpinnerPresetModeReverb) {
if (mCurPresetReverb != arg2) {
setReverbSoundType(arg2);
// mMediaClient.setMixerSoundType(convertSoundTypeByIdx(arg2, ReverbPresetMode));
// mMediaClient.setEqualizerType(arg2);
mCurPresetReverb = arg2;
}
} else if (arg0 == mSpinnerPresetModeEq) {
if (mCurPresetEq != arg2) {
// mMediaClient.setMixerSoundType(arg2);
// mMediaClient.setEqualizerType(arg2);
setEqSoundType(arg2);
mCurPresetEq = arg2;
}
} else if (arg0 == mSpinnerPresetModeTone) {
if (mCurPresetTone != arg2) {
setMagicVoice(arg2);
mCurPresetTone = arg2;
}
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
@SuppressLint("HandlerLeak")
private Handler mReportHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
Editable text = (Editable) mReport.getText();
switch (msg.what) {
case MSG_REPORT_RECORD_COST:
text.append("\nstartRecording cost ");
text.append(Integer.toString(msg.arg1));
text.append(" ms");
break;
case MSG_REPORT_READ_COST:
text.append("\nRead first frame cost ");
text.append(Integer.toString(msg.arg1));
text.append(" ms");
break;
case MSG_REPORT_TOTAL_COST:
text.append("\nTotal Record Start cost ");
text.append(Integer.toString(msg.arg1));
text.append(" ms");
break;
case MSG_REPORT_SING_START:
text.append("\nSing Compound Start!");
break;
case MSG_REPORT_SING_FINISH:
text.append("\nSing Compound Finished!");
break;
default:
break;
}
}
};
@SuppressLint("HandlerLeak")
private Handler mKTVHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SLIENT_START:
Log.v(SING_TAG, "MSG_SLIENT_START");
playSilent();
break;
case MSG_KTV_MODE_ENABLE:
Log.v(SING_TAG, "MSG_KTV_MODE_ENABLE");
// TODO: 2022/7/20 Here we must open if closed when user sing
enableKTVMode(true);
break;
case MSG_RECORD_START:
Log.v(SING_TAG, "MSG_RECORD_START");
startRecord();
break;
case MSG_PLAYBACK_START:
String path = mMusicPathAdapter.getItem(mSpinnerMusicSelector.getSelectedItemPosition());
Log.v(SING_TAG, "MSG_PLAYBACK_START: " + path);
playMusic(path);
break;
default:
break;
}
}
};
private static void sendMsg(Handler handler, int what, int arg1, int arg2, int delay) {
// FIXME: if here are multi clients, this line may remove the wrong msg.
handler.removeMessages(what);
handler.sendMessageDelayed(
handler.obtainMessage(what, arg1, arg2), delay);
}
// public static final int DEVICE_OUT_WIRED_HEADSET = 0x4;
// private boolean isHeadsetHasMic()
// {
// AudioManager localAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// int type = localAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC);
// Log.v(TAG, "KTV isHeadsetHasMic: type = " + type);
// return (type == AudioManager.DEVICE_OUT_WIRED_HEADSET);
// }
private boolean isHeadsetPlugIn() {
AudioManager localAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
return localAudioManager.isWiredHeadsetOn();
}
private void playSilent() {
// TODO Silent data does not need to be played
// if (mSlientPlayer == null)
// mSlientPlayer = new SlientPlayer();
//
// if (!mSlientPlayer.isPlaying())
// mSlientPlayer.play();
}
private void playMusic(String path) {
Log.d(TAG, "playMusic path: " + path);
if (mAudioPlayer.isPlaying()) {
mAudioPlayer.pause();
}
try {
// channel 3 flag for AudioFormat.CHANNEL_CONFIGURATION_STEREO
// format 2 flag for 16bit
AudioParamBean audioParam = new AudioParamBean(44100, 3, 2);
mAudioPlayer.setAudioParam(audioParam);
// 读取PCM文件内容
byte[] data = null;
try {
// InputStream inputStream = getResources().openRawResource(R.raw.rainy_city);
data = toByteArray(new FileInputStream(path), path.endsWith(".wav"));
} catch (Exception e) {
e.printStackTrace();
}
mAudioPlayer.setDataSource(data);
mAudioPlayer.prepare();
mAudioPlayer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
/***
* 将inputStream转换为byte[]
*/
public static byte[] toByteArray(InputStream input, boolean skipWAVHeader) throws Exception {
Log.d(TAG, "playMusic toByteArray skipWAVHeader: " + skipWAVHeader);
if (skipWAVHeader) {
// only skip once
long actSkipLength = input.skip(WAVE_HEADER_NUM);
Log.d(TAG, "playMusic toByteArray actSkipLength: " + actSkipLength);
if (actSkipLength != WAVE_HEADER_NUM) {
Log.w(TAG, "Warning! playMusic toByteArray actSkipLength is not 44 !");
}
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024 * 4];
int n;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
}
private void stopMusic() {
if (mAudioPlayer.isPlaying()) {
mAudioPlayer.pause();
}
// if (mSlientPlayer != null
// && mSlientPlayer.isPlaying())
// mSlientPlayer.stop();
}
private void startRecord() {
Log.v(TAG, "startRecord getListenRecordSame mode: " + mMediaClient.getListenRecordSame());
mRecStartTime = System.currentTimeMillis();
mRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, SampleRateInHz,
AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, RecBufSize * 2 * 2);
// mRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
// SampleRateInHz,
// AudioFormat.CHANNEL_IN_STEREO,
// AudioFormat.ENCODING_PCM_16BIT,
// RecBufSize*2*2);
mRecord.startRecording();
isRecording = true;
int duration = (int) (System.currentTimeMillis() - mRecStartTime);
sendMsg(mReportHandler, MSG_REPORT_RECORD_COST, duration, 0, 0);
mSingDelay = 0;
new Thread(new AudioRecordThread()).start();
}
private void stopRecord() {
Log.v(TAG, "stopRecord");
isRecording = false;
synchronized (mRecordLock) {
if (mRecord != null) {
mRecord.stop();
mRecord.release();
mRecord = null;
}
}
}
class AudioRecordThread implements Runnable {
@Override
public void run() {
writeDateTOFile();
copyWaveFile(AudioPCM, RecordWAV);
Log.v(TAG, "copyWaveFile over!");
/*
try {
File file = new File(AudioPCM);
if (file.exists()) {
file.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
*/
}
}
private void writeDateTOFile() {
byte[] recorddata = new byte[RecBufSize * 4];
FileOutputStream fos = null;
int readsize = 0;
int serial = 0;
try {
File file = new File(AudioPCM);
Log.d(SING_TAG, "AudioRecordThread run 111 AudioPCM file: " + file);
if (file.exists()) {
Log.d(SING_TAG, "AudioRecordThread run 222 AudioPCM file: " + file);
file.delete();
}
Log.d(SING_TAG, "AudioRecordThread run 333 AudioPCM file: " + file);
file.createNewFile();
Log.d(SING_TAG, "AudioRecordThread run 444 AudioPCM file: " + file);
fos = new FileOutputStream(file);
} catch (Exception e) {
Log.e(SING_TAG, "AudioRecordThread run err: " + e.getMessage());
e.printStackTrace();
}
Log.v(SING_TAG, "AudioRecordThread run");
while (isRecording) {
synchronized (mRecordLock) {
if (mRecord != null) {
long startTimeMs = System.currentTimeMillis();
readsize = mRecord.read(recorddata, 0, RecBufSize * 4);
int duration = (int) (System.currentTimeMillis() - startTimeMs);
if (serial == 0) {
serial++;
sendMsg(mReportHandler, MSG_REPORT_READ_COST, duration, 0, 0);
int total = (int) (System.currentTimeMillis() - mRecStartTime);
mRecDelay = total;
sendMsg(mReportHandler, MSG_REPORT_TOTAL_COST, total, 0, 0);
}
}
}
if (AudioRecord.ERROR_INVALID_OPERATION != readsize) {
try {
fos.write(recorddata);
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void copyWaveFile(String inFilename, String outFilename) {
FileInputStream in = null;
FileOutputStream out = null;
long totalAudioLen = 0;
long totalDataLen = totalAudioLen + 36;
long longSampleRate = SampleRateInHz;
int channels = 2;
long byteRate = 16 * SampleRateInHz * channels / 8;
byte[] data = new byte[256];
try {
in = new FileInputStream(inFilename);
out = new FileOutputStream(outFilename);
totalAudioLen = in.getChannel().size();
totalDataLen = totalAudioLen + 36;
WriteWaveFileHeader(out, totalAudioLen, totalDataLen,
longSampleRate, channels, byteRate);
while (in.read(data) != -1) {
out.write(data);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 复制单个文件
*
* @param oldpath string 原文件路径 如:c:/fqf.txt
* @param newpath string 复制后路径 如:f:/fqf.txt
* @return boolean
*/
public void copyfile(String oldpath, String newpath) {
try {
File old = new File(oldpath);
if (old.exists()) { //文件存在时
copyfile(new FileInputStream(oldpath), newpath); //读入原文件
} else {
Log.d(TAG, "复制单个文件操作出错");
}
} catch (Exception e) {
Log.d(TAG, "复制单个文件操作出错, err: " + e.getMessage());
e.printStackTrace();
}
}
public void copyfile(InputStream instream, String newpath) {
try {
File file = new File(newpath);
if (file.exists()) {
file.delete();
}
file.createNewFile();
int bytesum = 0;
int byteread = 0;
if (instream != null) { //文件流存在时
FileOutputStream fs = new FileOutputStream(newpath);
byte[] buffer = new byte[1444];
int length;
while ((byteread = instream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
// Log.d(TAG, "bytesum: " + bytesum);
fs.write(buffer, 0, byteread);
}
instream.close();
Log.d(TAG, "copyfile bytesum: " + bytesum);
}
} catch (Exception e) {
Log.d(TAG, "复制单个文件操作出错, err: " + e.getMessage());
e.printStackTrace();
}
}
private static final int WAVE_HEADER_NUM = 44;
private void WriteWaveFileHeader(FileOutputStream out, long totalAudioLen,
long totalDataLen, long longSampleRate, int channels, long byteRate)
throws IOException {
byte[] header = new byte[WAVE_HEADER_NUM];
header[0] = 'R'; // RIFF/WAVE header
header[1] = 'I';
header[2] = 'F';
header[3] = 'F';
header[4] = (byte) (totalDataLen & 0xff);
header[5] = (byte) ((totalDataLen >> 8) & 0xff);
header[6] = (byte) ((totalDataLen >> 16) & 0xff);
header[7] = (byte) ((totalDataLen >> 24) & 0xff);
header[8] = 'W';
header[9] = 'A';
header[10] = 'V';
header[11] = 'E';
header[12] = 'f'; // 'fmt ' chunk
header[13] = 'm';
header[14] = 't';
header[15] = ' ';
header[16] = 16; // 4 bytes: size of 'fmt ' chunk
header[17] = 0;
header[18] = 0;
header[19] = 0;
header[20] = 1; // format = 1
header[21] = 0;
header[22] = (byte) channels;
header[23] = 0;
header[24] = (byte) (longSampleRate & 0xff);
header[25] = (byte) ((longSampleRate >> 8) & 0xff);
header[26] = (byte) ((longSampleRate >> 16) & 0xff);
header[27] = (byte) ((longSampleRate >> 24) & 0xff);
header[28] = (byte) (byteRate & 0xff);
header[29] = (byte) ((byteRate >> 8) & 0xff);
header[30] = (byte) ((byteRate >> 16) & 0xff);
header[31] = (byte) ((byteRate >> 24) & 0xff);
header[32] = (byte) (2 * 16 / 8); // block align
header[33] = 0;
header[34] = 16; // bits per sample
header[35] = 0;
header[36] = 'd';
header[37] = 'a';
header[38] = 't';
header[39] = 'a';
header[40] = (byte) (totalAudioLen & 0xff);
header[41] = (byte) ((totalAudioLen >> 8) & 0xff);
header[42] = (byte) ((totalAudioLen >> 16) & 0xff);
header[43] = (byte) ((totalAudioLen >> 24) & 0xff);
out.write(header, 0, WAVE_HEADER_NUM);
}
private void prepareList(File sddir, int dirlevel) {
try {
prepareList_1(sddir, dirlevel);
} catch (Exception ex) {
Log.d(TAG, "find wav err: " + ex.getMessage());
ex.printStackTrace();
}
}
private void prepareList_1(File sddir, int dirlevel) {
File[] files = sddir.listFiles();
Log.d(TAG, "prepareList_1 DIR getPath: " + sddir.getPath());
Log.d(TAG, "prepareList_1 DIR getName: " + sddir.getName());
if (files != null) {
for (File file : files) {
if (file.isFile()) {
if (file.getName().endsWith(".pcm") || file.getName().endsWith(".wav")) {
Log.d(TAG, "find wav files getName: " + file.getName());
Log.d(TAG, "find wav files getPath: " + file.getPath());
mMusicPathAdapter.add(file.getPath());
mMusicListAdapter.add(file.getName());
}
} else if (file.isDirectory() && dirlevel > 0) {
prepareList(file, dirlevel - 1);
}
}
}
}
// TODO: 2022/7/20 FATAL NOTE:
// This method must be called after opening record when your app must be foreground!
private void setPlayFeedbackParam() {
if (mPlaySource == null) {
return;
}
setPlayFeedbackParam(mPlaySource.isChecked());
}
private void setPlayFeedbackParam(boolean doOpen) {
// mCachedLastPlayFeedbackParam = mCachedCurPlayFeedbackParam;
// Or use them!
// mCachedLastPlayFeedbackParam = mPlaySource.isChecked();
// mCachedLastPlayFeedbackParam = mMediaClient.getPlayFeedbackParam() == 1;
if (mPlaySource == null) {
Log.d(TAG, "setPlayFeedbackParam, mPlaySource=null, doOpen: " + doOpen);
} else {
Log.d(TAG, "setPlayFeedbackParam, doOpen: " + doOpen +
", setPlayFeedback.isChecked: " + mPlaySource.isChecked());
}
// KTV playback feedback mode opened if checked
mMediaClient.setPlayFeedbackParam(doOpen ? 1 : 0);
// mCachedCurPlayFeedbackParam = doOpen;
if (mPlaySource == null) {
return;
}
if (doOpen != mPlaySource.isChecked()) {
mPlaySource.setChecked(doOpen);
}
}
private void enableKTVMode() {
enableKTVMode(mKTVMode.isChecked());
}
private void enableKTVMode(boolean doOpen) {
Log.d(TAG, "enableKTVMode (true for open)mKTVMode.isChecked: " +
mKTVMode.isChecked() + ", doOpen: " + doOpen);
if (!mKTVMode.isChecked() && doOpen) {
mKTVMode.setChecked(true);
}
// KTV mode opened if checked
if (mKTVMode.isChecked()) {
openKTVDevice();
} else {
closeKTVDevice();
}
}
private void openKTVDevice() {
// redundant, garbage, meaningless calls for demo ...
// if (mCachedLastPlayFeedbackParam != mCachedCurPlayFeedbackParam) {
// Log.d(TAG, "enableKTVMode, fallback to previous status mCachedLastPlayFeedbackParam: "
// + mCachedLastPlayFeedbackParam);
// // fallback to previous status
// setPlayFeedbackParam(mCachedLastPlayFeedbackParam);
// } else {
// setPlayFeedbackParam();
// }
// if (mCachedLastListenRecordSame != mCachedCurListenRecordSame) {
// Log.d(TAG, "enableKTVMode, fallback to previous status mCachedLastListenRecordSame: "
// + mCachedLastListenRecordSame);
// setListenRecordSame(mCachedLastListenRecordSame);
// }
// if (mCachedLastExtSpeakerParam != mCachedCurExtSpeakerParam) {
// Log.d(TAG, "enableKTVMode, fallback to previous status mCachedLastExtSpeakerParam: "
// + mCachedLastExtSpeakerParam);
// setExtSpeakerParam(mCachedLastExtSpeakerParam);
// }
setPlayFeedbackParam();
mMediaClient.setMixerSoundType(mSpinnerPresetModeReverb.getSelectedItemPosition());
mMediaClient.setEqualizerType(mSpinnerPresetModeEq.getSelectedItemPosition());
mMediaClient.openKTVDevice();
}
private void doSingConvert(String musicFilename,
String recFilename, String singFilename, int aligncount) {
long totalAudioLen = 0;
long totalDataLen = totalAudioLen + 36;
long longSampleRate = SampleRateInHz;
int channels = 2;
long byteRate = 16 * SampleRateInHz * channels / 8;
FileInputStream music = null;
FileInputStream rec = null;
FileOutputStream sing = null;
int bufcount = 4000;
byte[] wavhead = new byte[WAVE_HEADER_NUM];
byte[] musicbuf = new byte[bufcount * 2 * 2];
byte[] recbuf = new byte[bufcount * 2 * 2];
byte[] singbuf = null;
try {
music = new FileInputStream(musicFilename);
rec = new FileInputStream(recFilename);
sing = new FileOutputStream(singFilename);
totalAudioLen = music.getChannel().size();
totalDataLen = totalAudioLen + 36;
WriteWaveFileHeader(sing, totalAudioLen, totalDataLen,
longSampleRate, channels, byteRate);
int musicready = music.read(wavhead);
int recready = rec.read(wavhead);
musicready = music.read(musicbuf);
if (aligncount > 0) {
Log.v(SING_TAG, "forward count: " + aligncount);
byte[] forwardskip = new byte[aligncount * 2 * 2];
recready = rec.read(forwardskip);
recready = rec.read(recbuf);
} else {
int afterwordcount = -aligncount;
Log.v(SING_TAG, "afterword count: " + afterwordcount);
byte[] alignbuf = new byte[(bufcount - afterwordcount) * 2 * 2];
recready = rec.read(alignbuf);
for (int i = 0; i < alignbuf.length; i++) {
recbuf[afterwordcount + i] = alignbuf[i];
}
}
while (musicready != -1 && recready != -1) {
singbuf = doOverlap(musicbuf, recbuf);
Log.v(TAG, "doSingConvert " + musicready / 2 + " samples");
sing.write(singbuf);
musicready = music.read(musicbuf);
recready = rec.read(recbuf);
}
music.close();
rec.close();
sing.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private byte[] doOverlap(byte[] musicbyte, byte[] recbyte) {
short[] musicshort = new short[musicbyte.length / 2];
ByteBuffer.wrap(musicbyte).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(musicshort);
short[] recshort = new short[recbyte.length / 2];
ByteBuffer.wrap(recbyte).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(recshort);
int temp = 0;
short[] singshort = new short[musicshort.length];
for (int i = 0; i < musicshort.length; i++) {
temp = (int) musicshort[i] + (int) recshort[i];
if (temp > 32767)
temp = 32767;
else if (temp < -32768)
temp = -32768;
singshort[i] = (short) temp;
}
byte[] singbyte = new byte[singshort.length * 2];
ByteBuffer.wrap(singbyte).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(singshort);
return singbyte;
}
class CompondSingThread implements Runnable {
@Override
public void run() {
sendMsg(mReportHandler, MSG_REPORT_SING_START, 0, 0, 0);
String musicpath = mMusicPathAdapter.getItem(mSpinnerMusicSelector.getSelectedItemPosition());
Log.v(TAG, "doSingConvert start: musicpath " + musicpath);
mSingDelay = (DelayPlayStart - DelayRecordStart + LatencyPlay) - (mRecDelay - (RecBufSize * 1000) / SampleRateInHz);
Log.v(SING_TAG, "doSingConvert start: mSingDelay " + mSingDelay);
int aligncount = (mSingDelay * SampleRateInHz) / 1000;
doSingConvert(musicpath, RecordWAV, SINGWAV, aligncount);
Log.v(TAG, "doSingConvert finish");
sendMsg(mReportHandler, MSG_REPORT_SING_FINISH, 0, 0, 0);
}
}
// =================================== check permissions START ================================= /
private void requestPermissionIfNeed() {
requestPermission(this, () -> {
Log.v(TAG, "requestPermissionIfNeed WRITE_EXTERNAL_STORAGE permission was granted");
permissionsPassed();
});
}
private void permissionsPassed() {
File appRootDir = new File("/storage/emulated/0/Android/data/com.example.mediademo/");
File cacheDir = getExternalCacheDir();
Log.d(TAG, "prepareList_1 cacheDir getPath: " + cacheDir.getPath());
Log.d(TAG, "prepareList_1 appRootDir getPath: " + appRootDir.getPath());
// File work_path = getExternalFilesDir(Environment.DIRECTORY_MUSIC);
File work_path = new File(WORKPATH);
Log.v(TAG, "permissionsPassed called, isListGot: " + isListGot +
", work_path.exists: " + work_path.exists());
if (!work_path.exists()) {
Log.v(TAG, "create work path!");
work_path.mkdirs();
}
if (!isListGot) {
copyAllRawFilesToWorkPath();
isListGot = true;
// TODO FATAL NOTE: XiaoMi can not access to this directory...
// prepareList(Environment.getExternalStorageDirectory(), 1);
prepareList(appRootDir, 1);
mMusicListAdapter.notifyDataSetChanged();
}
}
private void copyAllRawFilesToWorkPath() {
// 从assets根目录开始遍历
traverseAssets("", "");
// traverseRaws();
}
private void traverseRaws() {
// InputStream is = getResources().openRawResource(R.raw.langyabang_44100_2ch_16bit_14s);
// copyfile(is, WORKPATH + "langyabang_44100_2ch_16bit_14s.wav");
// try {
// Field[] fields = R.raw.class.getDeclaredFields();
// for (Field field : fields) {
// // rawName: langyabang_44100_2ch_16bit_14s
// String rawName = field.getName();
// int rawId = field.getInt(R.raw.class);
//
// Log.d(TAG, "copyAllRawFilesToWorkPath rawName: " + rawName);
//// Log.d(TAG, "copyAllRawFilesToWorkPath rawId: " + rawId);
//// Log.d(TAG, "copyAllRawFilesToWorkPath R.raw.langyabang_44100_2ch_16bit_14s: " + R.raw.langyabang_44100_2ch_16bit_14s);
// InputStream is = getResources().openRawResource(rawId);
// copyfile(is, WORKPATH + rawName);
// }
// // rawName就是文件名称,如果想要id的话可以通过下面的代码拿到,希望被采纳~
// // rawId = fields[i].getInt(R.raw.class);
// } catch (Exception e) {
// e.printStackTrace();
// Log.e(TAG, "copyAllRawFilesToWorkPath ex err: " + e.getMessage());
// }
}
/**
* 遍历assets文件夹
*
* @param tab 格式化显示占位符
* @param path 在assets中的路径
*/
private void traverseAssets(String tab, String path) {
AssetManager assetManager = getAssets();
try {
// 获取path目录下,全部的文件、文件夹
String[] list = assetManager.list(path);
if (list == null || list.length <= 0) {
// 当前为文件时,或者当前目录下为空
return;
}
for (String fileName : list) {
Log.d(TAG, "copyAllRawFilesToWorkPath traverseAssets fileName: " + fileName);
if (fileName.endsWith(".wav") || fileName.endsWith(".pcm")) {
InputStream is = getAssets().open(fileName);
copyfile(is, WORKPATH + fileName);
}
}
//
// for (int i = 0; i < list.length; i++) {
// System.out.println(tab + list[i]);
//
// String subPath;
// if ("".equals(path)) {
// // 如果当前是根目录
// subPath = list[i];
// } else {
// // 如果当前不是根目录
// subPath = path + "/" + list[i];
// }
//
// traverseAssets(tab.concat("___"), subPath);
// }
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "traverseAssets ex err: " + e.getMessage());
}
}
private static final int REQUEST_CODE = 1024;
private static final boolean skipDrawOverlays = true;
private void requestPermission(Activity con, Runnable run) {
Log.d(TAG, "requestPermission: called");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Log.d(TAG, "requestPermission: Build.VERSION_CODES.R");
// 先判断有没有权限
// if (Environment.isExternalStorageManager()) {
// if (ActivityCompat.checkSelfPermission(con, Manifest.permission.ACTION_MANAGE_OVERLAY_PERMISSIO ==
// PackageManager.PERMISSION_GRANTED) {
if (commonROMPermissionCheck(con)) {
Log.d(TAG, "requestPermission: has permission");
// success
// run.run();
Log.e(TAG, "requestPermission: Build.VERSION_CODES.M");
// 先判断有没有权限
if (ActivityCompat.checkSelfPermission(con, Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(con, Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED) {
Log.e(TAG, "requestPermission: WRITE_READ_EXTERNAL_STORAGE has permissions");
// success
run.run();
} else {
ActivityCompat.requestPermissions(con, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
}
} else {
Log.d(TAG, "requestPermission: has no permission");
if (skipDrawOverlays) {
// permission was not granted, we should request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_CODE);
return;
}
// Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
intent.setData(Uri.parse("package:" + con.getPackageName()));
con.startActivityForResult(intent, REQUEST_CODE);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Log.e(TAG, "requestPermission: Build.VERSION_CODES.M");
// 先判断有没有权限
if (ActivityCompat.checkSelfPermission(con, Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(con, Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED) {
// success
run.run();
} else {
ActivityCompat.requestPermissions(con, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
}
} else {
// success
run.run();
}
}
/**
* 判断悬浮窗权限权限
*/
private boolean commonROMPermissionCheck(Context context) {
boolean result = true;
if (skipDrawOverlays) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG, "RECORD_AUDIO permission was granted");
result = true;
} else {
Log.v(TAG, "RECORD_AUDIO permission was not granted, request!");
// // permission was not granted, we should request the permission.
// ActivityCompat.requestPermissions(this,
// new String[]{Manifest.permission.RECORD_AUDIO},
// MY_PERMISSIONS_REQUEST_RECORD_AUDIO);
result = false;
}
return result;
}
if (Build.VERSION.SDK_INT >= 23) {
try {
Class clazz = Settings.class;
Method canDrawOverlays =
clazz.getDeclaredMethod("canDrawOverlays", Context.class);
result = (boolean) canDrawOverlays.invoke(null, context);
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
}
}
Log.e(TAG, "commonROMPermissionCheck: canDrawOverlays=" + result);
return result;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// if (Environment.isExternalStorageManager()) {
if (commonROMPermissionCheck(this) && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED) {
Log.v(TAG, "onActivityResult READ_WRITE_EXTERNAL_STORAGE permission was granted");
permissionsPassed();
} else {
Log.w(TAG, "onActivityResult READ_WRITE_EXTERNAL_STORAGE permission denied!");
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
// case MY_PERMISSIONS_REQUEST_RECORD_AUDIO:
// if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Log.v(TAG, "RECORD_AUDIO permission was granted");
// } else {
// Log.w(TAG, "RECORD_AUDIO permission denied!");
// }
// break;
case REQUEST_CODE:
if (commonROMPermissionCheck(this) && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED) {
Log.v(TAG, "onRequestPermissionsResult READ_WRITE_EXTERNAL_STORAGE permission was granted");
permissionsPassed();
} else {
Log.w(TAG, "onRequestPermissionsResult READ_WRITE_EXTERNAL_STORAGE permission denied!");
}
break;
}
}
// =================================== check permissions END ================================= /
}
package com.example.mediademo;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.Gson;
import com.itgsa.opensdk.common.OnConnectionSucceedListener;
import com.itgsa.opensdk.media.MediaClient;
import com.itgsa.opensdk.media.extensions.KtvSupportInfo;
import com.itgsa.opensdk.media.extensions.MediaClientUtil;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MEDIA_DEMO";
private static final boolean ONLY_TEST_API = false;
private MediaClient mMediaClient;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ONLY_TEST_API) {
onlyTestAPIForKTV();
return;
}
// Test KTV features using demo
gotoTestKTV();
}
private void gotoTestKTV() {
startActivity(new Intent(this, KTVActivity.class));
}
// private boolean isVivoOs() {
// return "vivo".equals(android.os.Build.MANUFACTURER);
// }
// Generally redundant, meaningless APIs
@Deprecated
private boolean isKtvNewApiSupported_MeaninglessAPICalls() {
// OVM联盟sdk版本号
int version = mMediaClient.getVersion();
Log.d(TAG, "version is: " + version);
//不支持的版本,三方可选择自行适配(部分接口如果后续进行了拓展需要)
if (version < 10000) {
//其他替代方案或界面提示
Log.d(TAG, "version is not supported");
return false;
} else {
Log.d(TAG, "version is supported");
}
// 判断当前机器设备能否支持KTV
boolean isSupportedForDevice = mMediaClient.isDeviceSupportKaraoke();
if (isSupportedForDevice) {
Log.d(TAG, "KTV is supported for current device");
} else {
Log.d(TAG, "KTV is not supported for current device");
return false;
}
// 判断KTV是否支持当前APP
boolean isSupportedForApp = mMediaClient.isAppSupportKaraoke(getApplicationContext().getPackageName());
if (isSupportedForApp) {
Log.d(TAG, "KTV is supported for current APP");
} else {
Log.d(TAG, "KTV is not supported for current device");
return false;
}
return true;
}
// private boolean isKtvNewApiSupported() {
// return MediaClientUtil.isKtvNewApiSupported(mMediaClient);
// }
private void onlyTestAPIForKTV() {
mMediaClient = MediaClient.initialize(getApplicationContext());
// Generally redundant, meaningless APIs
// if (isKtvNewApiSupported_MeaninglessAPICalls()) { // TODO NOTE: We'd better NOT use this judgment
// }
// Whether the ability of KTV new API compatibility supports
// Indicates app is on the new architecture of KTV API
// True if the new API of KTV is supported, running on this device by using new API
// TODO NOTE: Recommend this judgement
if (mMediaClient.isSupported()) {
// or use this, same result
// if (MediaClientUtil.isKtvNewApiSupported(mMediaClient)) {
Log.d(TAG, "KTV is supported for the new architecture of KTV APIs, you can use them");
if (MediaClientUtil.isOsOppo()) {
mMediaClient.addOnConnectionSucceedListener(new OnConnectionSucceedListener() {
@Override
public void onConnectionSucceed() {
Log.i(TAG, "connectionSucceed");
onKtvNewApiSupported();
}
});
} else {
onKtvNewApiSupported();
}
} else {
Log.d(TAG, "KTV is not supported for the new architecture of KTV APIs, " +
"you CAN NOT use them");
// do something
//不支持的版本,三方可选择自行适配(部分接口如果后续进行了拓展需要)
//其他替代方案或界面提示
Log.d(TAG, "new APIs of KTV is not supported for your APP!");
// NOTE: 可以不用下面这个判断逻辑了,因为本来就不支持
// // OVM联盟sdk版本号
// int version = mMediaClient.getVersion();
// Log.d(TAG, "version is: " + version);
// //不支持的版本,三方可选择自行适配(部分接口如果后续进行了拓展需要)
// if (version < 10000) {
// //其他替代方案或界面提示
// Log.d(TAG, "version is not supported");
// } else {
// Log.d(TAG, "API version is supported, but KTV is not supported for your APP!");
// }
}
}
private void onKtvNewApiSupported() {
// 应用获取当前机器支持KTV的参数信息,比如应用设置何种参数(AudioTrack的采样率、flag等,AudioRecord的source等),可以正常使用KTV功能
//
// 若支持任意参数, value置为"default";
// 没有返回的key, value为默认值"default";
// 所有value给十进制数值的字符串形式, 例如AUDIO_SOURCE_MIC需要返回"1", AUDIO_OUTPUT_FLAG_DEEP_BUFFER需要返回"8"
//
// FOR VIVO examples:
// {
// "audioTrackParam": [
// {
// "streamType": "3",
// "sampleRate": "48000",
// "format": "default",
// "flag": "8"
// },
// {
// "streamType": "3",
// "sampleRate": "44100",
// "format": "default",
// "flag": "8"
// }
// ],
// "audioRecordParam": [
// {
// "streamType": "default",
// "sampleRate": "48000",
// "format": "default",
// "flag": "default",
// "source": "0"
// },
// {
// "streamType": "default",
// "sampleRate": "48000",
// "format": "default",
// "flag": "default",
// "source": "1"
// }
// ],
// "isSupportToneMode": false
//}
String ktvSupportInfoJson = mMediaClient.getKaraokeSupportParameters();
Log.d(TAG, "KTV ktvSupportInfoJson: " + ktvSupportInfoJson);
KtvSupportInfo supportInfo = new Gson().fromJson(ktvSupportInfoJson, KtvSupportInfo.class);
Log.d(TAG, "KTV isSupportListenRecordSame: " + supportInfo.isSupportListenRecordSame);
Log.d(TAG, "KTV isSupportExtSpeakerParam: " + supportInfo.isSupportExtSpeakerParam);
Log.d(TAG, "KTV isSupportToneMode: " + supportInfo.isSupportToneMode);
KtvSupportInfo.TrackSupportInfo targetTrackInfo =
new KtvSupportInfo.TrackSupportInfo("3", "48000", "2", "8");
Log.d(TAG, "KTV targetTrackInfo: " + targetTrackInfo.toString());
if (!MediaClientUtil.isTargetAudioSupported(supportInfo, targetTrackInfo)) {
return;
}
// track equals
KtvSupportInfo.RecordSupportInfo targetRecordInfo =
new KtvSupportInfo.RecordSupportInfo("default", "48000", "2", "8", "0");
Log.d(TAG, "KTV targetRecordInfo: " + targetRecordInfo.toString());
if (!MediaClientUtil.isTargetAudioSupported(supportInfo, targetRecordInfo)) {
return;
}
// record equals
Log.d(TAG, "test KTV openKTVDevice");
mMediaClient.openKTVDevice();
// 听录一致,选择录音输出数据,建议接口调用动作应发生在openKTVDevice后与录音前
// 0:录音输出为原始录音数据;1:录音输出为录音+应用playback数据,就是耳返数据(直播场景用);
mMediaClient.setListenRecordSame(1);
int recordSrcMode = mMediaClient.getListenRecordSame();
Log.d(TAG, "KTV ListenRecordSame mode: " + recordSrcMode);
// TODO NOTE: Must use the field supported to check API!!!
if (supportInfo.isSupportExtSpeakerParam) {
if (MediaClientUtil.isOsVivo()) {
testVivoKTV();
}
} else if (supportInfo.isSupportToneMode) {
Log.d(TAG, "setToneMode from SDK!");
mMediaClient.setToneMode(5);
}
// 设置人声音量大小,0~15 (OPPO是0-12,请OPPO确认)
mMediaClient.setMicVolParam(8);
// 获取当前yamaha人声音量值
// value :0~15
int micVolume = mMediaClient.getMicVolParam();
Log.d(TAG, "KTV micVolume: " + micVolume);
// 设置混响效果的音效种类,以及获取额外音效种类
// 类型( 0:无、1:KTV、2:剧场、3:音乐厅、4:录音棚 )
mMediaClient.setMixerSoundType(1);
// For VIVO extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: 老唱片
int[] extSoundTypes = mMediaClient.getExtMixerSoundType();
if (extSoundTypes != null) {
int testOne = 0;
for (int extSoundType : extSoundTypes) {
Log.d(TAG, "KTV extSoundTypes: " + extSoundType);
// just test one
if (testOne == 0) {
testOne = 1;
// You can use it
mMediaClient.setMixerSoundType(extSoundType);
}
}
}
// 设置均衡器EQ效果的音效种类,以及获取额外音效种类
// 类型( 0:无、1:标准、2:浑厚、3:清脆、4:明亮 )
mMediaClient.setEqualizerType(1);
// For VIVO extensions as bellow:
// 10: 温暖, 11: 空灵, 12: 3D迷幻, 13: KTV
int[] extEqTypes = mMediaClient.getExtEqualizerType();
if (extEqTypes != null) {
int testOne = 0;
for (int extEqType : extEqTypes) {
Log.d(TAG, "KTV extEqTypes: " + extEqType);
// just test one
if (testOne == 0) {
testOne = 1;
// You can use it
mMediaClient.setEqualizerType(extEqType);
}
}
}
// 控制耳返开启/关闭接口,系统默认打开,建议无论怎么app调用都打开调用一次,排除其他app不正确调用的干扰。
// 0 关闭:1 开启
mMediaClient.setPlayFeedbackParam(1);
// 获取当前耳返开关状态
// 0:开关未打开 1:开关已打开
int feedbackPlayState = mMediaClient.getPlayFeedbackParam();
Log.d(TAG, "KTV feedbackPlayState: " + feedbackPlayState);
Log.d(TAG, "test KTV closeKTVDevice");
mMediaClient.closeKTVDevice();
Log.d(TAG, "test KTV END");
}
private void testVivoKTV() {
Log.d(TAG, "testVivo KTV START");
// 控制外接音响设备开关,这个接口的开出是为了当用户使用大音响或者大功放设备K歌,此情景下啸叫厉害,故开了此接口。
// 注意:该接口在三个手机平台中都调用了也没有关系,只是在不支持的手机中不会有该功能,因此只有vivo手机中调用才起作用
// 0:关 1:开
mMediaClient.setExtSpeakerParam(1);
// 获取当前外接音响设备开关状态。
// 0:开关未打开 1:开关已打开
int extSpkState = mMediaClient.getExtSpeakerParam();
Log.d(TAG, "KTV extSpkState: " + extSpkState);
Log.d(TAG, "testVivo KTV END");
}
// public Gson createGson() {
// GsonBuilder builder = new GsonBuilder();
// builder.registerTypeAdapter(Integer.class, new IntegerDefaultAdapter());
// builder.registerTypeAdapter(String.class, new StringDefaultAdapter());
// return builder.create();
// }
//
// public class IntegerDefaultAdapter extends TypeAdapter<Integer> {
//
// @Override
// public void write(JsonWriter jsonWriter, Integer integer) throws IOException {
// jsonWriter.value(String.valueOf(integer));
// }
//
// @Override
// public Integer read(JsonReader jsonReader) throws IOException {
// try {
// return Integer.valueOf(jsonReader.nextString());
// } catch (NumberFormatException e) {
// e.printStackTrace();
// return -1;
// }
// }
// }
//
// public class StringDefaultAdapter extends TypeAdapter<String> {
//
// @Override
// public void write(JsonWriter jsonWriter, String s) throws IOException {
// jsonWriter.value(s);
// }
//
// @Override
// public String read(JsonReader jsonReader) throws IOException {
// if (jsonReader.peek() == JsonToken.NULL) {
// jsonReader.nextNull();
// return "";
// } else {
// return jsonReader.nextString();
// }
// }
// }
//
// public class StringNullAdapter extends TypeAdapter<String> {
//
// @Override
// public void write(JsonWriter writer, String value) throws IOException { // TODO Auto-generated method stub
// if (value == null) {
// writer.nullValue();
// return;
// }
// writer.value(value);
// }
//
// @Override
// public String read(JsonReader reader) throws IOException { // TODO Auto-generated method stub
// if (reader.peek() == JsonToken.NULL) {
// reader.nextNull();
// return "";
// }
// return reader.nextString();
// }
// }
}
package com.example.mediademo.util;
public class AudioParamBean {
//采样率
public int mSampleRateInHZ;
//声道
public int mChannel;
//音频数据的格式
public int mAudioFormat;
public AudioParamBean(int mSampleRateInHZ, int mChannel, int mAudioFormat) {
this.mSampleRateInHZ = mSampleRateInHZ;
this.mChannel = mChannel;
this.mAudioFormat = mAudioFormat;
}
}
package com.example.mediademo.util;
import android.media.AudioTrack;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
/***
* Description : 使用AudioTrack播放音乐
*/
public class AudioPlayer {
private static final String TAG = "AudioPlayer";
public static final int STATE_MSG_ID = 16;
private Handler mHandler;
//音频参数
private AudioParamBean mAudioParam;
//音频数据
private byte[] mData;
//AudioTrack对象
private AudioTrack mAudioTrack;
//播放源是否就绪
private boolean mBReady = false;
//播放线程
private PlayAudioThread mPlayAudioThread;
//线程退出标志
private boolean mThreadExitFlag = false;
//较优播放块大小
private int mPrimePlaySize = 0;
//当前播放位置
private int mPlayOffset = 0;
//当前播放状态, 0 未初始化, 2 正在播放
private int mPlayState = 0;
public AudioPlayer(Handler handler) {
mHandler = handler;
}
//设置播放参数
public void setAudioParam(AudioParamBean audioParam) {
mAudioParam = audioParam;
}
//设置播放源
public void setDataSource(byte[] data) {
mData = data;
}
//准备播放源
public boolean prepare() {
if (mData != null && mAudioParam != null) {
if (mBReady) {
return true;
} else {
try {
createAudioTrack();
} catch (Exception var2) {
var2.printStackTrace();
return false;
}
mBReady = true;
setPlayState(1);
return true;
}
} else {
return false;
}
}
public boolean release() {
stop();
releaseAudioTrack();
mBReady = false;
setPlayState(0);
return true;
}
public boolean start() {
if (!mBReady) {
return false;
} else {
switch (mPlayState) {
case 1:
mPlayOffset = 0;
setPlayState(2);
startThread();
case 2:
default:
break;
case 3:
setPlayState(2);
startThread();
}
return true;
}
}
public boolean pause() {
if (!mBReady) {
return false;
} else {
if (mPlayState == 2) {
setPlayState(3);
stopThread();
}
return true;
}
}
public boolean stop() {
if (!mBReady) {
return false;
} else {
setPlayState(1);
stopThread();
return true;
}
}
public boolean isPlaying(){
return mPlayState==2;
}
private synchronized void setPlayState(int state) {
mPlayState = state;
if (mHandler != null) {
Message msg = mHandler.obtainMessage(16);
msg.obj = mPlayState;
msg.sendToTarget();
}
}
/*
*构建一个AudioTrack对象
*/
private void createAudioTrack() throws Exception {
int minBufSize = AudioTrack.getMinBufferSize(mAudioParam.mSampleRateInHZ, mAudioParam.mChannel, mAudioParam.mAudioFormat);
mPrimePlaySize = minBufSize * 2;
Log.d("AudioPlayer", "mPrimePlaySize = " + mPrimePlaySize);
mAudioTrack = new AudioTrack(3, mAudioParam.mSampleRateInHZ, mAudioParam.mChannel, mAudioParam.mAudioFormat, minBufSize, 1);
}
private void releaseAudioTrack() {
if (mAudioTrack != null) {
mAudioTrack.stop();
mAudioTrack.release();
mAudioTrack = null;
}
}
private void startThread() {
if (mPlayAudioThread == null) {
mThreadExitFlag = false;
mPlayAudioThread = new PlayAudioThread();
mPlayAudioThread.start();
}
}
private void stopThread() {
if (mPlayAudioThread != null) {
mThreadExitFlag = true;
mPlayAudioThread = null;
}
}
public void onPlayComplete() {
mPlayAudioThread = null;
if (mPlayState != 3) {
setPlayState(1);
}
}
/*
*播放音频线程
*/
class PlayAudioThread extends Thread {
PlayAudioThread() {
}
public void run() {
mAudioTrack.play();
while (!mThreadExitFlag) {
try {
mAudioTrack.write(mData, mPlayOffset, mPrimePlaySize);
mPlayOffset = mPlayOffset + mPrimePlaySize;
} catch (Exception var2) {
var2.printStackTrace();
onPlayComplete();
break;
}
// 循环播放
if (mPlayOffset >= mData.length) {
mPlayOffset = 0;
}
}
mAudioTrack.stop();
Log.d("AudioPlayer", "PlayAudioThread complete...");
}
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity"/>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:singleLine="true"
android:textSize="15sp"
android:textColor="#f77718"
android:gravity="left"
android:background="#aa33ac"
android:id="@+id/textView3333" />
\ No newline at end of file
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_ktv_mode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="@+id/tb_ktv_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_play_music"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/btn_stop"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:clickable="true"
android:text="@string/text_stop_playing" />
<Button
android:id="@+id/btn_silent"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_toLeftOf="@id/btn_stop"
android:clickable="false"
android:text="@string/text_silent"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="4dip"
android:paddingBottom="4dip">
<Spinner
android:id="@+id/spinner_music"
android:layout_width="255dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<Button
android:id="@+id/btn_selected"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:clickable="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_ktv_record"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/btn_record_play"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:clickable="true"
android:text="@string/text_replay" />
<Button
android:id="@+id/btn_record"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_toLeftOf="@id/btn_record_play"
android:clickable="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_csing"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/btn_sing_play"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:clickable="true"
android:text="@string/text_replay" />
<Button
android:id="@+id/btn_sing"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_toLeftOf="@id/btn_sing_play"
android:clickable="true"
android:text="@string/text_start" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_play_source"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="@+id/tb_play_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_vol_mic"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/text_vol_mic"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<SeekBar
android:id="@+id/skb_vol_mic"
android:layout_width="230dip"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/text_vol_mic" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_save_preset_reverb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_preset_mode_reverb"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner_preset_reverb"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/tv_save_preset_reverb" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_save_preset_eq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_preset_mode_eq"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner_preset_eq"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/tv_save_preset_eq" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_save_preset_tone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_preset_mode_tone"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner_preset_tone"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/tv_save_preset_tone" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_output_select"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="@+id/rg_ext_spkr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_head_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_head_out" />
<RadioButton
android:id="@+id/rb_ext_spkr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_ext_spkr" />
</RadioGroup>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/text_rec_source"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="@+id/rg_rec_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_mic_direct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_mic_direct" />
<RadioButton
android:id="@+id/rb_mixed_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_mixed_out" />
<RadioButton
android:id="@+id/rb_process_mic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_process_mic" />
</RadioGroup>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/report"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3dp" />
</ScrollView>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:textColor="#f77718"
android:gravity="left"
android:textSize="15sp"
android:padding="10dp"
android:singleLine="true"
android:id="@+id/textView32" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Itgsa" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">mediademo</string>
<string name="title_KTV">KTVRecord Test</string>
<string name="text_ok">OK</string>
<string name="text_notok">Error</string>
<string name="text_vol_offset">Analog Volume Offset:</string>
<string name="text_dualmic">Dual Mic:</string>
<string name="text_bt_sco">BT SCO:</string>
<string name="text_hifi">HIFI: </string>
<string name="btn_set">Set</string>
<string name="btn_reload">Reload SRS MaxV Settings</string>
<string name="text_maxv">Enable SRS MaxV:</string>
<string name="text_mode">Mode: </string>
<string name="text_maxv_mode">MaxV Mode:</string>
<string name="text_vol_mode">Volume Mode:</string>
<string name="text_AClipEnable">Enable Anti-Clip:</string>
<string name="text_HighPassFilterEnable">Enable HPF:</string>
<string name="text_HighPassFilterCutoff">HPF CutOff:(0~24000)</string>
<string name="text_LowPassFilterEnable">Enable LPF:</string>
<string name="text_LowPassFilterCutoff">LPF CutOff:(0~24000)</string>
<string name="text_NoiseManagerEnable">Enable Noise Manager:</string>
<string name="text_VolCtrlEnable">Enable Volume Ctrl :</string>
<string name="text_LeftPeqMasterEnable">Enable Left PEQ:</string>
<string name="text_RightPeqMasterEnable">Enable Right PEQ:</string>
<string name="text_ReferLevel">Reference Level:(0~7fffffff)</string>
<string name="text_AntiClipLevel">Anti-Clip Level:(0~7fff)</string>
<string name="text_NoiseThresh">Noise Threshold:(0~7fffffff)</string>
<string name="text_InputGain">InputGain:(0~7fff)</string>
<string name="text_OutputGain">OutputGain:(0~7fff)</string>
<string name="text_streams">Stream Type:</string>
<string name="text_devices">Device Type:</string>
<string name="text_knee">Volume Knee:</string>
<string name="text_index">Volume Index(1~255):</string>
<string name="text_attenuation">Volume Attenuation(>0dB):</string>
<string name="text_audio_fmt">Audio Format:</string>
<string name="text_volume_default">DEFAULT:</string>
<string name="text_volume_headset">HEADSET:</string>
<string name="text_volume_speaker">SPEAKER:</string>
<string name="text_effect_bbe">BBE:</string>
<string name="text_effect_srs">effect:</string>
<string name="text_set_prop">Set System Property</string>
<string name="text_get_prop">Generate conf file</string>
<string name="text_recording">RECRODING:</string>
<string name="text_start_recording">Start</string>
<string name="text_stop_recording">Stop</string>
<string name="text_agc">Automatic Gain Control</string>
<string name="text_agc_target_level">Target Level:</string>
<string name="text_agc_comp_gain">Compression Gain:</string>
<string name="text_agc_limiter_enable">Limiter Enable:</string>
<string name="text_aec">Acoustic Echo Canceler</string>
<string name="text_aec_echo_delay">Echo Delay:</string>
<string name="text_ns">Noise Suppression</string>
<string name="text_playing">Playing:</string>
<string name="text_start_playing">Start</string>
<string name="text_stop_playing">Stop</string>
<string name="ENbutton">SRS Vip+ Enable</string>
<string name="STbutton">SRS Vip+ Set Parameter</string>
<string name="text_stream_in">StreamIn</string>
<string name="text_stream_out">StreamOut</string>
<string name="text_bbesonicmax_switch">Enable BBESonicmax:</string>
<string name="text_bbesonicmax_bypass">BBESonicmax Master Bypass:</string>
<string name="text_bbesonicmax_D3_bypass">3D-Expansion Bypass:</string>
<string name="text_bbesonicmax_HI_bypass">High Mode Bypass:</string>
<string name="text_bbesonicmax_M3_bypass">Mach 3 Bass Bypass:</string>
<string name="text_bbesonicmax_MP_bypass">MP Bypass:</string>
<string name="text_bbesonicmax_HPF_bypass">High Pass Filter Bypass:</string>
<string name="text_bbesonicmax_3D_gain">3D Gain:(50~150)</string>
<string name="text_bbesonicmax_cont_level">Cont Level:(0~120)</string>
<string name="text_bbesonicmax_proc_level">Proc Level:(0~120)</string>
<string name="text_bbesonicmax_iSet_freq">iSet Freq:(400~2000)</string>
<string name="text_bbesonicmax_HI_level">HI Level:(60~120)</string>
<string name="text_bbesonicmax_M3_Q">M3 Q:(50~150)</string>
<string name="text_bbesonicmax_M3_gain">M3 Gain:(0~120)</string>
<string name="text_bbesonicmax_M3_freq">M3 Freq:(40~300)</string>
<string name="text_bbesonicmax_MP_gain">MP Gain:(50~250)</string>
<string name="text_bbesonicmax_HPF_freq">HPF Freq:(20~250)</string>
<string name="text_bbesonicmax_headroom_level">Headroom Level:(-200~0)</string>
<string name="text_bbesonicmax_bypass_level">Bypass Level:(-120~0)</string>
<string name="text_preset_mode_reverb">Preset Reverb Mode:</string>
<string name="text_preset_mode_eq">Preset EQ Mode:</string>
<string name="text_preset_mode_tone">Preset Tone Mode:</string>
<string name="text_reload_save">Reload and Save Settings</string>
<string name="text_audio_source">AudioSource:</string>
<string name="text_audio_encoder">AudioEncoder:</string>
<string name="text_audio_format">AudioFormat:</string>
<string name="text_audio_rate">SampleRate:</string>
<string name="text_audio_channels">Channels:</string>
<string name="title_reccaptest">Record Capability</string>
<string name="text_record">Record</string>
<string name="text_play">Play</string>
<string name="text_pause">Puase</string>
<string name="text_srs_switch">Enable SRS:</string>
<string name="text_srs_inputgain">Input Gain:(0~100)</string>
<string name="text_srs_outputgain">Output Gain:(0~100)</string>
<string name="text_srs_tbspkrsize">Speaker Size:</string>
<string name="text_srs_center">Center:(0~100)</string>
<string name="text_srs_space">Space Control:(0~100)</string>
<string name="text_srs_tbctrl_headset">TruBass:(0~100)</string>
<string name="text_srs_definition_headset">Definition Control:(0~60)</string>
<string name="text_srs_focus_headset">Focus:(0~60)</string>
<string name="text_srs_tbctrl_speaker">TruBass:(0~80)</string>
<string name="text_srs_definition_speaker">Definition Control:(0~50)</string>
<string name="text_srs_focus_speaker">Focus(0~40):</string>
<string name="text_spectrum_switch">Enable Spectrum:</string>
<string name="text_spectrum_mode">Spectrum Mode:</string>
<string name="text_hpx_for_multichannel">HPX[Multichannel Audio]:</string>
<string name="text_ktv_mode">KTV Mode:</string>
<string name="text_vol_mic">Volume Mic:</string>
<string name="text_fb_dly">Feedback Delay:</string>
<string name="text_fb_gain">Feedback Gain:</string>
<string name="text_key_control">Key Control:</string>
<string name="text_room_type">Room Type:</string>
<string name="text_vocal_cancel">Vocal Cancel:</string>
<string name="text_miceq_band_1">MicEQ 1:</string>
<string name="text_miceq_band_2">MicEQ 2:</string>
<string name="text_miceq_band_3">MicEQ 3:</string>
<string name="text_miceq_band_4">MicEQ 4:</string>
<string name="text_miceq_band_5">MicEQ 5:</string>
<string name="text_rec_source">Rec Source:</string>
<string name="text_mic_direct">Direct</string>
<string name="text_mixed_out">Mix Out</string>
<string name="text_process_mic">Process Mic</string>
<string name="text_ld_rm">Ldirect Rmix</string>
<string name="text_play_music">Play:</string>
<string name="text_mic_type">Mic Type:</string>
<string name="text_mic_headset">Mic Headset</string>
<string name="text_mic_handset">Main Mic</string>
<string name="text_ktv_record">Record:</string>
<string name="text_default_sing">Default</string>
<string name="text_silent">Silent</string>
<string name="text_selected">Selected</string>
<string name="text_replay">Replay</string>
<string name="text_play_source">Play Feedback:</string>
<string name="text_output_select">Output Select:</string>
<string name="text_head_out">Headpiece</string>
<string name="text_ext_spkr">Ext Speaker</string>
<string name="text_ns_mode">NS mode:</string>
<string name="text_ns1">NS1</string>
<string name="text_ns2">NS2</string>
<string name="text_ns3">NS3</string>
<string name="text_normal">Normal</string>
<string name="text_preset_reverb">Reverb Mode:</string>
<string name="text_preset_eq">EQ Mode:</string>
<string name="text_save">Save</string>
<string name="text_roomsize">Room Size:</string>
<string name="text_damp">Damp:</string>
<string name="text_wet">Wet:</string>
<string name="text_dry">Dry:</string>
<string name="text_width">Width:</string>
<string name="text_gain">Gain:</string>
<string name="text_compressor">Compressor:</string>
<string name="text_start">Start</string>
<string name="text_stop">Stop</string>
<string name="text_test_mode">KTV Stress Test Type:</string>
<string name="text_ktv_mode_test">KTV Mode(On/Off)</string>
<string name="text_ktv_device_test">KTV Device(Speaker/Headset)</string>
<string name="text_ktv_test">KTV Stress Test Switch:</string>
<string name="text_total_count">Total Switch Count: </string>
<string name="text_switch_time">Switch Time(ms): </string>
<string name="text_clear">Clear Count</string>
<string name="text_echo_mode">Echo Mode:</string>
<string name="text_delay">Delay:</string>
<string name="text_pp">Post Proc:</string>
<string name="text_csing">Compound Sing:</string>
<string name="text_sing">Sing</string>
</resources>
\ No newline at end of file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Itgsa" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.Itgsa.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.KTVTest.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.KTVTest.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
\ No newline at end of file
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1024m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.injected.studio.version.check=false
\ No newline at end of file
#Thu Aug 11 14:58:11 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven {
allowInsecureProtocol true
url 'http://nexus.itgsa.com:5566/repository/gsai-snapshot'
credentials {
username 'developer'
password 'developer!@#'
}
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
allowInsecureProtocol true
url 'http://nexus.itgsa.com:5566/repository/gsai-snapshot'
credentials {
username 'developer'
password 'developer!@#'
}
}
}
}
rootProject.name = "audiodemo"
include ':app'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment