Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

UnsupportedOperationException: Cannot create AudioRecord in Android mode #37

Closed
markcosmic opened this issue Jun 18, 2019 · 10 comments
Closed
Labels
Android bug Something isn't working

Comments

@markcosmic
Copy link

Since doing the recent SDK update in Processing for Android:
The Sound Library is no longer functioning in Android mode. I get this error:
java.lang.UnsupportedOperationException: Cannot create AudioRecord
at android.media.AudioRecord$Builder.build(AudioRecord.java:626)
at processing.sound.JSynAndroidAudioDeviceManager$AndroidAudioInputStream.start(Unknown Source:66)
at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source:29)
I installed Processing 3 on 2 windows 10 PCs and a windows 7 PC and received the same error.
As a test I tried the “SimplePlayback” Processing 3 Sound example.
It worked in JAVA mode; giving this INFO:
Jun 11, 2019 12:32:42 PM com.jsyn.devices.javasound.JavaSoundAudioDevice
INFO: JSyn: default output latency set to 80 msec for Windows 10
Here is the sketch, slightly modified:
import processing.sound.*;
SoundFile soundfile;
void setup() {
//fullScreen();
size(640, 360);
background(255);
soundfile = new SoundFile(this, “vibraphon.aiff”);
println(“SFSampleRate= " + soundfile.sampleRate() + " Hz”);
println(“SFSamples= " + soundfile.frames() + " samples”);
println(“SFDuration= " + soundfile.duration() + " seconds”);
soundfile.loop();
}
void draw() {
float playbackSpeed = map(mouseY, 0, width, 0.25, 4.0);
soundfile.rate(playbackSpeed);
float panning = map(mouseX, 0, width, -1.0, 1.0);
soundfile.pan(panning);
}
void mouseDragged(){
float amplitude = map(mouseY, 0, height, 0.2, 1.0);
soundfile.amp(amplitude);
}
I should mention that other than no sound, in Android mode, the apps work fine. I've been using the Sound library for months in Android mode with no issues until my recent use of the SDK Updater in Processing for Android.
Can you help me?

@kevinstadler kevinstadler added Android bug Something isn't working labels Jun 19, 2019
@kevinstadler
Copy link
Collaborator

@markcosmic thanks for reporting! Could you please call Sound.list() from one of your Android sketches and post the output here?

@Calsign any idea what's going on there? I've got a hunch that either the device doesn't support capturing audio at all (hence the UnsupportedOperationException), or maybe the chosen device simply doesn't have any input ports, in which case AndroidAudioInputStream.start() shouldn't try to instantiate the AudioRecord (if someone attempted to create an AudioIn down the line an appropriate error message should be thrown in that case).

@kevinstadler kevinstadler changed the title android mode issue UnsupportedOperationException: Cannot create AudioRecord in Android mode Jun 19, 2019
@markcosmic
Copy link
Author

Thanks for getting back to me. The error this thread now refers to is interesting because the sketch I listed in my original thread only uses playback. I get the same error if I change “import processing.sound.*” to “import processing.sound.SoundFile”. I am not setting up to audio record, nor am I trying to. I’m just trying to get the playback function to work as it did before I used the SDK updater. In using Sound.list(), the emulator reports:
max input 1
max output 1
Along with the mentioned error

@kevinstadler
Copy link
Collaborator

@markcosmic yeah I can see that, I'll have a look. I'm also a bit confused why you're still getting the INFO: JSyn: default output latency set to 80 msec for Windows 10 message though, that one should've been removed some versions ago. Can you tell me what version of Processing, Android Mode as well as the Sound library you are running?

@markcosmic
Copy link
Author

I'm using:
Processing 3.5.3
Android Mode 4.0.4
Sound 2.2.0

@kevinstadler
Copy link
Collaborator

@markcosmic this issue should be fixed with Sound library version 2.2.1, which will become available from the contribution manager in the next couple of days. In the meantime you could already download the new version from here: https://github.com/processing/processing-sound/releases/download/v2.2.1/sound.zip
Simply extract the zip into your Processing/libraries/ folder (on MacOS this is usually in your Documents), replacing the sound folder that's already there. Please let me know if you manage to test the new version, and if it fixes your problem!
@Calsign the new version also adds support for selecting the Android audio input device from within the sketch. In the process I changed the default device from MIC to DEFAULT, please let me know if this breaks anything for your sketches!

@markcosmic
Copy link
Author

Thank you

@markcosmic
Copy link
Author

Ok, been testing the new update 2.2.1. In Java Mode I still get this INFO message:
Jun 24, 2019 3:22:06 PM com.jsyn.devices.javasound.JavaSoundAudioDevice
INFO: JSyn: default output latency set to 80 msec for Windows 10
In Android Mode the sketch doesn't load quickly or smoothly. Using the above listed sketch "SimplePlayBack", the sound starts before the app is visible on the device emulator. When I click the stop button in the Processing IDE the sound keeps playing. The sound stop when I quit the emulator. If I try to run the sketch in Java mode while the sketch is still playing sound from Android Mode, sound resumes when I quit the sketch from Java Mode. Java Mode stops the sound correctly when I stop the sketch. The sound keeps playing in Android Mode even when I start a different sketch in the emulator.

@kevinstadler
Copy link
Collaborator

Does it just not load smoothly or is it also not playing back smoothly? Either way if this is limited to the Android device emulator then there's probably nothing that can be done on the sound library side. Have you tried running the sketch on an actual Android device?

It's true that playback currently does not stop when the sketch is backgrounded on Android (or stopped from the Processing IDE). When running on an actual device the sound only stops when the app is killed on the device itself. If we want to implement the default behaviour to be pausing the playback while the sketch is backgrounded, the appropriate code will have to go here:

public class Callback {
public void dispose() {
lineOut.stop();
synth.stop();
}
public void pause() {
// TODO
}
public void resume() {
// TODO
}
}

I'm a bit confused why the sound keeps playing on the emulator though when the sketch is stopped since dispose() seems to be implemented correctly. @codeanticode do you know more about how these callback functions are invoked differently on the device emulator in comparison to an actual Android system?

@markcosmic
Copy link
Author

I don't know that the callback functions are invoked differently on the device emulator in comparison to an actual Android device, but they act the same. The sound playback did not pause when the sketch was backgrounded on the Android device I tested on. The sound only stopped when the app was killed on the device. Same as the emulator

@markcosmic
Copy link
Author

I honestly don't think the issue is with the Processing Sound library. It seemed to be working fine until the latest Android SDK update. I believe the issue is in the SDK and Google needs to fix it. It's this simple...
Sound Working... Android SDK update... Sound Not working...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants