Giter Site home page Giter Site logo

Comments (4)

phamh-si avatar phamh-si commented on August 16, 2024

Has there been any progress on supporting steaming?

from ableplayer.

DevHack avatar DevHack commented on August 16, 2024

@terrill
Any updates made in this front?

from ableplayer.

derekjackson-das avatar derekjackson-das commented on August 16, 2024

+1 for adding HLS format, please.

from ableplayer.

limefrogyank avatar limefrogyank commented on August 16, 2024

It's a bit hacky, but I was able to make it work using hls.js.

When you determine the source url for your stream, you have to enable Hls only after AblePlayer has finished loading. I have to use the data-able-player tag due to forces outside of my control. I couldn't find an event I could use to trigger the time to setup Hls, so I ended up just waiting 1 second at a time. (Yes, very hacky) But this will load the hls javascript without it already being in the html document, too.

const myVideo = {video element};
const streamSrc = "https://something.com/path/to/a.m3u8";

async function waitForAblePlayerLoad() {
  let count = 0;
  const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
  const frameDelay = () => new Promise(resolve => requestAnimationFrame(resolve));
  
  let foundPlayer = null;
  do {
	  await waitFor(1000);
	  //await frameDelay();
	  AblePlayerInstances.forEach(player => {
		  if (player.media == myVideo) {
			  foundPlayer = player;
		  }
	  });
	  count++;
	  //console.log(count);
	  if (count > 20) {
		  // just in case we don't want to wait forever
		  throw new Error("Timeout: AblePlayer not created after 20 seconds... should not happen");
		  break;
	  }
  } while (foundPlayer == null || !foundPlayer.playerCreated);
  
  if (hlsScriptTagPromise == null) {
	  hlsScriptTagPromise = new Promise((resolve) => {
		  var hlsScriptTag = document.createElement('script');
		  hlsScriptTag.onload = () => {
			  resolve();
		  };
		  hlsScriptTag.src = "https://cdn.jsdelivr.net/npm/hls.js@latest";
		  const firstScriptTag = document.getElementsByTagName('script')[0];
		  firstScriptTag.parentNode?.insertBefore(hlsScriptTag, firstScriptTag);
	  });
  }
  await hlsScriptTagPromise;
  if (Hls.isSupported()) {
	  var hls = new Hls();
	  //console.log(hls);
	  hls.loadSource(streamSrc);
	  hls.attachMedia(myVideo);
  }
}
waitForAblePlayerLoad();

from ableplayer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.