videojs: Download/stream video in chunks with quality selecton

有些话、适合烂在心里 提交于 2019-12-24 11:06:53

问题


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?


回答1:


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
            }
        });

    })


来源:https://stackoverflow.com/questions/51598081/videojs-download-stream-video-in-chunks-with-quality-selecton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!