admin管理员组文章数量:1332872
I'm using getUserMedia
with the following constraints:
var constraints = {
audio: true,
video: {
width: 960,
height: 540,
}
};
navigator.mediaDevices.getUserMedia(constraints).then(...);
This works when using desktops or when using mobile devices while they are in landscape mode. However, when rotating the mobile device to portrait mode, the video object loses the aspect ratio:
When the device is held as Landscape:
When the device is held as Portrait:
This happens both on iOS and Android devices, on Chorme, Safari and Samsung browser.
I tried playing around with the constraints aspectRatio
, min
, ideal
as suggested by the MDN docs, but it seems these constraints are of no effect at all.
Is there any way to always maintain the aspect ratio as 1.777 even if the mobile device is rotated as portrait mode?
I'm using getUserMedia
with the following constraints:
var constraints = {
audio: true,
video: {
width: 960,
height: 540,
}
};
navigator.mediaDevices.getUserMedia(constraints).then(...);
This works when using desktops or when using mobile devices while they are in landscape mode. However, when rotating the mobile device to portrait mode, the video object loses the aspect ratio:
When the device is held as Landscape:
When the device is held as Portrait:
This happens both on iOS and Android devices, on Chorme, Safari and Samsung browser.
I tried playing around with the constraints aspectRatio
, min
, ideal
as suggested by the MDN docs, but it seems these constraints are of no effect at all.
Is there any way to always maintain the aspect ratio as 1.777 even if the mobile device is rotated as portrait mode?
Share Improve this question edited Jul 9, 2018 at 10:37 Koby Douek asked Jul 9, 2018 at 10:29 Koby DouekKoby Douek 16.7k20 gold badges78 silver badges110 bronze badges1 Answer
Reset to default 6I found out that you can use reversed aspectRatio
when in Portrait mode.
I use this constraints in Landscape mode:
mediaConstraints: MediaStreamConstraints = {
video: {
aspectRatio: 16/9
}
};
and this constraints in Portrait mode:
mediaConstraints: MediaStreamConstraints = {
video: {
aspectRatio: 9/16
}
};
The caveat of this solution is you have to detect orientation change and call again getUserMedia()
, losing your stream.
Also if you are recording the stream, you should prevent screen rotation with ScreenOrientation.lock()
(not working in Safari) so user is not able to reset stream by rotating device while recording.
本文标签: javascriptHow to maintain a landscape aspect ratio with getUserMedia on mobile devicesStack Overflow
版权声明:本文标题:javascript - How to maintain a landscape aspect ratio with getUserMedia on mobile devices? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742311413a2450947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论