processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.69k stars 3.33k forks source link

deviceShaken() does not work on Android >= 11.0 on Firefox #5718

Open Spaxe opened 2 years ago

Spaxe commented 2 years ago

Most appropriate sub-area of p5.js?

p5.js version

1.4.1

Web browser and version

Firefox 102.2.0

Operating System

Android 11 & Android 12

Steps to reproduce this

Steps:

  1. Open https://openprocessing.org/sketch/1615161 on Android
  2. Shake the phone
  3. notice that the acceleration numbers show up on iOS Firefox and Android on Chrome. on Android Firefox it's NaN

I have tried three different Android phones to no avail. I also note that the deviceShaken() example page on p5.js reference doesn't run. https://p5js.org/reference/#/p5/deviceShaken https://p5js.org/reference/#/p5/accelerationX works on my Android 12

Snippet:

let shakenCount = 0;

function setup() {
    createCanvas(windowWidth, windowHeight);
    noLoop();

    //request access to Device Motion API. 
    OpenProcessing.requestDeviceMotion()
        .then(function() {
            setShakeThreshold(5);
            //Once user gives access, this function is called. 
            //Also, all the P5js acceleration variables and functions are accessible.
            loop();
        })

    noStroke();
    textAlign(CENTER);
    textSize(32);
}

function draw() {
    background(255);
    text("x: " + accelerationX, width / 2, height / 5);
    text("y: " + accelerationY, width / 2, 2 * height / 5);
    text("z: " + accelerationZ, width / 2, 3 * height / 5);
    text("shaken: " + shakenCount, width / 2, 4 * height / 5);
}

function deviceShaken() {
    shakenCount++;
}
Spaxe commented 2 years ago

I tested the deviceShaken() once more: https://openprocessing.org/sketch/1615161 Still doesn't work on Android 12, works on iPad 15.

Also discovered that https://p5js.org/reference/#/p5/accelerationX works on my Android 12 ... so I'm not sure how or why.

Spaxe commented 2 years ago

Update: works on Chrome today... weird. Doesn't work on Firefox.

xinranyu-yuki commented 2 years ago

Hi, can I take this issue?

Qianqianye commented 2 years ago

Thanks @xinranyu-yuki. Just assigned you to this issue.