p2p-media-loader icon indicating copy to clipboard operation
p2p-media-loader copied to clipboard

JWPlayer HLSJS Provider

Open Denoder opened this issue 3 years ago • 25 comments

I have made a github repository for the jwplayer provider, you can find it here:

github: https://github.com/Teranode/jw-provider

cdn: https://cdn.jsdelivr.net/gh/teranode/[email protected]/provider.hlsjs.js

This features the full hls.js API support rather than the limited scope of functions directed by the original jwplayer provider. So you can configure all of what hls.js uses.

This also works with the external hls.js file, but can also use the internal one provided by jwplayer

Installation: append the cdn (or your own self-hosted copy) "before" the jwplayer file (might work after too but to be on the safe side load it before).

afterwards you will condifure p2pml (example):

const iid = setInterval(() => {
    if (window.player.hls && window.player.hls.config) {
        clearInterval(iid);
        p2pml.hlsjs.initHlsJsPlayer(window.player.hls)
    }
}, 200)

I'll be providing updates as the jwplayer release schedule increments. This is currently compatible with JWPlayer 8.18.4

Denoder avatar Feb 04 '21 21:02 Denoder

Hello,

I might be doing it wrong. `

<meta charset="UTF-8">

<title>JWPlayer with hls.js engine and P2P demo</title>

<script src="https://cdn.jsdelivr.net/npm/p2p-media-loader-core@latest/build/p2p-media-loader-core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@latest/build/p2p-media-loader-hlsjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/teranode/[email protected]/provider.hlsjs.js"></script>
<script src="https://content.jwplatform.com/libraries/aG3IMhIy.js"></script>


<style>
    #wrapper {
        width: 720px;
        margin-left: auto;
        margin-right: auto;
        display: block;
    }

</style>
<script>

    if (p2pml.hlsjs.Engine.isSupported()) {
        var engine = new p2pml.hlsjs.Engine();

        var player = jwplayer("player");

        player.setup({
            preload: "auto",
            file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8"
        });

        const iid = setInterval(() => {
            console.log(player.hls);
            if (player.hls && player.hls.config) {
                clearInterval(iid);
                p2pml.hlsjs.initHlsJsPlayer(player.hls)
            }
        }, 200);
    } else {
        document.write("Not supported :(");
    }

</script>
`

jhemmmm avatar Feb 05 '21 04:02 jhemmmm

Ops, I was doing it wrong. player.hls.config = { liveSyncDurationCount: 7, loader: engine.createLoaderClass() }

jhemmmm avatar Feb 05 '21 05:02 jhemmmm

Well, there's a problem on this one. When you try to change a quality, It stopped working, it just keeps loading and won't work anymore.

jhemmmm avatar Feb 05 '21 05:02 jhemmmm

player.hls.config = { liveSyncDurationCount: 7, loader: engine.createLoaderClass() }

You can add config through hlsjsConfig when setup player. Using hlsjsConfig will keep default hls config without override like using player.hls.config = { liveSyncDurationCount: 7, loader: engine.createLoaderClass() } Ex:

if (p2pml.hlsjs.Engine.isSupported()) {
    var engine = new p2pml.hlsjs.Engine();

    var player = jwplayer("player");

    player.setup({
        preload: "auto",
        file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8",
        hlsjsConfig: {
            liveSyncDurationCount: 7
            loader: engine.createLoaderClass(),
        },
    });

    const iid = setInterval(() => {
        console.log(player.hls);
        if (player.hls && player.hls.config) {
            clearInterval(iid);
            p2pml.hlsjs.initHlsJsPlayer(player.hls)
        }
    }, 200);
} else {
    document.write("Not supported :(");
}

hoangvietfreelancer avatar Feb 05 '21 06:02 hoangvietfreelancer

Well, there's a problem on this one. When you try to change a quality, It stopped working, it just keeps loading and won't work anymore.

In my case(my test stream), there is no problem when change quality. Had you tried another stream?

hoangvietfreelancer avatar Feb 05 '21 06:02 hoangvietfreelancer

player.hls.config = { liveSyncDurationCount: 7, loader: engine.createLoaderClass() }

You can add config through hlsjsConfig when setup player. Using hlsjsConfig will keep default hls config without override like using player.hls.config = { liveSyncDurationCount: 7, loader: engine.createLoaderClass() } Ex:

