Is It possible to read and define HLS stream key by a vriable instead of stream.key file?

I encrypted an MP4 video file FFMPEG. That gave me a playlist manifest file (namely stream.m3u8), a key file (namely stream.m3u8.key) and some .ts files. I used code below to play stream.m3u8 file and it worked

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><head>
<link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/7.4.1/video.min.js"></script>
</head>
<body>
<video id="example-video" class="video-js vjs-default-skin" controls="controls" width="640" height="360">
<source src="./stream.m3u8" type="application/x-mpegURL" />
</video>
<script>
var player = videojs('example-video');
</script>
</body>
</code>
<code><head> <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet"> <script src="https://vjs.zencdn.net/7.4.1/video.min.js"></script> </head> <body> <video id="example-video" class="video-js vjs-default-skin" controls="controls" width="640" height="360"> <source src="./stream.m3u8" type="application/x-mpegURL" /> </video> <script> var player = videojs('example-video'); </script> </body> </code>
<head>
    <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
    <script src="https://vjs.zencdn.net/7.4.1/video.min.js"></script>
</head>
<body>
    <video id="example-video" class="video-js vjs-default-skin" controls="controls" width="640" height="360">
       <source src="./stream.m3u8" type="application/x-mpegURL" />
    </video>
    <script>
        var player = videojs('example-video');
    </script>
</body>

After I tried to use input and select file attributes and I tried code below

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><html>
<head>
<link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/7.4.1/video.min.js"></script>
</head>
<body>
<label for="input">Choose a video file to process:</label>
<input type="file" id="input" name="input_video">
<p id="demo"><p/>
<video id="video" class="video-js vjs-default-skin" width="320" height="240" controls style="display: none;">
<source id="vid" type="application/x-mpegURL" />
</video>
</body>
<script>
document.getElementById("input").addEventListener("change", function() {
var media = URL.createObjectURL(this.files[0]);
var vid = document.getElementById("vid");
vid.src = media;
var video = document.getElementById("video");
video.style.display = "block";
video.play();
document.getElementById("demo").innerHTML = vid.src;
var player = videojs('video');
//player.play();
});
</script>
</html>
</code>
<code><html> <head> <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet"> <script src="https://vjs.zencdn.net/7.4.1/video.min.js"></script> </head> <body> <label for="input">Choose a video file to process:</label> <input type="file" id="input" name="input_video"> <p id="demo"><p/> <video id="video" class="video-js vjs-default-skin" width="320" height="240" controls style="display: none;"> <source id="vid" type="application/x-mpegURL" /> </video> </body> <script> document.getElementById("input").addEventListener("change", function() { var media = URL.createObjectURL(this.files[0]); var vid = document.getElementById("vid"); vid.src = media; var video = document.getElementById("video"); video.style.display = "block"; video.play(); document.getElementById("demo").innerHTML = vid.src; var player = videojs('video'); //player.play(); }); </script> </html> </code>
<html>
    <head>
        <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
        <script src="https://vjs.zencdn.net/7.4.1/video.min.js"></script>
    </head>

    <body>
        <label for="input">Choose a video file to process:</label>
        <input type="file" id="input" name="input_video">
        <p id="demo"><p/>
        <video id="video" class="video-js vjs-default-skin" width="320" height="240" controls style="display: none;">
            <source id="vid" type="application/x-mpegURL" />
        </video>
    </body>
    
    <script>
        document.getElementById("input").addEventListener("change", function() {
          var media = URL.createObjectURL(this.files[0]);
          
          var vid = document.getElementById("vid");
          vid.src = media;
          
          var video = document.getElementById("video");
          video.style.display = "block";
          video.play();
          
          document.getElementById("demo").innerHTML = vid.src;
          
          var player = videojs('video');
          //player.play();
        });
    </script>

</html>

The code above can read stream.m3u8 playlist file but can not read “key file” because the location of key file is define in stream.m3u8 itself.

When I browse the stream.m3u8 file and try to play, the play window shows the duration (by seconds) but tries and tries and tries to play but can not play. This shows that it can not recall key file.

I believe that if I define key file location out of manifest file, for example inside JavaScript code this problem will be solved.
HOW CAN I DEFINE KEY FILE LOCATION OUT OF PLAYLIST FILE?

You can define the key in JavaScript.

Since you are using Video.js, you have to define that via Video.js. As far as I know, there isn’t any option for that in Video.js API.

Video.js uses http-streaming, and the process of parsing m3u8 done in it. Therefore you’re able to handle that in this library.

Helpful links:

  • package.json
  • decrypts the media-segment if it has a key uri and an iv
  • m3u8-parser

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật