Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Weird video player behaviour in urls?

Discussion in 'Web' started by unity_8I_suMy7c9iU0g, Apr 2, 2024.

  1. unity_8I_suMy7c9iU0g

    unity_8I_suMy7c9iU0g

    Joined:
    May 29, 2020
    Posts:
    27
    Unity version - 2022.3.7f1

    I got a script set up to set video player url. It combines the websites host name (ex. youtube.com) and the path to a video (ex. /videos/example.mp4). But for some odd reason, when Play() function is used, it takes the current page's url on which the game is located (ex. youtube.com/games/unityWeb) and combines the set url with it (so it becomes youtube.com/games/unityWeb/youtube.com/videos/example.mp4)

    I'm not sure if this is an intended behaviour, if it is, how can i prevent url from being edited like this?

    I'm sure it's not the script's fault, as it logs the url in the line right above the Play() function
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,616
    I‘d still like to see the script. ;)
     
  3. unity_8I_suMy7c9iU0g

    unity_8I_suMy7c9iU0g

    Joined:
    May 29, 2020
    Posts:
    27
    Code (CSharp):
    1. public class VideoOverlay : MonoBehaviour
    2. {
    3.     [SerializeField]
    4.     VideoPlayer player;
    5.     [SerializeField]
    6.     GameObject videoPopup;
    7.  
    8.     [DllImport("__Internal")]
    9.     private static extern string GetHost();
    10.  
    11.     string url;
    12.     [SerializeField]
    13.     string videoUrl;
    14.  
    15.     void Awake()
    16.     {
    17.         url = "youtube.com";
    18.  
    19.         /*
    20.         host url is taken with this .jslib plugin:
    21.             var plugin = {
    22.                 GetHost: function () {
    23.                     var data = window.top.location.hostname;;
    24.                     var bufferSize = lengthBytesUTF8(data) + 1;
    25.                     var buffer = _malloc(bufferSize);
    26.                     stringToUTF8(data, buffer, bufferSize);
    27.                     return buffer;
    28.                 }
    29.             };
    30.  
    31.             mergeInto(LibraryManager.library, plugin);
    32.         */
    33. #if !UNITY_EDITOR
    34.             url = GetHost();
    35. #endif
    36.     }
    37.  
    38.     void OpenOverlay() //Called by a button
    39.     {
    40.         videoPopup.SetActive(true);
    41.  
    42.         Debug.Log(videoUrl);
    43.         Debug.Log(url);
    44.         player.url = url + videoUrl;
    45.     }
    46.  
    47.     void Play() //Called by a button
    48.     {
    49.         Debug.Log(player.url);
    50.  
    51.         player.Stop();
    52.         player.Play();
    53.     }
    54. }
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,616
    URLs usually begin with „https://„
    perhaps that‘s what‘s missing here?
     
  5. unity_8I_suMy7c9iU0g

    unity_8I_suMy7c9iU0g

    Joined:
    May 29, 2020
    Posts:
    27
    Oh, that's a silly mistake.

    Thank you!