Hi! I have a code working at all. It runs everything and finds sketch’s data. The only error is a deprecated method, but it is underlined yellow, so I think it should not affect.
It says Sketch launched on the device , but on my phone it appears a fast flash and then a black screen when the app is opened.
Pd: I use Processing 3.5.3 on Windows 10 Pro and my phone runs Android 5.1 Lollipop.
Sorry, I am beginner. I am not sure if there is an issue on Android mode version, Processing versions, Android API level or permissions.
Thank you very much
import ketai.sensors.*;
import android.media.MediaPlayer;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
KetaiSensor sensor;
float minSize = 150 * displayDensity;
float maxSize = 300 * displayDensity;
ArrayList<ColorDot> dots;
int stepCount = 0;
int updateTime = 0;
float walkSpeed = 0;
int numNotes = 5;
AudioPlayer [] notes = new AudioPlayer[numNotes];
int lastNote = int(random(1) * 4);
void setup() {
fullScreen();
orientation(LANDSCAPE);
colorMode(HSB, 360, 100, 100, 100);
noStroke();
for (int i = 0; i < numNotes; i++) notes[i] = new AudioPlayer();
notes[0].loadFile(this, "Piano.mf.A1.mp3");
notes[1].loadFile(this, "Piano.mf.G1.mp3");
notes[2].loadFile(this, "Piano.mf.E1.mp3");
notes[3].loadFile(this, "Piano.mf.D1.mp3");
notes[4].loadFile(this, "Piano.mf.C1.mp3");
dots = new ArrayList<ColorDot>();
sensor = new KetaiSensor(this);
sensor.start();
}
void draw() {
background(0, 0, 0);
for (int i = dots.size() - 1; i >= 0 ; i--) {
ColorDot d = dots.get(i);
d.update();
d.display();
if (d.colorAlpha < 1) {
dots.remove(i);
}
}
}
class ColorDot {
float posX, posY;
float rad, maxRad;
float colorHue, colorAlpha;
int note;
ColorDot() {
posX = int(random(1, width/maxSize)) * maxSize;
posY = int(random(1, height/maxSize)) * maxSize;
rad = 0.1;
float speedf = constrain(walkSpeed, 0, 2)/2.0;
maxRad = map(speedf, 1, 0, minSize, maxSize);
selectNote();
colorHue = map(note, 0, 4, 0, 360);
colorAlpha = 70;
}
void selectNote() {
float r = random(1);
note = lastNote;
if (r < 0.4) note--;
else if (r > 0.6) note++;
if (note < 0) note = 1;
if (4 < note) note = 3;
notes[note].play();
lastNote = note;
}
void update() {
if (rad < maxRad) {
rad *= 1.5;
} else {
colorAlpha -= 0.1;
}
}
void display() {
fill(colorHue, 100, 100, colorAlpha);
ellipse(posX, posY, rad, rad);
}
}
void onStepDetectorEvent() {
int now = millis();
stepCount++;
if (5000 < now - updateTime) {
walkSpeed = stepCount/5.0;
stepCount = 0;
updateTime = now;
}
dots.add(new ColorDot());
}
class AudioPlayer extends MediaPlayer {
boolean loadFile(PApplet app, String fileName) {
AssetFileDescriptor desc;
try {
desc = app.getActivity().getAssets().openFd(fileName);
} catch (IOException e) {
println("Error loading " + fileName);
println(e.getMessage());
return false;
}
if (desc == null) {
println("Cannot find " + fileName);
return false;
}
try {
setDataSource(desc.getFileDescriptor(), desc.getStartOffset(), desc.getLength());
setAudioStreamType(AudioManager.STREAM_MUSIC);
prepare();
return true;
} catch (IOException e) {
println(e.getMessage());
return false;
}
}
void play() {
if (isPlaying()) seekTo(0);
start();
}
}