[英]Blob video stream not showing on iOS when receiving a stream from socket.io (JavaScript and Node.js)
This works perfectly fine on android (every part of it).这在 android(它的每个部分)上都可以正常工作。 But when I receive a video stream wrapped in a blob on iOS from android or another iOS device, it does not show any sign of loading the video or displaying it.
But when I receive a video stream wrapped in a blob on iOS from android or another iOS device, it does not show any sign of loading the video or displaying it. However, when I show my own video to myself on iOS, it works.
但是,当我在 iOS 上向自己展示自己的视频时,它可以工作。
I have tried the following:我尝试了以下方法:
video.setAttribute('autoplay', '');
video.setAttribute('playsinline', '');
video.setAttribute('muted', '');
Or adding a source element to the video element, but these did not work.或者向视频元素添加源元素,但这些都不起作用。
How am I supposed to fix the receiving video issue on iOS?我应该如何解决 iOS 上的接收视频问题?
Code (sorry for all the styling):代码(对不起所有的样式):
Client:客户:
let media;
const done = document.getElementById('done');
const vidCon = document.getElementById('video-con');
var getUserMedia = (navigator.mediaDevices.getUserMedia || navigator.mediaDevices.webkitGetUserMedia || navigator.mediaDevices.mozGetUserMedia).bind(navigator.mediaDevices);
getUserMedia({
video: true,
audio: true
}).then((stream) => {
const myVideo = document.createElement('video');
myVideo.srcObject = stream;
myVideo. setAttribute('autoplay', '');
myVideo. setAttribute('muted', '');
myVideo. setAttribute('playsinline', '');
myVideo.style.width = '100%';
myVideo.style.height = '80%';
myVideo.muted = true;
myVideo.style.display = 'block';
myVideo.style.objectFit = 'cover';
media = new MediaRecorder(stream);
media.onstart = function(e) {
this.chunks = [];
myVideo.play();
document.getElementById('video-base-con').append(myVideo);
}
done.onclick = function() {
media.stop();
audio.src = "93642-Blakes_7_Gun_144bpm.wav";
audio.play();
audio.addEventListener('ended', go);
done.style.display = 'none';
document.getElementById('blank-choosing').style.display = 'block';
}
media.ondataavailable = function(e) {
this.chunks.push(e.data);
}
media.onstop = function(e) {
myVideo.remove();
var blob = new Blob(this.chunks, { 'type' : 'video/ogg; codecs=opus' });
socket.emit('send-video', blob);
}
});
socket.on('recieve-video', (stream, codeNew) => {
if (codeNew == code.value) {
document.getElementById('blank-video').style.display = 'none';
console.log('recieved video.');
const blob = new Blob([stream], { 'type' : 'video/ogg; codecs=opus' });
const video = document.createElement('video');
video.src = window.URL.createObjectURL(blob);
video. setAttribute('autoplay', '');
video. setAttribute('muted', '');
video. setAttribute('playsinline', '');
vidCon.style.display = 'block';
video.style.width = '90%';
video.style.height = '100%';
video.style.objectFit = 'cover';
vidCon.style.width = '100%';
vidCon.style.height = '100%';
vidCon.style.textAlign = 'center';
vidCon.style.backgroundColor = 'lightgray';
vidCon.style.borderRadius = '30px';
vidCon.append(video);
video.play();
video.addEventListener('ended', () => {
video.remove();
vidCon.style.display = 'none';
answers.style.display = 'block';
}, false);
}
});
Server:服务器:
socket.on('send-video', (blob) => {
socket.broadcast.emit('recieve-video', blob, code);
});
Thanks in advance!提前致谢!
This is almost certainly a media type (f/k/a MIME type) issue.这几乎可以肯定是媒体类型(f/k/a MIME 类型)问题。 The default media types generated by MediaRecorder are not the same on Android and iOS devices.
MediaRecorder 生成的默认媒体类型在 Android 和 iOS 设备上不同。 Right after your
media = new MediaRecorder(stream)
line examine the media type with media.mimeType
to see what default you received in each case.在您的
media = new MediaRecorder(stream)
行之后,使用media.mimeType
检查媒体类型,以查看您在每种情况下收到的默认值。
You can try choosing the media type explicitly with code like this, so you don't get stuck with the default.您可以尝试使用这样的代码显式选择媒体类型,这样您就不会被默认设置所困扰。
media = new MediaRecorder(stream, {mimeType: 'video/mp4'})
or或者
media = new MediaRecorder(stream, {mimeType: 'video/webm'})
You may have to struggle to find a common media type provided by both Android and iOS.您可能很难找到 Android 和 iOS 提供的通用媒体类型。
It looks like you're trying to choose the media type in your Blob constructor.看起来您正在尝试在 Blob 构造函数中选择媒体类型。 You Can't Do That™.
你不能那样做™。 The media type is set when you construct your MediaRecorder.
媒体类型在您构建 MediaRecorder 时设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.