Gershon Papi
Gershon Papi

Reputation: 5106

videojs: Download/stream video in chunks with quality selecton

I want to create a video streaming website, like youtube and I've been stuck on 2 requirements which I'm not sure if videojs solves or not.

  1. Say there's a 1-hour video, I want the video to be downloaded and streamed in chunks, and not the whole file. I've seen that streaming format like HLS and DASH, solves that (looking on the network tab of chrome, I see chunks downloaded as the video plays). But on the other hand, I think it prevents my 2nd requirement.
  2. Different quality selection. I was looking into videojs-contrib-hls and saw and by looking in the demo and the adaptive bitrate switching documentation, it seems that the quality of the video is chosen automatically by some policy (which can be overridden), but cannot be chosen specifically by the user.

I was wondering if maybe I'm not understanding things correctly? Are browsers smart enough to achieve my 1st requirement on their own?

Upvotes: 1

Views: 2542

Answers (1)

murtaza sanjeliwala
murtaza sanjeliwala

Reputation: 205

You can fulfill your 2nd requirement by following way.

   //initilaize your player 
   var player = videojs(element_id);

    player.ready(function () {        
        player.src({
            src: hls_url,
            type: 'application/x-mpegURL'
        });
        player.play();
    });

    player.on('loadedmetadata', function () {
        var _hls = player.hls;

        //get quality list
        var  quality_list = _hls.representations();  //load it to your custom dropdown

        //you can change quality using below (it will select quality greater than 720)
        _hls.representations().forEach(function (rep) {

       //you can change the condition as per your dropdown selection

            if (rep.width > 720) {
                rep.enabled(true);  //select this quality
            } else {
                rep.enabled(false);  //disable this quality
            }
        });

    })

Upvotes: 1

Related Questions