如何使用 google-cardboard 的磁性按钮在 phone 中 play/pause 视频?
How to play/pause video in phone using magnetic button of google-cardboard?
我正在制作 RajawaliVR 的演示,我想 play/pause 使用 google-cardboard.So 的磁力按钮制作视频,请帮助我如何实现。
你可以使用我的助手 classes 它是一个监听按钮的服务,一些操作通过接口 class 发布到主界面 activity。这是代码
/**
* Created by volkanugur
*
* WORK WITH CARDBOARD VERSION 1
* =============================
* MAGNET
* ========== N-S ============
*/
public class CardBoardButtonHelper extends Service implements SensorEventListener {
private SensorManager sensorManager = null;
private float __SENSOR_OLD_POSITION__ = -1;
long timestamp = 0;
long timestamp_ee = 0;
Singleton __ = Singleton.getInstance();;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
initsensor();
}
private void initsensor() {
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Register magnetic sensor
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
SensorManager.SENSOR_DELAY_UI);
}
@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
float X = event.values[0];
Log.e("Sens",X+"");
if (__SENSOR_OLD_POSITION__!=-1) {
if (Math.abs(X - __SENSOR_OLD_POSITION__) > 50) {
if (Math.abs(timestamp_ee-timestamp)>1300) {
Vibrator v = (Vibrator) __.get__MAIN__().getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
((CardButtonTrigger) (__.get__MAIN__())).CardButton_Triggered();
timestamp_ee = System.currentTimeMillis();
}
timestamp = System.currentTimeMillis();
}
}
__SENSOR_OLD_POSITION__ = X;
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
我正在制作 RajawaliVR 的演示,我想 play/pause 使用 google-cardboard.So 的磁力按钮制作视频,请帮助我如何实现。
你可以使用我的助手 classes 它是一个监听按钮的服务,一些操作通过接口 class 发布到主界面 activity。这是代码
/**
* Created by volkanugur
*
* WORK WITH CARDBOARD VERSION 1
* =============================
* MAGNET
* ========== N-S ============
*/
public class CardBoardButtonHelper extends Service implements SensorEventListener {
private SensorManager sensorManager = null;
private float __SENSOR_OLD_POSITION__ = -1;
long timestamp = 0;
long timestamp_ee = 0;
Singleton __ = Singleton.getInstance();;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
initsensor();
}
private void initsensor() {
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Register magnetic sensor
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
SensorManager.SENSOR_DELAY_UI);
}
@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
float X = event.values[0];
Log.e("Sens",X+"");
if (__SENSOR_OLD_POSITION__!=-1) {
if (Math.abs(X - __SENSOR_OLD_POSITION__) > 50) {
if (Math.abs(timestamp_ee-timestamp)>1300) {
Vibrator v = (Vibrator) __.get__MAIN__().getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
((CardButtonTrigger) (__.get__MAIN__())).CardButton_Triggered();
timestamp_ee = System.currentTimeMillis();
}
timestamp = System.currentTimeMillis();
}
}
__SENSOR_OLD_POSITION__ = X;
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}