Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Video player fails to play signed urls #320

Closed
pedramp20 opened this issue Oct 12, 2021 · 8 comments
Closed

Video player fails to play signed urls #320

pedramp20 opened this issue Oct 12, 2021 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@pedramp20
Copy link

pedramp20 commented Oct 12, 2021

Describe the bug
When signed url is passed to the suggested video player (video.js), it fails with:
No compatible source was found for this media.

<VideoPlayer
    autoplay
    controls
    sources={[{
      src: 'https://xxxxxxxx.cloudfront.net/{path}/{path.m3u8}{token}',
      type: 'application/x-mpegURL'
    }]}
@pedramp20 pedramp20 changed the title setup video player stuck at adding video js package video player setup gets stuck at adding video js package Oct 12, 2021
@nathanagez
Copy link
Collaborator

Hi @pedramp20, please can you provide the VideoPlayer component source code ?

@nathanagez nathanagez self-assigned this Oct 12, 2021
@nathanagez nathanagez added the question Further information is requested label Oct 12, 2021
@pedramp20
Copy link
Author

pedramp20 commented Oct 12, 2021

@nathanagez I actually realised that for signed urls the right way of passing source and token is as follows:

<VideoPlayer
    autoplay
    controls
    sources={[{
      src: 'https://xxxxxxxx.cloudfront.net/{path}/{path.m3u8}',
      type: 'application/x-mpegURL'
    }]}
    token={token}
  />

However, now I am getting the following error:

VIDEOJS: WARN: Problem encountered with playlist 0-http://localhost:3000/undefined. Trying again since it is the only playlist.

Here is the videoplayer component code:

import React from 'react';
import videojs from 'video.js';
import 'video.js/dist/video-js.css';


export default class VideoPlayer extends React.Component {
  componentDidMount() {
    this.player = videojs(this.videoNode, this.props);
  }

  componentWillUnmount() {
    if (this.player) {
      this.player.dispose();
    }
  }

  render() {
    return (
      <div>
        <div data-vjs-player>
          <video ref={(node) => { this.videoNode = node; }} className="video-js"></video>
        </div>
      </div>
    );
  }
}

Ps. Since video setup got stuck in adding video js to package.json, I manually added the package and called setup again.

@pedramp20 pedramp20 changed the title video player setup gets stuck at adding video js package Video player fails to play signed urls Oct 12, 2021
@nathanagez
Copy link
Collaborator

@nathanagez I actually realised that for signed urls the right way of passing source and token is as follows:

<VideoPlayer
          autoplay
          controls
          sources={[{
            src: 'https://xxxxxxxx.cloudfront.net/{path}/{path.m3u8}{token}',
            type: 'application/x-mpegURL'
          }]}
          token={token}
        />

However, now I am getting the following error:

VIDEOJS: WARN: Problem encountered with playlist 0-http://localhost:3000/undefined. Trying again since it is the only playlist.

@pedramp20 token have to be append to each requests, I'll provide you the correct snippet of code but I'm not in front of my computer FTM.
I'll ping you ASAP.

@nathanagez nathanagez added bug Something isn't working and removed question Further information is requested labels Oct 12, 2021
@pedramp20
Copy link
Author

pedramp20 commented Oct 12, 2021

@nathanagez do you mean this? https://gist.github.com/wizage/1523dd1f6928e0d852042e6adbaf54cd
It didn't work for me

@pedramp20
Copy link
Author

pedramp20 commented Oct 12, 2021

I resolved the issue using React Player. if anyone else is having problem with playing HLS with credentials. here is how to play it with react player:

<ReactPlayer
    url={source} //this your source url WITHOUT APPENDED TOKEN: https://xxxxxxxx.cloudfront.net/{path}/{path.m3u8}
    controls={true}
    config={{
      file: {
        hlsOptions: {
          xhrSetup: function xhrSetup(xhr, url) {
            xhr.setRequestHeader(
              "Access-Control-Allow-Headers",
              "Content-Type, Accept, X-Requested-With"
            );
            xhr.setRequestHeader(
              "Access-Control-Allow-Origin",
              "*"
            );
            xhr.setRequestHeader(
              "Access-Control-Allow-Credentials",
              "true"
            );
            xhr.open('GET', url + token); // this is your token: ?Policy=foo&Key-Pair-Id=bar&Signature=foobar
          }
        }
      }
    }}
  />

@nathanagez
Copy link
Collaborator

nathanagez commented Oct 12, 2021

https://gist.github.com/wizage/1523dd1f6928e0d852042e6adbaf54cd

Yes but instead of using Hls use Vhs since Hls is deprecated.

import React from 'react';
import videojs from 'video.js';
import 'video.js/dist/video-js.css';


export default class VideoPlayer extends React.Component {
  componentDidMount() {
    videojs.Vhs.xhr.beforeRequest = (function (options) {
      options.uri = `${options.uri}${this.props.token}`;
      return options;
    }).bind(this);
    this.player = videojs(this.videoNode, this.props);
  }

  componentWillUnmount() {
    if (this.player) {
      this.player.dispose();
    }
  }

  render() {
    return (
      <div>
        <div data-vjs-player>
          <video ref={(node) => { this.videoNode = node; }} className="video-js"></video>
        </div>
      </div>
    );
  }
}

@nathanagez nathanagez added question Further information is requested and removed bug Something isn't working labels Oct 12, 2021
@pedramp20
Copy link
Author

pedramp20 commented Oct 15, 2021

@nathanagez I am having problem playing videos using both react player and video js on iOS (Safari). Is there a specific config that needs to be set? I have already tried this but didn't work

{
  html5: {
    hls: {
      overrideNative: overrideNative
    },
    nativeVideoTracks: !overrideNative,
    nativeAudioTracks: !overrideNative,
    nativeTextTracks: !overrideNative
  }
}

@pedramp20
Copy link
Author

#323

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants