Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Video Player with Auth Token

Discussion in 'Audio & Video' started by JamesCitu, Jan 25, 2022.

  1. JamesCitu

    JamesCitu

    Joined:
    Feb 6, 2017
    Posts:
    3
    When a Video Player attempts to read from a URL, is it possible to set the Authorization Token in a Header?

    I've found a Basic username:password combination for example HTTP://username:password@example.com does not seem to be implemented.

    The video I want to access must be stored on a secure server, is there any way around this issue?
     
  2. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Unfortunately, you can't do it directly in the VideoPlayer. What you need to do is use an UnityWebRequest and SetRequestHeader. When the file has finished downloading, you can then set the VideoPlayer.url to the downloaded file path like this.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Video;
    3.  
    4. public class SetUrlScript : MonoBehaviour
    5. {
    6.     public VideoPlayer player;
    7.     public string fileName;
    8.  
    9.     void Start()
    10.     {
    11.         player.url = Application.streamingAssetsPath + "/" + fileName;
    12.         player.Play();
    13.     }
    14. }
    15.  
    I added your feedback for this feature on our product board.
     
  3. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,688
    Is there any update on this @The_Island ?
    Seems odd that in 2022, there is no way to provide a secure URL endpoint for the Video Stream via URL, even having webrequest overrides to be able to customise it.

    Is there truly no way to use secure URL's that require authentication with the VideoPlayer component?
     
  4. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    The reason we can't implement this is the same reason we can't tell the amount of buffering. Most platforms don't provide it. We are highly dependent on platform-specific SDKs to get hardware accelerated decoders, parser and demuxer. And for some reason, some platforms didn't think providing authentication and buffering info was necessary. A half-baked solution would be to implement half of them and just say they are unsupported on the other platform. But it is rarely well received because Unity tries to be as much platform agnostic as possible.

    Our plan is to remove these dependencies and only keep the decoders. Unfortunately, we will have to redo some of the tools ourselves, but we think it is the best long-term solution. The advantage of this is it would be open source, in c#, and you would have access to the low-level tool.
     
    Last edited: Aug 2, 2022
  5. dhindman

    dhindman

    Joined:
    Jan 28, 2016
    Posts:
    17