GithubHelp home page GithubHelp logo

muxinc / hls-video-element Goto Github PK

View Code? Open in Web Editor NEW
38.0 15.0 18.0 191 KB

A custom element (web component) for playing HTTP Live Streaming (HLS) videos.

Home Page: https://hls-video-element-mux.vercel.app

License: MIT License

JavaScript 59.40% HTML 40.60%

hls-video-element's Introduction

hls-video-element's People

Contributors

dylanjha avatar evoactivity avatar github-actions[bot] avatar heff avatar luwes avatar mmcc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hls-video-element's Issues

Support tracks (subtitles, thumbnails) as children of the element

Hey! We're using this library and media-chrome, I'd like to add a thumbnail track in combination with support for m3u8 files that I pull from Mux, so basically this:

https://github.com/muxinc/media-chrome/blob/4c4ef8a03aaef406d6ebfd14f8f737d7a523552b/examples/control-elements/media-clip-selector.html#L18-L24

but with the hls-video element. I've tried extending/copying the hls-video web component, but I haven't figured out how to place the track into the actual

I was hoping this would work:

<hls-video-custom slot="media" src={videoSrc}>
  <track
    slot="media"
    label="thumbnails"
    default
    kind="metadata"
    src={`https://image.mux.com/${playbackId}/storyboard.vtt`}
  ></track>
</hls-video-custom>

It looks like maybe custom-video-element should allow appending children to the native video element here: https://github.com/muxinc/custom-video-element/blob/8723e13a7622c23bb277b518afd300ddae3dbde2/index.js#L43

Maybe something like this in custom-video-element?

if (template.nativeChild) {
  nativeEl.appendChild(template.nativeChild);
}

autoplay not working

Loving the work done here!

I can't seem to get autoplay to work on my end though. Should this be added alongside control?

Unable to resume the live video from paused position

There is no option to make the live video resumable from paused position . The video always goes to the end while resuming. May be i could not find the way to do that or there isn't any way to do that. Please give feedback .

Manage error like Hls do

Hi,

It should be great to manage error like hls doc suggère, see https://github.com/video-dev/hls.js/blob/master/docs/API.md#fifth-step-error-handling.

hls.on(Hls.Events.ERROR, function (event, data) {
  var errorType = data.type;
  var errorDetails = data.details;
  var errorFatal = data.fatal;

  switch (data.details) {
    case Hls.ErrorDetails.FRAG_LOAD_ERROR:
      // ....
      break;
    default:
      break;
  }
});
hls.on(Hls.Events.ERROR, function (event, data) {
  if (data.fatal) {
    switch (data.type) {
      case Hls.ErrorTypes.NETWORK_ERROR:
        // try to recover network error
        console.log('fatal network error encountered, try to recover');
        hls.startLoad();
        break;
      case Hls.ErrorTypes.MEDIA_ERROR:
        console.log('fatal media error encountered, try to recover');
        hls.recoverMediaError();
        break;
      default:
        // cannot recover
        hls.destroy();
        break;
    }
  }
});

Cordialement,

PS: I could have propose a PR for this and the 2 other issues I submitted today but I haven't done before ...

How to access hlsConfig?

For local development reasons, i need to rewrite the URLs to the partfiles and playlists when hls.js is requesting them. The hls.js config uses thexhrSetup property for this, but i could not find a way to make my config known to the hls-video-element. I am using a pure ES6 & preact enviroment, running directly in the browser, so no webpack is involved - just to clarify the situation.

This is what I've tried so far:

<hls-video
  controls
  src="/media/somewhere/masterplaylist.m3u8"
  config="{ \"xhrSetup\": function (xhr, url) {.....} }"
  hlsConfig="{ \"xhrSetup\": function (xhr, url) {.....} }"
</hls-video>

Yet hls.js seems to not receive the config data from the attribute, so my question is:
How can i make the hls -config object known to the element?

Version used: https://unpkg.com/hls-video-element@0
Example config im using:

{
  xhrSetup: function (xhr, url) {
    if (url.indexOf('https://my-project.com/') !== -1) {
       url = url.replace(
         'https://my-project.com/',
         'http://127.0.0.1:8000/'
        )
     }
     xhr.open('GET', url)
     throw new Error('this never gets thrown - this code is never reached anyways')
   }
}

Expose hls

Hi,

In my project I have a list of videos. Right now, if 10 videos appear then I have 10 start load and it consume a lot of bandwidth even if the user don't watch them. It's one of the main problem for me to use only hls video element and not other js player as usual.

So, I have made a test and if I attach hls to "this", like this.hls = new Hls ... then I can access outside hls.

May I made a mistake ? How can I control ouside the behavior of hls attach to a video ?

Thanks.

Providing fallback MP4

Thanks for this component!

Forgive a possibly naive question, but I'm trying to understand what happens if both the native HLS support and hls.js are incompatible with a given browser?

Is this too rare of a case to be concerned about?

With a native video tag, you might provide multiple sources:

<video>
	<!-- Selected if browser has native HLS support -->
	<source
		src="https://example.com/some-video-playlist.m3u8"
		type="application/x-mpegURL"
	/>
	<!-- Selected if browser does not have native HLS support -->
	<source
		src="https://example.com/some-video.mp4"
		type="video/mp4"
	/>
	Your browser does not support HTML5 video.
</video>

HLS-native browsers (like Safari) correctly play the m3u8, and incompatible browsers correctly play the mp4.

However the same markup with the hls-video element always seems to play the mp4, even if there's native HLS support or hls.js would have worked.

<hls-video>
	<!-- Expected to be selected if browser has native HLS support OR hls.js works -->
	<source
		src="https://example.com/some-video-playlist.m3u8"
		type="application/x-mpegURL"
	/>
	<!-- In practice this is always selected -->
	<source
		src="https://example.com/some-video.mp4"
		type="video/mp4"
	/>
	Your browser does not support HTML5 video.
</hls-video>

Any advice on the correct approach to supporting this edge case is appreciated.

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.