Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Help Wanted 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:
    177
    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.
     
unityunity