if (p2pml.hlsjs.Engine.isSupported()) {
    var engine = new p2pml.hlsjs.Engine();

    var player = jwplayer("player");

    player.setup({
        preload: "auto",
        file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8",
        hlsjsConfig: {
            liveSyncDurationCount: 7
            loader: engine.createLoaderClass(),
        },
    });

    const iid = setInterval(() => {
        console.log(player.hls);
        if (player.hls && player.hls.config) {
            clearInterval(iid);
            p2pml.hlsjs.initHlsJsPlayer(player.hls)
        }
    }, 200);
} else {
    document.write("Not supported :(");
}

doing this fixed the change quality change. not really sure why but thanks. :)

jhemmmm avatar Feb 05 '21 06:02 jhemmmm

player.hls.config = { liveSyncDurationCount: 7, loader: engine.createLoaderClass() }

You can add config through hlsjsConfig when setup player. Using hlsjsConfig will keep default hls config without override like using player.hls.config = { liveSyncDurationCount: 7, loader: engine.createLoaderClass() } Ex:

if (p2pml.hlsjs.Engine.isSupported()) {
    var engine = new p2pml.hlsjs.Engine();

    var player = jwplayer("player");

    player.setup({
        preload: "auto",
        file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8",
        hlsjsConfig: {
            liveSyncDurationCount: 7
            loader: engine.createLoaderClass(),
        },
    });

    const iid = setInterval(() => {
        console.log(player.hls);
        if (player.hls && player.hls.config) {
            clearInterval(iid);
            p2pml.hlsjs.initHlsJsPlayer(player.hls)
        }
    }, 200);
} else {
    document.write("Not supported :(");
}

doing this fixed the change quality change. not really sure why but thanks. :)

right sorry about that i forgot to say that you needed to add this to the player setup:

        hlsjsConfig: {
            liveSyncDurationCount: 7
            loader: engine.createLoaderClass(),
        },

Denoder avatar Feb 05 '21 18:02 Denoder

@Teranode can you give some optimize setting for VOD stream with JWPlayer ? Related: https://github.com/Novage/p2p-media-loader/blob/master/FAQ.md#how-to-achieve-better-p2p-ratio-for-vod-streams

jazz1611 avatar Feb 08 '21 08:02 jazz1611

@Teranode hello, i see your new HLS provider v2 but if run P2P loader with v8.19.0 will error code 232000 "Unknown manifest loading error.", i can run normal jwplayer v8.19.0 without P2P loader

jazz1611 avatar Mar 02 '21 09:03 jazz1611

@Teranode hello, i see your new HLS provider v2 but if run P2P loader with v8.19.0 will error code 232000 "Unknown manifest loading error.", i can run normal jwplayer v8.19.0 without P2P loader

@jazz1611 you have to use https://cdn.jsdelivr.net/npm/hls.js@latest now, not sure why I have to debug it at some other time, but the entire codebase changed so i need to look through things.

Denoder avatar Mar 02 '21 15:03 Denoder

It also might have to do with: https://github.com/Novage/p2p-media-loader/pull/178

Denoder avatar Mar 02 '21 17:03 Denoder

I've provided a release for the fix in the pull request, feel free to use that: https://github.com/Teranode/jw-provider/releases/tag/0.0.3

Denoder avatar Mar 02 '21 18:03 Denoder

I've provided a release for the fix in the pull request, feel free to use that: https://github.com/Teranode/jw-provider/releases/tag/0.0.3

hello,

your update is working with jwplayer v8.19.0 + P2P loader. also can you fix this error in Firefox browser? Screenshot_4

jazz1611 avatar Mar 03 '21 06:03 jazz1611

If anyone's reading this, can anyone run debug mode and tell me if it's working.

Denoder avatar Mar 08 '21 18:03 Denoder

@Teranode It's not working due to JWPlayer 8.19.0 Provider(maybe hls.js) adding this rangeStart: 0 and rangeEnd: 0 to xhr instead of nothing(undefined) So this line https://github.com/Novage/p2p-media-loader/blob/85adce9b0edbc00dfa073321d93a61590af3afc8/p2p-media-loader-hlsjs/lib/hlsjs-loader.ts#L41 should be:

