我正在使用HTML Media Capture和while(scanf("%s %d%d",&znak,&X,&Y)!=EOF){
if(znak=='+'){
if(index==number){
size_t newnum = (number + 2) * 2;
int **tmp=(int **)realloc(ponuka, newnum * sizeof(*ponuka));
number=newnum;
ponuka=tmp;
} // allocating array
ponuka[index]=(int *)malloc(2 * sizeof ( int )); // 2nd dimension
ponuka[index][0]=X;
ponuka[index][1]=Y;
index++;
}
else{
int first=1;
int match=0;
int bestDeal;
int tmp;
for (i = ass; i < index; i++){
if(ponuka[i][0]==X && ponuka[i][1]<=Y && ponuka[i][1]>0){
if(first){tmp=ponuka[i][1];}
if(ponuka[i][1]<=tmp){
tmp=ponuka[i][1];
bestDeal=i;
} // found match and assign index into variable;;
match=1;
}
}
int gg=ponuka[bestDeal];
ponuka[bestDeal]=ponuka[0];
ponuka[0]=gg;
ass++; // trying to swap values and incrementing looping so matches values will be at start and loop wont go through them
}
}
}
方法。它不能与Chrome一起使用,我会在失败时收到警报。
以下是我使用的示例代码:
getUserMedia
答案 0 :(得分:2)
Chrome无法识别标准的navigator.getUserMedia。它适用于Microsoft Edge。您需要添加供应商前缀。
对于Chrome:navigator.webkitGetUserMedia
这是JSFiddle的工作代码 https://jsfiddle.net/RamiSarieddine/t9d3hpyr/
//browser support check "ms" vendor function is for IE8
navigator.getUserMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia );
if (navigator.getUserMedia) {
navigator.getUserMedia(
// constraints
{
video: true,
audio: true
},
// successCallback
function (localMediaStream) {
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(localMediaStream);
// Do something with the video
video.play();
},
// errorCallback
function (err) {
console.log("The following error occured: " + err);
}
);
} else {
alert("getUserMedia not supported by your web browser or Operating system version");
}
答案 1 :(得分:2)
navigator.getUserMedia
已被navigator.mediaDevices.getUserMedia
取代。
后者使用现代承诺,可在Edge,Firefox和Chrome中本地使用。还有adapter.js官方WebRTC polyfill可以帮助他们达到标准(例如srcObject
)。
这是一个适用于所有三个方面的小提琴:https://jsfiddle.net/srn9db4h/
var constraints = { video: true, audio: true };
navigator.mediaDevices.getUserMedia(constraints)
.then(stream => video.srcObject = stream)
.catch(e => console.error(e));
答案 2 :(得分:1)
无法使用Chrome
尝试使用webkit
,moz
前缀,请参阅Navigator.getUserMedia()
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
if (navigator.getUserMedia) {
//do stuff
}
答案 3 :(得分:0)
这个小验证怎么样?
async getMediaStream(constraints): Promise<MediaStream> {
return new Promise(function (resolve, reject) {
if (navigator.mediaDevices
&& navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => resolve(stream))
.catch(err => reject(err));
} else {
const getUserMedia = navigator.getUserMedia
|| navigator['webkitGetUserMedia']
|| navigator['mozGetUserMedia']
|| navigator['msGetUserMedia'];
getUserMedia(
constraints,
(stream) => resolve(stream),
(err) => reject(err)
);
}
});
}
const isEdge = navigator.userAgent.indexOf('Edge') !== -1
&& (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob);
getMediaStream({
audio: isEdge ? true : {
echoCancellation: false
}
})
.then(stream => console.log(stream))
.catch(err => console.error(err))
关于,尼科尔斯:)