1

I’m trying to play a live stream using Video.js in a Vue.js application, but I’m encountering the following error:

  VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either 
  because the server or network failed or because the format is not supported.

Here’s the code I’m using:

<template>
  <video ref="videoPlayer" id="videoPlayer" class="video-js"></video>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import videojs from 'video.js';
import 'video.js/dist/video-js.css';

const videoPlayer = ref(null);
let player = null;

onMounted(async () => {
  player = videojs(videoPlayer.value, {
    autoplay: true,
    controls: true,
    sources: [
      {
        src: 'http://82.212.74.2:8000/live/7407',
        type: 'application/x-mpegURL',
      },
    ],
  });
});
</script>

The stream URL (http://82.212.74.2:8000/live/7407) works perfectly in VLC Player, and VLC shows that the stream is H264 - MPEG-4 AVC.

How can I solve this issue I would really appreciate the help..

2 Answers 2

2

This is an mpegts stream, not HLS, which application/x-mpegURL represents. Video.js doesn't play that, and there is no native browser support. There is an mpegts.js library which may work (I haven't used it), but it's more usual to convert to HLS for browser playout.

2
  • The package worked, THX a lot But I will have to contact to the stream owner to add allow cors header in the server
    – omar ba44
    Commented Mar 24 at 20:46
  • @omarba44 No need for CORS. You need to access the stream using some server-side script/code that lives on your server and then that same code sends data back to the caller (your app). You can try PHP if you know it. Use the .php file link as the source to the player (Mpeg-TS).
    – VC.One
    Commented Mar 28 at 0:17
0

I’m trying to play a live stream using Video.js in a Vue.js application, but I’m encountering the following error:
VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported.

Your stream location is http:// so it cannot load into a page that starts with https://.

The solution is to use a proxy script/code from your server to access the stream at its http location and then return the bytes back into your app.

PS: As mentioned in the other Answer, your bytes are in .ts format. You need to use a TS player like the one that was recommended (or else if you understand M3U8 structure, just create a temporary M3U8 data as a String and turn into URL using createobjecturl, then pass that to VideoJS).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.