gpt4 book ai didi

javascript - 在浏览器中获取我的视频

转载 作者:行者123 更新时间:2023-11-30 15:28:59 25 4
gpt4 key购买 nike

我使用 Twilio API 在 iPad 和笔记本电脑之间创建视频聊天。

它适用于 iPad:我有 2 个屏幕(大屏幕包含来自笔记本电脑的视频,小屏幕包含来自 iPad 的视频)。但是我在笔记本电脑的浏览器中只有一个大屏幕(带有来自 iPad 的视频),而且我没有小屏幕,带有来自笔记本电脑摄像头的视频。

我的代码:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://media.twiliocdn.com/sdk/js/video/v1/twilio-video.min.js"></script>
</head>
<body>
<script type="text/javascript">
var accessToken = "..."
const Video = Twilio.Video;
const client = new Video.Client(accessToken);
const localMedia = new Video.LocalMedia();

Video.getUserMedia().then(mediaStream => {
localMedia.addStream(mediaStream);
});

client.connect({
to: 'my-room',
localMedia: localMedia
}).then(room => {
const localParticipant = room.localParticipant;
room.participants.forEach(participant => {
participant.on('trackAdded', track => {
if (track.kind === 'audio') {
console.log('Added an AudioTrack %s', track.id);
} else {
console.log('Added a VideoTrack %s', track.id);
}
});
participant.on('trackRemoved', track => {
if (track.kind === 'audio') {
console.log('Removed an AudioTrack %s', track.id);
} else {
console.log('Removed a VideoTrack %s', track.id);
}
});
participant.on('trackEnabled', track => {
if (track.kind === 'audio') {
console.log('Enabled AudioTrack %s', track.id);
} else {
console.log('Enabled VideoTrack %s', track.id);
}
});
participant.on('trackDisabled', track => {
if (track.kind === 'audio') {
console.log('Disabled AudioTrack %s', track.id);
} else {
console.log('Disabled VideoTrack %s', track.id);
}
});

const element = participant.media.attach();
document.body.appendChild(element);

participant.media.tracks.forEach(track => {
track.attach('#track-view');
});
});

room.once('participantConnected', participant => {
console.log('Participant "%s" has connected to the Room', participant.identity);
});

room.once('participantDisconnected', participant => {
console.log('Participant "%s" has disconnected from Room', participant.identity);
});

}, error => {
console.error('Failed to connect to the Room', error);
});
</script>
</body>
</html>

在我笔记本电脑的浏览器中显示带有来自笔记本电脑的视频的小屏幕的最佳方式是什么?

最佳答案

此处为 Twilio 开发人员布道师。

在我看来,您似乎没有将本地媒体附加到页面的任何地方。你能试试这样的东西吗:

Video.getUserMedia().then(mediaStream => {
localMedia.addStream(mediaStream);
const element = localMedia.attach();
document.body.appendChild(element);
});

让我知道这是否有帮助。

关于javascript - 在浏览器中获取我的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42527188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com