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
I‘d still like to see the script.
public class VideoOverlay : MonoBehaviour
{
[SerializeField]
VideoPlayer player;
[SerializeField]
GameObject videoPopup;
[DllImport("__Internal")]
private static extern string GetHost();
string url;
[SerializeField]
string videoUrl;
void Awake()
{
url = "youtube.com";
/*
host url is taken with this .jslib plugin:
var plugin = {
GetHost: function () {
var data = window.top.location.hostname;;
var bufferSize = lengthBytesUTF8(data) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(data, buffer, bufferSize);
return buffer;
}
};
mergeInto(LibraryManager.library, plugin);
*/
#if !UNITY_EDITOR
url = GetHost();
#endif
}
void OpenOverlay() //Called by a button
{
videoPopup.SetActive(true);
Debug.Log(videoUrl);
Debug.Log(url);
player.url = url + videoUrl;
}
void Play() //Called by a button
{
Debug.Log(player.url);
player.Stop();
player.Play();
}
}
URLs usually begin with „https://„
perhaps that‘s what‘s missing here?
2 Likes
Oh, that’s a silly mistake.
Thank you!