Code Monkey home page Code Monkey logo

Comments (9)

matvp91 avatar matvp91 commented on August 15, 2024

indigo-player does not support changing formats on the fly. However, it's best to destroy your first player (which will gracefully kill the instance and free memory) and initialize a new one. This is some sample code:

let player = IndigoPlayer.init(container, firstConfig);
player.destroy();
player = IndigoPlayer.init(container, secondConfig);

Changing source on the video element is not a good idea as there might be other logic wrapped around it (in order to play MPEG-DASH, HLS, or another supported format). It's best to stick to the API in order not to break anything unexpectedly.

from indigo-player.

stoicbuddha avatar stoicbuddha commented on August 15, 2024

Sorry, I should clarify: I don't want to switch formats, I want to switch sources (so HLS -> HLS). I fully understand why switching formats would be implausible, but switching media sources shouldn't be as big of a deal.

I did notice there is a setSource on player inside of the instance object, but that gives me the same result at this time (seems to switch, DOM Exception gets thrown when I try to play it).

from indigo-player.

matvp91 avatar matvp91 commented on August 15, 2024

Using player.setSource(...) would break, because you're setting the HLS source directly to the video element this way. indigo-player takes care of loading your sources (which is one single format in the list of formats) by booting hlsjs for you and setting the correct MediaSource buffer to the video element.

The list of sources is not designed to support multiple assets, it is designed to support a single asset provided by multiple formats to support a wider range of browsers. Eg: you'll have an asset encoded in DASH+Widevine, HLS+FairPlay, ... and indigo will pick the first supported format for your browser. The way it's designed, a player instance is responsible for a single asset in it's first supported format.

Is there a reason why destroying and initializing the player a second time (which would not impact load time, as hlsjs media chunk is already fetched) would not work?

Sample here: https://codepen.io/matvp91/pen/KLaKmW (click the two buttons to switch the source).

from indigo-player.

stoicbuddha avatar stoicbuddha commented on August 15, 2024

It looks like that may be what we end up having to do. I'm not opposed to it, it just wasn't feasible with our last player. I'll close this, as a solution technically exists. Perhaps something to add to the docs?

from indigo-player.

stoicbuddha avatar stoicbuddha commented on August 15, 2024

@matvp91 So I'm finally getting back to this, and am fine redrawing the player for switching source. However, I'm needing to do this within the module but I don't seem to have access to the top-level player variable from inside of the module unless I store the player in the global window and access it that way.

Is there a method to do this from within a module?

from indigo-player.

matvp91 avatar matvp91 commented on August 15, 2024

Each facade returned by IndigoPlayer.init is specifically for the video asset provided in the config by design. I suggest adding code to switch the player in your page logic (which would simply call destroy and re-initiate the player, thus providing you a fresh facade).

from indigo-player.

stoicbuddha avatar stoicbuddha commented on August 15, 2024

The reason I am doing it from the module, is that the module is used for password wall functionality. If they know the password, they get to see the video.

For security reasons, we don't immediately make the proper m3u8 available, so we load in a generic trailer we have until we get the proper m3u8 after verifying the password.

Having this at the page level would break the encapsulation of the modules. I could make a window-scoped function that does the player redraw, but I'm also now realizing that IndigoPlayer is available via window. So I think I can redraw from within the module; I'll test and let you know.

from indigo-player.

matvp91 avatar matvp91 commented on August 15, 2024

I remember we quickly discussed this in a different topic, and it makes me wonder, is there any reason why you would want to have the password confirmation part of the player & not part of the page?

IMO, this would fit your needs best:

  • Request a password (by an input field).
  • Check the password on your backend, when it matches, provide the playback URL. (Or, not secure at all, but have it match client-side before you provide the playback URL).
  • Start the player with the playback URL (by calling IndigoPlayer.init).

If I'm missing something, I'm sorry, it's been a while since we had this conversation. :)

from indigo-player.

stoicbuddha avatar stoicbuddha commented on August 15, 2024

We will be setting up a JS embed for the player, so we won't have access to the pages it is on.

What I currently do is hide the main ui (.ig-ui) and create an overlay with an input on top of the player. Once you submit the password, it checks it against our API and if the API sends back the proper response with a new source, I destroy the current player and reload it without the password plugin active.

from indigo-player.

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.