javascript – Change video src in Mac and iOS browsers?


The mediaRequest API returns a blob object.
I dynamically change src for video and image tags. This works on PC, Android browsers . Changing src for image tag also works on Mac Safari/iOS browsers .
Changing src for video tag does not work on Mac Safari/iOS. Black screen in video tag.There are no errors in the console.

Blob {size: 19390998, type: 'application/octet-stream'}

Code:

mediaRequest(media.id, media.contentType)
  .then((mediaRes) => {
    console.log(mediaRes);
    const container = document.querySelector(`.${typeChat}`);
    if (filetype === "image") {
      const mediaPlaceholder = container.querySelector(`img[data-media-id="${media.id}"]`);
      mediaPlaceholder.src = url.createObjectURL(mediaRes);
    } else if (filetype === "video") {
      const mediaPlaceholder = container.querySelector(`video[data-media-id="${media.id}"]`);
      mediaPlaceholder.src = url.createObjectURL(mediaRes);
    }
  })
  .catch((error) => console.log(error));

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img