javascript - 视频方向javascript

标签 javascript android angularjs cordova

我正在使用 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 时检测设备的方向?是否可以?因为我无法解锁方向。我是一名学生,我是这个环境的新手。

最佳答案

我用 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);

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

关于javascript - 视频方向javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39117870/

相关文章:

android - 如何检查 Environment.DIRECTORY_DOCUMENTS 在 android 中为空

javascript - Angular JS - 监听或绑定(bind) $http 请求

javascript - 为什么 res.redirect 实际上没有重定向我?

javascript - 组件指令中的 $destroy

javascript - 根据 AngularJS 的输入更改按钮名称

javascript - 以编程方式触发选择加载方法

javascript - jQuery 不断添加显示 : block to my table row

javascript - d3.js:将数据绑定(bind)到现有的 svg。 selector.each 是做什么的?

android - android中API level11之前的getActionView()的替代方法是什么?

android - HERE Maps Android 集成,MISSING_LIBRARIES 错误