julioz / audiocapturesample Goto Github PK
View Code? Open in Web Editor NEWSample project to test the AudioCapture API introduced in Android 10 (Q)
Sample project to test the AudioCapture API introduced in Android 10 (Q)
When I run this code in the emulator when playing music with another app, nothing is recorded. I tried several music apps.
All permissions are given.
I do get the popup message about the recording and I see the icon on top about the recoding.
The recoding file is saved, but when I open it, it only contains zeros.
I tried it on android 10 and 11.
Android 10: Automotive emulator and Polestar 2
Android 11: Automotive emulator (both with headset on and off)
Can you give me this project named by 《AudioCaptureSample》 with Java code?
I am trying to record youtube audio playback. When I play the .pcm file, I cannot hear anything. I am playing the recordings on a pcm player and my audio encoding is the same as in the java code.My android studio version is 3.5.0 and I am running code for android Q.
I have been implementing this functionality to record audio playbacks played on the device.
It is working fine when my app is in foreground, and I am getting pretty fine audio recordings, but it is throwing the below error whenever my app goes to background.
I have implemented this as a service and starting this service from another service which is a foreground service. I have tried all of the configuration for audioFormat but audioRecord object is failing to initialize.
Below is the function where app is crashed at run time.
private final void startAudioCapture() {
AudioPlaybackCaptureConfiguration config = new AudioPlaybackCaptureConfiguration.Builder(mediaProjection)
.addMatchingUsage(AudioAttributes.USAGE_MEDIA)
.build();
AudioFormat audioFormat = new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(8000)
.setChannelMask(AudioFormat.CHANNEL_IN_MONO)
.build();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
return;
}
int bufferSize = AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
audioRecord = new AudioRecord.Builder()
.setAudioFormat(audioFormat)
.setBufferSizeInBytes(bufferSize)
.setAudioPlaybackCaptureConfig(config)
.build();
audioRecord.startRecording();
audioCaptureThread = new Thread() {
@Override
public void run() {
File outputFile = createAudioFile();
writeAudioToFile(outputFile);
}
};
audioCaptureThread.start();
mIsRecording = true;
}
Errors:- E/IAudioFlinger: createRecord returned error -1 E/AudioRecord: createRecord_l(1): AudioFlinger could not create record track, status: -1 E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1. E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.Myapp.app.internal, PID: 18240 java.lang.RuntimeException: Unable to start service com.Myapp.app.AudioService@bfz0813 with Intent { act=AudioService:Start cmp=com.Myapp.app.internal/com.Myapp.app.AudioService }: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
Note:- This works perfect for all android version less than 11.
I am a student.
I want to rewrite this code in java.
for Microphone audio recording I get permission like the following.
public class Microphone extends AppCompatActivity {
public static boolean permissionToRecordAccepted = false;
private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200;
private String[] permissions = {Manifest.permission.RECORD_AUDIO};
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_microphone);
if (this.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, REQUEST_RECORD_AUDIO_PERMISSION);
} else {
permissionToRecordAccepted = true;
}
if (permissionToRecordAccepted) {
System.out.println("permission granted.");
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_RECORD_AUDIO_PERMISSION:
permissionToRecordAccepted = (grantResults[0] == PackageManager.PERMISSION_GRANTED);
}
}
}
I want to rewrite this code in java. But , I am confused .
I didn't know how to get permission for internal audio captureing in java.
Can you help me to get permission for internal audio ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.