【问题标题】:Video orientation javascript视频方向javascript
【发布时间】:2016-08-24 08:12:25
【问题描述】:

我正在使用 angular-js 和 cordova 制作一个移动项目。我想添加一个我想显示视频的功能,当我将设备旋转到横向或纵向时它应该自行旋转,但我有一个限制,在应用程序打开的开头我使用 lockOrientation(portrait) 所以我不想将任何页面旋转到横向,我只想旋转视频而不是屏幕。我尝试用

检测旋转
  window.addEventListener("orientationchange", function() {
        alert("the orientation of the device is now " + screen.orientation.angle);
    });

在 css 中我可以旋转代码下方的视频。

transform:rotate(90deg);

我的问题是如何在使用 lockOrientation 时检测设备的方向?可能吗?因为我无法解锁方向。我是一名学生,对这个环境很陌生。

【问题讨论】:

    标签: javascript android angularjs cordova


    【解决方案1】:

    我用DeviceMotion插件https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device-motion/解决了

    function onSuccess(acceleration) {
        alert('Acceleration X: ' + acceleration.x + '\n' +
              'Acceleration Y: ' + acceleration.y + '\n' +
              'Acceleration Z: ' + acceleration.z + '\n' +
              'Timestamp: '      + acceleration.timestamp + '\n');
    }
    
    function onError() {
        alert('onError!');
    }
    
    var options = { frequency: 3000 };  // Update every 3 seconds
    
    var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
    

    在设备以纵向模式锁定时,我通过加速检测到设备运动,并在检查设备处于纵向模式还是横向模式时进行检查。

    【讨论】:

      猜你喜欢
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多