我有这个html代码(在php文件中):
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="mystyle/mystyle1.css">
</head>
<body>
<h1> try media stream page</h1> <br>
<div class="container">
<video id="video" width="400" height="300">
Your browser do not suppoer this vidio!
</video>
</div>
<div id="demo">
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="functions/funcs.js"></script>
</body>
</html>
和此javascript代码:
$(document).ready(function(){
var constraints = { audio: true, video: true};
navigator.mediaDevices.getUserMedia(constraints)
.then(mediaStream => {
var video = document.querySelector('video');
video.srcObject = mediaStream;
var myJSON = JSON.stringify(mediaStream);
console.log(myJSON);
video.play();
});
});
当我从浏览器进入php文件时,输出是带有用户摄像头的视频流。
我正在尝试对mediaStream对象进行字符串化 但是stringify函数将空字符串返回到myJSON,这是什么问题?
我的主要目标是对mediaStream对象进行字符串化,然后将字符串写入文件,从其他用户读取该文件,然后将字符串解析回mediaStream对象,以向该用户显示特定用户的摄像机流。
也许还有其他简单的方法可以做到这一点?