Güncel YouTube uygulamasını soran ne yapar kullanmalıdır burada düşünüyorum.
Video oynatma başvurumda da aynı tür bir sorunla uğraştım.
o/o portre iken cihaz etrafında (orientation >= 60 && orientation <= 120) || (orientation >= 240 && orientation <= 300)
olacağını yatay yön aralığına yatması halinde peyzaja kullanıcı kuvvetleri yönlendirme, 0'dan 360
İzle değişmektedir SensorManager
cihaz yönüne size bildirir OrientationEventListener initialize ederse ve bu durumu bir numaraya veya bir bayrağa kaydedin ve sonra aygıt Dikey yönelim aralığına geri dönerse (orientation <= 40 || orientation >= 320
), enum/flag'ı işaretleyin ve setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
numaralı telefonu arayın, bayrağı/enonu sıfırlayın ve kullanıcı zorla yeniden yönlendirinceye kadar sensörü devre dışı bırakın. ,
private enum SensorStateChangeActions {
WATCH_FOR_LANDSCAPE_CHANGES, SWITCH_FROM_LANDSCAPE_TO_STANDARD, WATCH_FOR_POTRAIT_CHANGES, SWITCH_FROM_POTRAIT_TO_STANDARD;
}
private SensorStateChangeActions mSensorStateChanges;
public void goFullScreen() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
mSensorStateChanges = SensorStateChangeActions.WATCH_FOR_LANDSCAPE_CHANGES;
if (null == sensorEvent)
initialiseSensor(true);
else
sensorEvent.enable();
}
public void shrinkToPotraitMode() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mSensorStateChanges = SensorStateChangeActions.WATCH_FOR_POTRAIT_CHANGES;
if (null == sensorEvent)
initialiseSensor(true);
else
sensorEvent.enable();
}
/**
* Initialises system sensor to detect device orientation for player changes.
* Don't enable sensor until playback starts on player
*
* @param enable if set, sensor will be enabled.
*/
private void initialiseSensor(boolean enable) {
sensorEvent = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
/*
* This logic is useful when user explicitly changes orientation using player controls, in which case orientation changes gives no callbacks.
* we use sensor angle to anticipate orientation and make changes accordingly.
*/
if (null != mSensorStateChanges
&& mSensorStateChanges == SensorStateChangeActions.WATCH_FOR_LANDSCAPE_CHANGES
&& ((orientation >= 60 && orientation <= 120) || (orientation >= 240 && orientation <= 300))) {
mSensorStateChanges = SensorStateChangeActions.SWITCH_FROM_LANDSCAPE_TO_STANDARD;
} else if (null != mSensorStateChanges
&& mSensorStateChanges == SensorStateChangeActions.SWITCH_FROM_LANDSCAPE_TO_STANDARD
&& (orientation <= 40 || orientation >= 320)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
mSensorStateChanges = null;
sensorEvent.disable();
} else if (null != mSensorStateChanges
&& mSensorStateChanges == SensorStateChangeActions.WATCH_FOR_POTRAIT_CHANGES
&& ((orientation >= 300 && orientation <= 359) || (orientation >= 0 && orientation <= 45))) {
mSensorStateChanges = SensorStateChangeActions.SWITCH_FROM_POTRAIT_TO_STANDARD;
} else if (null != mSensorStateChanges
&& mSensorStateChanges == SensorStateChangeActions.SWITCH_FROM_POTRAIT_TO_STANDARD
&& ((orientation <= 300 && orientation >= 240) || (orientation <= 130 && orientation >= 60))) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
mSensorStateChanges = null;
sensorEvent.disable();
}
}
};
if (enable)
sensorEvent.enable();
}
Bu, YouTube işlevselliğine benzer çalıştı bu yardımcı olur umarım:
İşte demo kodudur.
Uygulamam varsayılan olarak dikey modda. Kullanıcı, bir düğmeyi tıklatarak veya cihazı eğerek yatay moda geçebilir. Ancak manzara modunda, etkinliği tekrar dikey moda getirmenin bir yolu yoktur. Yönlendirmeyi dikey olarak zorlamak için başka bir düğme sağlanacaksa, bu son seçenek olacaktır. Ben bilmek istedim manzaraya zorladıktan sonra sensör moduna ayarlamak mümkündür. Duraklatmada sensör moduna ayarlı seçeneğini denedim, ancak cihaz dikey moddayken manzara moduna geçmek istediğimde portre moduna geri dönecek. – Kulai