((context.rangeStart == undefined) || (context.rangeEnd == undefined)) || (context.rangeStart === 0 && context.rangeEnd === 0)

I haven't tested on other player and hls.js so I won't make a pull request now

hoangvietfreelancer avatar Mar 09 '21 11:03 hoangvietfreelancer

Thanks m8, it works for me on flowplayer and jwplayer so ill release an update.

Denoder avatar Mar 09 '21 20:03 Denoder

Thanks m8, it works for me on flowplayer and jwplayer so ill release an update.

hello, do i need //cdn.jsdelivr.net/npm/hls.js@latest in jwplayer setting when run your script provider.hlsjs v4, p2p-media-loader-hlsjs.min.js ?

jazz1611 avatar Mar 10 '21 16:03 jazz1611

@jazz1611 You can add it if you want but it's not necessary

hoangvietfreelancer avatar Mar 10 '21 16:03 hoangvietfreelancer

@jazz1611 You can add it if you want but it's not necessary

hello, okay. without that hls.js the player still work at normal but this issues still not fixed.

I've provided a release for the fix in the pull request, feel free to use that: https://github.com/Teranode/jw-provider/releases/tag/0.0.3

hello,

your update is working with jwplayer v8.19.0 + P2P loader. also can you fix this error in Firefox browser? Screenshot_4

jazz1611 avatar Mar 10 '21 16:03 jazz1611

Using this provider seems to ignore the below settings. requiredSegmentsPriority

afdah avatar Apr 06 '21 13:04 afdah

Well, there's a problem on this one. When you try to change a quality, It stopped working, it just keeps loading and won't work anymore.

In my case(my test stream), there is no problem when change quality. Had you tried another stream? Hi @hoangvietfreelancer hoangvietfreelancer Some devices not support, the player can't initial. How to fix ? } else { document.write("Not supported :("); // How to load native player if not supported p2p ? }

alexwuan96 avatar Apr 29 '21 21:04 alexwuan96

You can using native player if not support using this:


if (p2pml.hlsjs.Engine.isSupported()) {
    var engine = new p2pml.hlsjs.Engine();

    var player = jwplayer("player");

    player.setup({
        preload: "auto",
        file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8",
        hlsjsConfig: {
            liveSyncDurationCount: 7
            loader: engine.createLoaderClass(),
        },
    });

    const iid = setInterval(() => {
        console.log(player.hls);
        if (player.hls && player.hls.config) {
            clearInterval(iid);
            p2pml.hlsjs.initHlsJsPlayer(player.hls)
        }
    }, 200);
} else {
    var player = jwplayer("player");

    player.setup({
        preload: "auto",
        file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8",
    });
}

Simply if it not support just init the player like normal

hoangvietfreelancer avatar Apr 30 '21 16:04 hoangvietfreelancer

the p2p lib and your script still working in jwplayer?

jazz1611 avatar Jun 15 '21 16:06 jazz1611

@Teranode hello, i just tested again. p2p lib and your script working with jwplayer v8.20.2. in Firefox can play with alot client p2p but in Chrome i open 2 tab with same URL but no stream from p2p. what wrong with Chrome ?

jazz1611 avatar Jul 12 '21 08:07 jazz1611

You can using native player if not support using this:


if (p2pml.hlsjs.Engine.isSupported()) {
    var engine = new p2pml.hlsjs.Engine();

    var player = jwplayer("player");

    player.setup({
        preload: "auto",
        file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8",
        hlsjsConfig: {
            liveSyncDurationCount: 7
            loader: engine.createLoaderClass(),
        },
    });

    const iid = setInterval(() => {
        console.log(player.hls);
        if (player.hls && player.hls.config) {
            clearInterval(iid);
            p2pml.hlsjs.initHlsJsPlayer(player.hls)
        }
    }, 200);
} else {
    var player = jwplayer("player");

    player.setup({
        preload: "auto",
        file: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8",
    });
}

Simply if it not support just init the player like normal

Thank for your template. I was used it but the video loading and warn image Uploading image.png… [email protected]:1 [warn] > playback not stuck anymore @52.014543, after 2736ms JW Player Warning 330000. JW Player Warning 334001 what are problems ?

pedro0606 avatar Sep 27 '21 01:09 pedro0606