What is the process for enabling HLS.js to retrieve data from the server side?

I have successfully implemented a video player using hls.js, and I have some ts files stored in https:/// along with an m3u8 file.

To read the content of the m3u8 file, I used PHP to fetch it and sent the data to JavaScript (res["manifest"] = the content of m3u8), and then passed it into hls.loadSource(), as shown below:

var manifest = res["manifest"];
var blob = new Blob([manifest]);
var hls = new Hls();
var url = URL.createObjectURL(blob);

hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function() {
    video.load();
});

After this, hls began fetching the files listed in the m3u8 document using the following format:

blob:https://<my domain>/<video name>.mp4

However, since the actual files are located at:

https://<my domain>/<video name>.mp4

View request log

The URLs starting with "blob:" are created by URL.createObjectURL in the front-end. I now want to configure hls to send requests to video.php, which will then read the ts files and respond with their contents from the server side.

Is there any method to achieve this? (such as modifying the source code or changing settings)

Answer №1

I'm so proud of what I've accomplished.

I made changes to the source code in src/loader/fragment.ts as shown below:

@@ -78,9 +78,7 @@ export class BaseSegment {
 
   get url(): string {
     if (!this._url && this.baseurl && this.relurl) {
-      this._url = buildAbsoluteURL(this.baseurl, this.relurl, {
-        alwaysNormalize: true,
-      });
+      this._url = 'video.php?f=' + this.relurl;
     }
     return this._url || '';
   }

I then recompiled with webpack. Now the get request is directed to video.php with the query parameter "f=<video name>.mp4", allowing me to handle the request in my video.php file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps can be taken to resolve the mouse-pointer problem?

Currently, I am utilizing PHP, jQuery, JavaScript, and other tools for my website development. I have a new requirement for a script in jQuery/JavaScript that can trigger an alert when the user's mouse-pointer moves away from the tab where my website ...

Using Selenium and Python to showcase the source of an image within an iframe

My goal is to automatically download an image from shapeNet using Python and selenium. I have made progress, but I am stuck on the final step. from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.s ...

PhoneGap Troubleshooting: Device Plugin Malfunctioning

I'm having trouble getting the device plugin to work with my Cordova/PhoneGap project. Currently, I am using Cordova version 3.3.1-0.1.2. I followed the documentation and installed the plugin using the following command: C:\ProjectFolder>pl ...

The background image refuses to load

I've been working on a website project using nodejs, expressjs, and pug as my template engine. I designed the home page in pure pug but ran into an issue when trying to add a background image to a specific section of the site. Despite double-checking ...

Having trouble locating the function in one of the included JavaScript files when receiving an Ajax response?

I have implemented jquery tabs that initiate an ajax call when a tab is clicked. When the tab is clicked, it triggers the ajax call to fetch the HTML response and then appends it to the current page. However, I am encountering an issue; Within the ajax re ...

Adjusting body styles in a NextJS application using localStorage prior to hydration: A step-by-step guide

If you visit the React website and toggle the theme, your choice will be saved in localStorage. Upon refreshing the page, the theme remains persistent. In my NextJS project, I am attempting to achieve a similar outcome by applying styles to the body eleme ...

avoid selecting a d3 table

I'm currently learning about creating tables in D3 and I have a question regarding when to use ".select()": For example, when constructing circles: var circles = svg.selectAll("circle") .data(dataSet) .enter() .append("circle") .att ...

Personalized configurations from the environment in the config.json file

I need to dynamically populate a setting object in my config.json file based on environment variables. The settings should vary depending on the environment. "somesetting": { "setting1": "%S1%", "setting2": "%S2%" } I am currently working on Wind ...

Exploring the use of data attributes in jQuery to access JSON objects

I have set a data-attribute for multiple elements and I am looking to access the JSON object using this data attribute in jQuery. <div class="content"> <div class="plans" data-plan="state-1"><span class="pricing-symbol">$</span> ...

"Troubleshoot: jQuery UI accordion not functioning properly in response to

I've encountered an issue with the accordion functionality while working with dynamic data. To address this, I'm incorporating JavaScript to generate <div> and <h3> tags for the accordion. Here is the code snippet I am using: $(&ap ...

Identifying when a user is idle on the browser

My current project involves developing an internal business application that requires tracking the time spent by users on a specific task. While users may access additional pages or documents for information while filling out a form, accurately monitoring ...

Obtain all the selection choices in a dropdown list using Selenium

Although I have come across similar questions, this one is distinct in its simplicity. Unlike other queries that involve iterating over options in a loop, my question revolves around the usage of the getOptions() method mentioned in Selenium documentation. ...

Utilizing CSS to Display a Variety of Colors within a Text String

Is it possible to style different words in a sentence with various colors using only CSS, without using the span element? For instance, how can I make the word "Red" appear in red, "Blue" in blue, and "Green" in green within an h1 tag? ...

Utilize the npm module directly in your codebase

I am seeking guidance on how to import the source code from vue-form-generator in order to make some modifications. As a newcomer to Node and Javascript, I am feeling quite lost. Can someone assist me with the necessary steps? Since my Vue project utilize ...

What is the best method for transmitting the filename using Plupload?

I've been trying to solve this issue for a while now. My problem seems straightforward – I want to send the filename along with the file as a multipart request in Plupload, but so far, I haven't had any success. The main thing I'm missin ...

What is the best way to display a component with multiple pieces of content?

I have a tool that generates card components, extracting data from a const array and displaying it in a table format within a card UI component. I am looking to add an ADD button inside each card to open a modal with input fields. However, the issue is tha ...

Issues with jQuery Ajax Request Parsing JSON Data in Internet Explorer

My code is working perfectly with ajax jQuery call to json, except for IE. jQuery.ajax({ url: "/session/json.php", type: "GET", data: "", success: function(data) { var obj = jQuery.parseJSON( ...

The Safari browser is unable to provide the country name in the geolocation response

My geolocation feature for displaying country names is functional in Chrome and Firefox, but not in Safari. How can I troubleshoot this issue? Javascript: $.get("http://freegeoip.net/json/", function (response) { $("#ip").html("IP: " + response.ip); ...

Creating a dynamic line chart in Primefaces that updates every second in JSF 2

I'm looking to create a dynamic webpage featuring a Primefaces line chart that updates every second. Currently, I retrieve 100 data points from my database in the managed bean. Rather than loading all the data at once onto the line chart, I would lik ...

Implementing a Reset Button to Clear Checkboxes with PHP or JavaScript

I'm looking for help with setting up a button to reset the checkboxes on my preferences page. UPDATEL: Here's more information: The solutions provided should only affect checkboxes that are currently selected, not those enabled onLoad. This is ...