HEADJACK
Search Results for

    Show / Hide Table of Contents

    Class App

    Namespace: Headjack

    This static class is the starting point for all the functionality of the Headjack SDK

    Fields

    camera

    Transform of headjack's camera

    Declaration
    public static Transform camera
    Field Value
    Type Description
    Transform

    Transform in the middle of both eyes

    Remarks
    Note

    GameObject associated with this Transform does not necessarily have a Camera component

    CameraParent

    VR Camera GameObject

    Declaration
    public static GameObject CameraParent
    Field Value
    Type Description
    GameObject

    GameObject of the active VR Camera

    Remarks
    Note

    For Camera Position or Rotation, please use camera. For Disabling or Enabling the Camera, please use SetCamera(Boolean, Boolean)

    Crosshair

    Headjack's default crosshiar

    Declaration
    public static Crosshair Crosshair
    Field Value
    Type Description
    Crosshair

    Crosshair class with all settings

    CrosshairHit

    All raycast information about what the user is looking at

    Declaration
    public static RaycastHit CrosshairHit
    Field Value
    Type Description
    RaycastHit

    RaycastHit information

    Remarks
    Note

    Use IsCrosshairHit(Collider, App.RaycastSource) to quickly check if an certain object is being looked at

    Examples
    public float DistanceToObjectLookingAt
    {
        return App.CrosshairHit.distance;
    }

    CurrentProject

    The id of the project that is currently being played

    Declaration
    public static string CurrentProject
    Field Value
    Type Description
    System.String

    The id of the project that is currently being played

    CurrentVideo

    The id of the video that is currently being played

    Declaration
    public static string CurrentVideo
    Field Value
    Type Description
    System.String

    The id of the video that is currently being played

    Data

    App metadata

    Declaration
    public static AppDataStruct Data
    Field Value
    Type Description
    AppDataStruct

    LaserHit

    All raycast information about what the user is pointing at with the motion controller

    Declaration
    public static RaycastHit LaserHit
    Field Value
    Type Description
    RaycastHit

    RaycastHit information

    Remarks
    Note

    Use IsCrosshairHit(Collider, App.RaycastSource) to quickly check if an certain object is being aimed at

    Examples
    public Vector3 AimingLocation
    {
        return App.LaserHit.point;
    }

    LocalVersionTracking

    Locally stored files/media version data

    Declaration
    public static LocalVersionTracking LocalVersionTracking
    Field Value
    Type Description
    LocalVersionTracking

    NO_CATEGORY

    Pass this string to GetProjects(String, Int32, Int32) to get all projects with explicitly no category set

    Declaration
    public const string NO_CATEGORY = "NO_CATEGORY"
    Field Value
    Type Description
    System.String

    Player

    The video player instance

    Declaration
    public static VideoPlayerBase Player
    Field Value
    Type Description
    VideoPlayerBase

    The video player instance with it's own functions and variables, see VideoPlayerBase

    TouchHit

    All raycast information about what the user is touching on screen (Cardboard)

    Declaration
    public static RaycastHit TouchHit
    Field Value
    Type Description
    RaycastHit

    RaycastHit information

    Remarks
    Note

    Use IsCrosshairHit(Collider, App.RaycastSource) to quickly check if an certain object is being touched

    Examples
    public GameObject ObjectTouching
    {
        return App.TouchHit.collider.gameObject;
    }

    Properties

    CameraScale

    Changing the camera scale will Shrink or Enlarge the world around you. Useful if an interface needs to get just a little bigger or smaller

    Declaration
    public static float CameraScale { get; set; }
    Property Value
    Type Description
    System.Single

    Returns the current camera scale

    Remarks
    Note

    Will clamp between 0.01 and 100

    Examples
    // Shrink or grow with the arrow keys
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            App.CameraScale+=1;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            App.CameraScale-=1;
        }
    }

    CinemaConnected

    Returns whether the Cinema server connection is live/online

    Declaration
    public static bool CinemaConnected { get; }
    Property Value
    Type Description
    System.Boolean

    True if Cinema server connection is live, otherwise false

    Examples
    // Enable a gameobject only if Cinema server connection is online
    public void ToggleGameObjectOnCinemaConnect(GameObject toggleThis) {
        toggleThis.SetActive(App.CinemaConnected);
    }

    CinemaSupported

    Returns whether the current template supports Cinema, and if this app is allowed to use it

    Declaration
    public static bool CinemaSupported { get; }
    Property Value
    Type Description
    System.Boolean

    True if Cinema is supported and allowed

    Remarks
    Note

    Only valid after initialization

    Examples
    // Enable a gameobject only if Cinema is allowed
    public void ToggleGameObjectOnCinemaSupported(GameObject toggleThis) {
        toggleThis.SetActive(App.CinemaSupported);
    }

    CurrentPlatform

    Checks the current platform

    Declaration
    public static App.VRPlatform CurrentPlatform { get; }
    Property Value
    Type Description
    App.VRPlatform

    The current platform Headjack is running on

    Remarks
    Note

    For testing: You can change this in the Headjack settings window

    Examples
    void LogCurrentPlatform()
    {
    #if UNITY_ANDROID
    if (App.CurrentPlatform == App.VRPlatform.Oculus)
    {
        Debug.Log("This app is running on Oculus Go/Quest");
    }
    if (App.CurrentPlatform == App.VRPlatform.Cardboard)
    {
        Debug.Log("This app is running on Android Cardboard");
    }
    #endif
    #if UNITY_IOS
    if (App.CurrentPlatform == App.VRPlatform.Cardboard)
    {
        Debug.Log("This app is running on iOS Cardboard");
    }
    #endif
    #if UNITY_STANDALONE
    if (App.CurrentPlatform == App.VRPlatform.Oculus)
    {
        Debug.Log("This app is running on Oculus Rift");
    }
    if (App.CurrentPlatform == App.VRPlatform.OpenVR)
    {
        Debug.Log("This app is running on HTC Vive");
    }
    #endif
    }

    EnableOVRPlatformMenu

    If true, the back button on the Oculus Mobile platforms will open the Oculus Platform Menu. You can disable this when the user goes out of the menu and in a video.

    Declaration
    public static bool EnableOVRPlatformMenu { get; set; }
    Property Value
    Type Description
    System.Boolean

    If the platform menu is enabled

    Remarks
    Note

    Oculus Mobile platforms only

    Warning

    If disabled, make sure that the back button will always bring you back to the "upper menu" where it is enabled. The user must always be able to reach the Oculus platform menu by keep pressing the back button.

    Examples
    // Disable when playing a video
    void PlayVideo(string id)
    {
        App.EnableOVRPlatformMenu=false;
        App.Play(id, true, true, null);
    }

    ForceConservativeVideoSupport

    Force conservative video downloads/streams, where the maximum resolution is capped at UHD (not recommended).

    Declaration
    public static bool ForceConservativeVideoSupport { get; set; }
    Property Value
    Type Description
    System.Boolean

    IsPublished

    Returns whether app has published state set in Headjack

    Declaration
    public static bool IsPublished { get; }
    Property Value
    Type Description
    System.Boolean

    True if the app is set to published in Headjack (and is therefore available to use)

    Remarks
    Warning

    If an app is set to unpublished in Headjack, the app will receive no media information, like projects, videos or thumbnails.

    Examples
    // Show message to the user when app is unpublished
    public void MessageUserUnpublished() 
    {
        if (!Headjack.App.IsPublished)
        {
            Headjack.App.ShowMessage("This app is not published and is currently unavailable!", 5);
        }
    }

    IsVRMode

    Returns whether app is currently running in VR mode (e.g. stereo display), or not (e.g. fullscreen cardboard menu)

    Declaration
    public static bool IsVRMode { get; }
    Property Value
    Type Description
    System.Boolean

    True if the app is currently running in VR mode

    Examples
    // Show message to the user when not in VR mode
    public void MessageUserNotVR() 
    {
        if (!Headjack.App.IsVRMode)
        {
            Headjack.App.ShowMessage("You are currently not in VR mode", 5);
        }
    }

    MonoSphereRadius

    The radius (in meters) of the virtual sphere where monoscopic equirectangular video content is projected onto.

    Declaration
    public static float MonoSphereRadius { get; set; }
    Property Value
    Type Description
    System.Single

    Returns the current mono sphere radius

    Remarks
    Note

    The default radius of 10 meters is comfortable as it matches the focal length of most current VR headset optics

    Examples
    void SetMonoSphere(bool indoorVideo)
    {
        if (indoorVideo) {
            App.MonoSphereRadius = 2f;
        } else {
            App.MonoSphereRadius = 10f;
        }
    }

    PauseVideoOnFocusLoss

    Whether to automatically pause the video when the app loses focus, for instance on Android when the on-screen keyboard is shown. Default is to pause video on focus loss (i.e. true).

    Note

    Changing this does not affect video pausing on Oculus platforms when OS menu is overlayed.

    Declaration
    public static bool PauseVideoOnFocusLoss { get; set; }
    Property Value
    Type Description
    System.Boolean

    ShowCrosshair

    Headjack's crosshair

    Declaration
    public static bool ShowCrosshair { get; set; }
    Property Value
    Type Description
    System.Boolean

    True if the crosshair is currently visible

    Examples
    public void HideCrosshair() 
    {
        App.ShowCrosshair=false;
    }

    UseAndroidInternalStorage

    If true, downloaded data (including media) is stored on less accessible internal app storage on Android. By default, the app data is stored in app-specific storage that is still accessible through e.g. USB file access.

    Declaration
    public static bool UseAndroidInternalStorage { get; set; }
    Property Value
    Type Description
    System.Boolean

    Whether app internal storage is used on Android

    Remarks
    Note

    Can only be set before the app is initialized with Initialize(OnEnd, Boolean, Boolean, String, String)!

    Note

    Enabling internal app storage on Android disables the background downloading functionality on that platform, due to file permission limitations.

    Examples
    // use app internal storage on Android
    App.UseAndroidInternalStorage = true;
    App.Initialize(OnInitialized);

    Methods

    CanBeDownloaded(String)

    Check if a project's contents can be downloaded.

    Declaration
    public static bool CanBeDownloaded(string projectId)
    Parameters
    Type Name Description
    System.String projectId

    Project id

    Returns
    Type Description
    System.Boolean

    true if the project can be downloaded

    Examples
    public bool DownloadIfPossible(ProjectId)
    {
        if(App.CanBeDownloaded(ProjectId))
        {
            App.Download(ProjectId);
            return true;
        }else{
            return false;
        }
    }

    Cancel(String)

    Cancel an active download

    Declaration
    public static void Cancel(string ProjectId)
    Parameters
    Type Name Description
    System.String ProjectId

    Project download to cancel

    Examples
    public void CancelAllDownloads()
    {
        string[] projects = App.GetProjects();
        foreach (string project in projects)
        {
            App.Cancel(project);
        }
    }

    Delete(String)

    Delete all local files of a project

    Declaration
    public static void Delete(string ProjectId)
    Parameters
    Type Name Description
    System.String ProjectId

    The project id

    Examples
    public void DeleteAllProjects()
    {
        string[] projects = App.GetProjects();
        foreach (string project in projects)
        {
            App.Delete(project);
        }
    }

    DestroyVideoPlayer()

    Destroys the active videoplayer

    Declaration
    public static void DestroyVideoPlayer()
    Examples
    GameObject menuObject;
    public void BackToMenu()
    {
    App.DestroyVideoPlayer();
    menuObject.SetActive(true);
    }

    Download(String, Boolean, OnEnd)

    Download all files in a project

    Declaration
    public static void Download(string ProjectId, bool WifiOnly = false, OnEnd onEnd = null)
    Parameters
    Type Name Description
    System.String ProjectId

    The project you want to download

    System.Boolean WifiOnly

    Only download when connected to Wifi

    OnEnd onEnd

    Will be called when the download is finished

    Remarks
    Note

    Will call onEnd with (false,"NoWifi") if WifiOnly is true and there is no wifi connection

    Examples
    public string id;
    public void DownloadAndPlayFirstVideo()
    {
        id = App.GetProjects()[0];
        App.Download(id, true, OnDownloaded);
    }
    public void OnDownloaded(bool succes, string error)
    {
        if (succes)
        {
            App.Play(id, false, false, null);
        }else{
        Debug.Log(error);
    }
    }

    DownloadAllTextures(OnEnd, Boolean, OnImageProgress)

    Download and import all textures

    Declaration
    public static void DownloadAllTextures(OnEnd OnLoaded = null, bool GenerateMipmaps = true, OnImageProgress progressListener = null)
    Parameters
    Type Name Description
    OnEnd OnLoaded

    Will be called when done

    System.Boolean GenerateMipmaps

    Automatically generate mipmaps after importing

    OnImageProgress progressListener

    Will be called with current progress information

    Remarks
    Note

    Will only download textures once, or when they are updated on the server

    Examples
    public void LoadTextures()
    {
        App.LoadAllTextures(OnReady);
    }
    public void OnReady(bool Succes)
    {
        if (Succes)
        {
            print("Got all textures!");
        } else
        {
            print("Could not load the textures");
        }
    }

    DownloadSingleMedia(String, Boolean, OnEnd)

    Download a single media item (e.g. media from a custom variable)

    Declaration
    public static void DownloadSingleMedia(string mediaId, bool wifiOnly, OnEnd onEnd = null)
    Parameters
    Type Name Description
    System.String mediaId

    ID of media item that will be downloaded

    System.Boolean wifiOnly

    Set to true to only download over wifi and not use mobile data

    OnEnd onEnd

    This delegate is called when the download has finished (or failed)

    Remarks
    Note

    mediaId must be a media item either from a custom variable or a thumbnail of a project or category used in the app

    Note

    Videos in projects are special entries on the server and do not have a media ID

    Note

    onEnd returns bool indicating success of download and a string containing error message if unsuccessful

    Examples
    // download a specific custom media variable
    public void DownloadFirstExtraMedia()
    {
        App.DownloadSingleMedia(Headjack.CustomVariables.GetVariable<string>("a_media_variable"), false,
            delegate (bool success, string error)
            {
                if (success)
                {
                    Debug.Log("Downloaded a_media_variable media");
                }
                else
                {
                    Debug.LogError("Downloading a_media_variable media failed!");
                }
            });
    }

    DownLoadSingleTexture(String, OnEnd, Boolean, Boolean)

    Download and import a texture

    Declaration
    public static void DownLoadSingleTexture(string Id, OnEnd OnLoaded = null, bool UnscaledSlow = false, bool GenerateMipmaps = true)
    Parameters
    Type Name Description
    System.String Id

    The media id or project of the texture/thumbnail

    OnEnd OnLoaded

    Will be called when done

    System.Boolean UnscaledSlow

    Get the raw image from the server

    System.Boolean GenerateMipmaps

    Automatically generate mipmaps after importing

    Remarks
    Note

    Will only download the texture once, or when it is updated on the server

    Warning

    Headjack automatically converts images, these have a maximum resolution of 1024x1024. You can download and import the original file by setting "UnscaledSlow" to true. However, keep in mind that this can generate CPU spikes and some devices do not support textures higher then 2048x2048.

    Examples
    public void DownLoadSingleTexture()
    {
        App.LoadAllTextures("12345678",OnReady);
    }
    public void OnReady(bool Succes)
    {
        if (Succes)
        {
            print("Got the texture!");
        } else
        {
            print("Could not download the texture");
        }
    }

    Fade(Boolean, Single, OnEnd)

    Fade screen to or from black

    Declaration
    public static void Fade(bool ToBlack, float Time = 1F, OnEnd OnFade = null)
    Parameters
    Type Name Description
    System.Boolean ToBlack

    True to fade to black (fade out), false to fade from black (fade in)

    System.Single Time

    Duration of the fade effect in seconds

    OnEnd OnFade

    Event function that gets executed when fade is completed

    Remarks
    Note

    Use this function to hide stutter, by fading to black before heavy loading

    Note

    The parameters of OnFade (bool success, string error) are unused

    Examples
    UnityEngine.GameObject interface;
    // This function fades the screen to black for 1.5 seconds and then disables the 'interface' GameObject
    // Another function has to fade the screen back in, or the screen will remain black
    void FadeOutInterface()
    {
        App.Fade(true, 1.5f, delegate (bool success, string error) {interface.SetActive(false);});
    }

    GetAdditionalMedia()

    Get IDs of extra media items from server

    Declaration
    [Obsolete("Additional media has been superseded by template variables. Please use Headjack.CustomVariables.GetVariable<string>(string variable) instead.")]
    public static List<string> GetAdditionalMedia()
    Returns
    Type Description
    System.Collections.Generic.List<System.String>

    List of ID strings of extra media items as entered on Headjack "Edit app" page

    Remarks
    Note

    Download a media item from this list using DownloadSingleMedia(String, Boolean, OnEnd)

    Note

    Load the downloaded media as texture using GetImage(String, Boolean)

    Note

    Get metadata for media item using GetMediaMetadata(String)

    Examples
    // return number of extra media items
    public int GetNumberOfExtraMedia()
    {
        return App.GetAdditionalMedia().Count;
    }

    GetAppMetadata()

    Get metadata for the app

    Declaration
    public static App.AppMetadata GetAppMetadata()
    Returns
    Type Description
    App.AppMetadata

    App.AppMetadata class containing metadata for app

    Examples
    bool IsMyAppPublished()
    {
        return Headjack.App.GetAppMetadata().Published;               
    }

    GetCategories()

    Get all (sub)category IDs used in this app.

    Declaration
    public static string[] GetCategories()
    Returns
    Type Description
    System.String[]

    a string array containing all category IDs

    GetCategoryMetadata(String)

    Get metadata for category

    Declaration
    public static App.CategoryMetadata GetCategoryMetadata(string categoryId)
    Parameters
    Type Name Description
    System.String categoryId

    ID of category

    Returns
    Type Description
    App.CategoryMetadata

    App.CategoryMetadata class containing metadata for category, or null when invalid category ID

    Examples
    // return a list of all category names
    public List<String> AllCategoryNames
    {
        List<String> names = new List<String>();
        foreach(string id in App.GetCategories())
        {
            names.Add(App.GetCategoryMetadata(id).Name);
        }
        return names;
    }

    GetColor(String, Color)

    Get the app colors, from the server

    Declaration
    [Obsolete("Please use CustomVariables.GetVariable<Color>() instead.")]
    public static Color GetColor(string Key, Color DefaultValue)
    Parameters
    Type Name Description
    System.String Key
    Color DefaultValue
    Returns
    Type Description
    Color

    Returns the color given in Key

    Examples
    public Color GetBackgroundColor(string key)
    {
        return App.GetColor(key,Color.black);
    }

    GetCustomVariable(String)

    Access custom template variables, downloaded from Headjack

    Declaration
    [Obsolete("Please use CustomVariables.GetVariable<string>() instead.")]
    public static string GetCustomVariable(string key)
    Parameters
    Type Name Description
    System.String key

    String key/name identifying the custom variable

    Returns
    Type Description
    System.String

    Returns the string value corresponding to the custom variable key, or null of key does not exist

    Examples
    // Get a Texture object of an additional media item, whose id is passed to this
    // template using a custom variable called "menu_background_image_id"
    public Texture2D getBackgroundTexture()
    {
        return App.GetImage(App.GetCustomVariable("menu_background_image_id"));
    }

    GetCustomVideoParam(String, String, out Int32)

    Get metadata for video associated with project ID

    Declaration
    public static bool GetCustomVideoParam(string id, string paramName, out int paramVal)
    Parameters
    Type Name Description
    System.String id

    Project ID or Video ID to retrieve custom parameter from

    System.String paramName

    Custom video parameter identifier

    System.Int32 paramVal

    Value of custom video parameter

    Returns
    Type Description
    System.Boolean

    Whether parameter with paramName could be retrieved

    Remarks
    Note

    Available video params depends on VideoMetadata.ProjectionType

    Note

    EQUIRECT projection has "FovX" and "FovY" int params for horizontal and vertical field of view

    Note

    FLAT projection has "OrgX" and "OrgY" int params for original video width and height in pixels

    GetDescription(String)

    Get the Description of the given project

    Declaration
    public static string GetDescription(string ProjectId)
    Parameters
    Type Name Description
    System.String ProjectId

    The project id

    Returns
    Type Description
    System.String

    The description of the project with ProjectId, null if the project has no description

    Remarks
    Note

    To get a list with available projects, use GetProjects(String, Int32, Int32)

    Warning

    When using this, make sure to check if the string is not null before using to avoid NullReference exceptions

    Examples
    public string GetFirstDescription()
    {
        string[] ids = App.GetProjects();
        return App.GetDescription(ids[0]);
    }

    GetImage(String, Boolean)

    Get a downloaded texture from te server

    Declaration
    public static Texture2D GetImage(string Id, bool UnscaledSlow = false)
    Parameters
    Type Name Description
    System.String Id

    Project id or media id

    System.Boolean UnscaledSlow

    Get the raw texture

    Returns
    Type Description
    Texture2D

    Texture 2d of given project/media id. Returns null if the media file doesn exists. Returns null if the given project doesn't have a thumbnail attached

    Remarks
    Warning

    When using this, make sure to check if the Texture is not null before using to avoid NullReference errors

    Examples
    public void ApplyTexture(string MediaId)
    {
        GetComponent<MeshRenderer>().material.mainTexture = App.GetImage(MediaId);
    }

    GetMediaDownloadedBytes(String)

    Get the progress of an individual media download in bytes

    Declaration
    public static long GetMediaDownloadedBytes(string MediaId)
    Parameters
    Type Name Description
    System.String MediaId

    The media (by ID) to check

    Returns
    Type Description
    System.Int64

    The download progress in bytes, -1 when not currently downloading

    Remarks
    Note

    Use GetMediaMetadata(String) to get media item's total size in bytes

    Note

    Video IDs are not supported, use GetProjectProgress(String) instead

    Examples
    public string GetDetailedDownloadProgress(string mediaId)
    {
        long progress = App.GetMediaDownloadedBytes(mediaId);
        if (progress < 0) {
            return "not downloading";
        }
        return progress + "/" + App.GetMediaMetadata(mediaId).FileSize;
    }

    GetMediaFullPath(String)

    Get the full local path to a downloaded media file

    Declaration
    public static string GetMediaFullPath(string Id)
    Parameters
    Type Name Description
    System.String Id

    ID of the media item

    Returns
    Type Description
    System.String

    full local path to media item with Id (file may not exist if not downloaded), or null if Id is incorrect

    Examples
    // Download and load a video from a specific custom variable into the Unity VideoPlayer
    public void LoadMenuVideo(UnityEngine.Video.VideoPlayer player)
    {
        // get the video ID by getting it from a specific named custom variable
        string videoId = Headjack.CustomVariables.GetVariable<string>("menu_video");
        // download the video file
        Headjack.App.DownloadSingleMedia(videoId, false, delegate (bool success, string error)
        {
            // if the video successfully downloaded, load that video into the Unity VideoPlayer
            if (success)
            {
                player.url = Headjack.App.GetMediaFullPath(videoId);
            }
        });
    }

    GetMediaMetadata(String)

    Get metadata for media item

    Declaration
    public static App.MediaMetadata GetMediaMetadata(string mediaId)
    Parameters
    Type Name Description
    System.String mediaId

    ID of media item

    Returns
    Type Description
    App.MediaMetadata

    App.MediaMetadata class containing metadata for media item, or null when invalid mediaId

    Remarks
    Note

    mediaId must be a media item either from a custom variable or a thumbnail of a project or category used in the app

    Note

    Videos in projects are special entries on the server and do not have a media ID

    Examples
    // return filesize of specific custom media variable (or -1 if custom variable fails to return media)
    public long GetCustomFileSize()
    {
        // try to get media id from custom variable named a_media_variable
        string mediaId;
        if (Headjack.CustomVariables.TryGetVariable<string>("a_media_variable", out mediaId))
        {
            App.MediaMetadata mediaMetaData = Headjack.App.GetMediaMetadata(mediaId);
            if (mediaMetaData != null)
            {
                return mediaMetaData.FileSize;
            }
        }
        return -1;
    }

    GetMediaPath(String)

    Local path for media file "Id"

    Declaration
    public static string GetMediaPath(string Id)
    Parameters
    Type Name Description
    System.String Id
    Returns
    Type Description
    System.String

    GetMediaProgress(String)

    Get the download progress of an individual media item in percentage (0 to 100)

    Declaration
    public static float GetMediaProgress(string MediaId)
    Parameters
    Type Name Description
    System.String MediaId

    The media (by ID) to check

    Returns
    Type Description
    System.Single

    The download progress from 0 to 100, -1 when not currently downloading or total size unknown

    Remarks
    Note

    The returned value is not rounded, for displaying smooth loading bars

    Note

    Video IDs are not supported, use GetProjectProgress(String) instead

    Examples
    public string GetProgressText(string mediaId)
    {
        float progress = App.GetMediaProgress(mediaId);
        if (progress < 0) {
            return "-%";
        }
        return Mathf.FloorToInt(progress).ToString() + "%";
    }

    GetMediaUrl(String)

    Url for media file "Id"

    Declaration
    public static string GetMediaUrl(string Id)
    Parameters
    Type Name Description
    System.String Id
    Returns
    Type Description
    System.String

    GetProjectMetadata(String, App.ByteConversionType)

    Get metadata of project

    Declaration
    public static App.ProjectMetadata GetProjectMetadata(string projectId, App.ByteConversionType FileSizeFormat = App.ByteConversionType.Megabytes)
    Parameters
    Type Name Description
    System.String projectId

    Project ID whose video metadata to retrieve

    App.ByteConversionType FileSizeFormat

    Filesize format of TotalSize in return class

    Returns
    Type Description
    App.ProjectMetadata

    App.ProjectMetadata class containing metadata for project, null when projectId is invalid

    Remarks
    Note

    Use GetProjects(String, Int32, Int32) to get a list of Project IDs for this App

    Note

    Some variables in the returned App.ProjectMetadata class can be null if the project is missing data (e.g. does not have a thumbnail)

    Examples
    // Set text of 3D Text Mesh to filesize (in MB) of project with projectId
    void SetProjectSize(string projectId, UnityEngine.TextMesh projectSizeText)
    {
        float projectSize = Headjack.App.GetProjectMetadata(projectId, Headjack.App.ByteConversionType.Megabytes).TotalSize;
        // set 3D text to <projectSize> MB (projectSize is rounded to 2 decimal points)
        projectSizeText.text = projectSize.ToString("2n") + " MB";
    }

    GetProjectProgress(String)

    Get the download progress of a project (0 to 100)

    Declaration
    public static float GetProjectProgress(string ProjectId)
    Parameters
    Type Name Description
    System.String ProjectId

    The project to check

    Returns
    Type Description
    System.Single

    The download progress from 0 to 100, -1 on fail

    Remarks
    Note

    The returned value is not rounded, for displaying smooth loading bars

    Examples
    public string GetProgressText(string projectid)
    {
        if (!App.ProjectIsDownloading(projectid))
        {
            return null;
        }
        float progress = App.GetProjectProgress(projectid);
        return Mathf.FloorToInt(progress).ToString() + "%";
    }

    GetProjects(String, Int32, Int32)

    Contains all available projects from the server

    Declaration
    public static string[] GetProjects(string CategoryId = null, int MaxPageSize = -1, int CurrentPage = 0)
    Parameters
    Type Name Description
    System.String CategoryId

    Only return projects that fit in this category filter

    System.Int32 MaxPageSize

    Only return a part from the list

    System.Int32 CurrentPage

    The part of the list to return. Starting at 0

    Returns
    Type Description
    System.String[]

    A list with project ids

    Remarks
    Note

    Use GetCategories() To get all available categories.

    Examples
    //In this case, 5 projects per page
    public string[] WhatsOnTheFirstPage
    {
        return App.GetProjects(null,5,0);
    }
    public string[] WhatsOnTheLastPage
    {
        return App.GetProjects(null,5,int.MaxValue);
    }

    GetStreamProfile(String)

    Get the video encoding settings for streaming video

    Declaration
    public static App.StreamProfile GetStreamProfile(string Id)
    Parameters
    Type Name Description
    System.String Id

    ID of the video or project (containing the video)

    Returns
    Type Description
    App.StreamProfile

    App.StreamProfile stream encoding profile and settings

    GetTitle(String)

    Get the title of the given project

    Declaration
    public static string GetTitle(string Id)
    Parameters
    Type Name Description
    System.String Id

    The project id

    Returns
    Type Description
    System.String

    The title of the project with ProjectId

    Remarks
    Note

    To get a list with available projects, use GetProjects(String, Int32, Int32)

    Examples
    public string GetFirstTitle()
    {
        string[] ids = App.GetProjects();
        return App.GetTitle(ids[0]);
    }

    GetTrackingOrigin()

    Gets whether to Unity scene is centered on the floor level or the eye level

    Declaration
    public static App.TrackingOrigin GetTrackingOrigin()
    Returns
    Type Description
    App.TrackingOrigin

    GetVideoAvailability(String, Boolean)

    Get the availability of a video based on the video or project ID

    Declaration
    public static App.VideoAvailability GetVideoAvailability(string Id, bool Stream)
    Parameters
    Type Name Description
    System.String Id

    ID of the video or project (containing the video)

    System.Boolean Stream

    Whether to return availability of the stream of this video or the download

    Returns
    Type Description
    App.VideoAvailability

    App.VideoAvailability whether the video can be downloaded or streamed (and why)

    GetVideoFilename(String)

    Local filename of video

    Declaration
    public static string GetVideoFilename(string Id)
    Parameters
    Type Name Description
    System.String Id
    Returns
    Type Description
    System.String

    GetVideoLocalSubPath(String, Boolean)

    Local path for video file "Id"

    Declaration
    public static string GetVideoLocalSubPath(string Id, bool dl = false)
    Parameters
    Type Name Description
    System.String Id
    System.Boolean dl
    Returns
    Type Description
    System.String

    GetVideoMetadata(String)

    Get metadata for video associated with project ID

    Declaration
    public static App.VideoMetadata GetVideoMetadata(string Id)
    Parameters
    Type Name Description
    System.String Id

    Project ID whose video metadata to retrieve

    Returns
    Type Description
    App.VideoMetadata

    App.VideoMetadataclass containing metadata for video item, or null when invalid Project ID or project without video

    Remarks
    Note

    Use GetProjects(String, Int32, Int32) to get a list of Project IDs for this App

    Note

    To get filesize and other information about a project, use GetProjectMetadata(String, App.ByteConversionType)

    Examples
    // Returns string with duration of video in n-th project (first = 0, second = 1, etc. project in App)
    // in format MM:SS (M = minutes, S = seconds)
    string GetFormattedVideoDuration(int projectIndex)
    {
        string[] projects = Headjack.App.GetProjects();
        // if projectIndex is invalid (negative or larger than number of projects), return empty string
        if (projectIndex < 0 || projectIndex >= projects.Length) 
        {
            return "";
        }
        return Headjack.App.GetVideoMetadata(projects[projectIndex]).DurationMMSS;               
    }

    GetVideoPath(String)

    Local path for video file "Id"

    Declaration
    public static string GetVideoPath(string Id)
    Parameters
    Type Name Description
    System.String Id
    Returns
    Type Description
    System.String

    GetVideoProfile(String)

    Get the video encoding settings for downloaded video

    Declaration
    public static App.VideoProfile GetVideoProfile(string Id)
    Parameters
    Type Name Description
    System.String Id

    ID of the video or project (containing the video)

    Returns
    Type Description
    App.VideoProfile

    App.VideoProfile video encoding profile and settings

    GetVideoStreamUrl(String)

    Get the URL to a video when streaming

    Declaration
    public static string GetVideoStreamUrl(string VideoId)
    Parameters
    Type Name Description
    System.String VideoId

    ID of the video, see VideoId

    Returns
    Type Description
    System.String

    URL to the video stream (usually to .m3u8 HLS playlist or direct .mp4 video file). Returns null if VideoId could not be found or if video cannot be streamed.

    GetVideoUrl(String)

    Url for video file "Id"

    Declaration
    public static string GetVideoUrl(string Id)
    Parameters
    Type Name Description
    System.String Id
    Returns
    Type Description
    System.String

    GotFiles(String)

    Check if you have all the files of a project

    Declaration
    public static bool GotFiles(string ProjectId)
    Parameters
    Type Name Description
    System.String ProjectId

    Project to check

    Returns
    Type Description
    System.Boolean

    True if you have all the files

    Remarks
    Note

    Does not check if you have the latest version of the files, for that see UpdateAvailable(String)

    Examples
    public void StreamOnlyWhenFilesAreNotPresent(string projectid)
    {
        if (App.GotFiles(projectid))
        {
            App.Play(projectid, false, false, null);
        }
        else
        {
            App.Play(projectid, true, true, null);
        }
    }

    GotMediaFile(String)

    Check if a Media file is already downloaded

    Declaration
    public static bool GotMediaFile(string MediaId)
    Parameters
    Type Name Description
    System.String MediaId
    Returns
    Type Description
    System.Boolean

    Initialize(OnEnd, Boolean, Boolean, String, String)

    Initialize the app and download necessary data

    Declaration
    public static void Initialize(OnEnd OnReady, bool autoCreateCamera = true, bool cardboardStereoMode = true, string platform = null, string customHost = null)
    Parameters
    Type Name Description
    OnEnd OnReady

    Will be called when done

    System.Boolean autoCreateCamera

    Also activate the VR camera

    System.Boolean cardboardStereoMode

    (cardboard) VR Mode enabled for cardboard

    System.String platform

    The encoding profile platform identifier to use (null means automatic)

    System.String customHost

    Use a custom hosted app metadata file (contact support@headjack.io for more information)

    Remarks
    Note

    Must be called before all other Headjack operations

    Examples
    public void Initialize()
    {
        App.Initialize(OnReady);
    }
    public void OnReady(bool Succes)
    {
        if (Succes)
        {
            print("Initialized!");
        } else
        {
            print("No internet connection");
        }
    }

    Initialize(OnEnd, Boolean, Boolean, String, String, String, String)

    Declaration
    public static void Initialize(OnEnd OnReady, bool autoCreateCamera, bool cardboardStereoMode, string appId, string authKey, string platform = null, string customHost = null)
    Parameters
    Type Name Description
    OnEnd OnReady
    System.Boolean autoCreateCamera
    System.Boolean cardboardStereoMode
    System.String appId
    System.String authKey
    System.String platform
    System.String customHost

    IsCrosshairHit(Collider, App.RaycastSource)

    Returns true if the user is aiming at the target

    Declaration
    public static bool IsCrosshairHit(Collider target, App.RaycastSource raycastSource = App.RaycastSource.Gaze)
    Parameters
    Type Name Description
    Collider target

    The collider to check

    App.RaycastSource raycastSource

    Where the raycast is coming from

    Returns
    Type Description
    System.Boolean

    True if the user is looking at the collider

    Examples
    bool IsTheCameraLookingAtMe
    {
        return App.IsCrosshairHit(gameobject);
    }

    IsCrosshairHit(Collider, out RaycastHit, App.RaycastSource)

    Returns true if the user is aiming at the target

    Declaration
    public static bool IsCrosshairHit(Collider target, out RaycastHit hitInfo, App.RaycastSource raycastSource = App.RaycastSource.Gaze)
    Parameters
    Type Name Description
    Collider target

    The collider to check

    RaycastHit hitInfo

    RaycastHit containing all information about the raycast

    App.RaycastSource raycastSource

    Where the raycast is coming from

    Returns
    Type Description
    System.Boolean

    True if the user is looking at the collider

    Examples
    bool IsTheCameraLookingAtMe
    {
        return App.IsCrosshairHit(gameobject);
    }

    IsCrosshairHit(GameObject, App.RaycastSource)

    Returns true if the user is aiming at the target

    Declaration
    public static bool IsCrosshairHit(GameObject target, App.RaycastSource raycastSource = App.RaycastSource.Gaze)
    Parameters
    Type Name Description
    GameObject target

    The object to check

    App.RaycastSource raycastSource

    Where the raycast is coming from

    Returns
    Type Description
    System.Boolean

    True if the user is looking at the object

    Remarks
    Note

    Object must have a collider (2d colliders won't work)

    Examples
    bool IsTheCameraLookingAtMe
    {
        return App.IsCrosshairHit(gameobject);
    }

    IsCrosshairHit(GameObject, out RaycastHit, App.RaycastSource)

    Returns true if the user is aiming at the target

    Declaration
    public static bool IsCrosshairHit(GameObject target, out RaycastHit hitInfo, App.RaycastSource raycastSource = App.RaycastSource.Gaze)
    Parameters
    Type Name Description
    GameObject target

    The object to check

    RaycastHit hitInfo

    RaycastHit containing all information about the raycast

    App.RaycastSource raycastSource

    Where the raycast is coming from

    Returns
    Type Description
    System.Boolean

    True if the user is looking at the object

    Remarks
    Note

    Object must have a collider (2d colliders won't work)

    Examples
    bool IsTheCameraLookingAtMe
    {
        return App.IsCrosshairHit(gameobject);
    }

    IsLiveStream(String)

    Check if a project contains a live stream

    Declaration
    public static bool IsLiveStream(string id)
    Parameters
    Type Name Description
    System.String id
    Returns
    Type Description
    System.Boolean

    true if the project contains a live stream

    Examples
    public string CheckIfLiveStream(ProjectId)
    {
        if(App.IsLiveStream(ProjectId))
        {
            return "Livestream!";
        } else {
            return "No Livestream";
        }
    }

    IsPackaged(String)

    Declaration
    public static bool IsPackaged(string id)
    Parameters
    Type Name Description
    System.String id
    Returns
    Type Description
    System.Boolean

    Play(Int32, Boolean, Boolean, OnEnd)

    Declaration
    public static void Play(int projectNr, bool Stream, bool WifiOnly, OnEnd onEnd = null)
    Parameters
    Type Name Description
    System.Int32 projectNr
    System.Boolean Stream
    System.Boolean WifiOnly
    OnEnd onEnd

    Play(String, Boolean, Boolean, OnEnd)

    Play a project

    Declaration
    public static void Play(string ProjectId, bool Stream, bool WifiOnly, OnEnd onEnd = null)
    Parameters
    Type Name Description
    System.String ProjectId

    The project you want to play

    System.Boolean Stream

    Directly stream the video from the server

    System.Boolean WifiOnly

    (Streaming) only stream when connected to a wifi network

    OnEnd onEnd

    Will be called when the video is finished

    Remarks
    Note

    Will automatically create and initialize the video player. If stream is false, the video won't play if it isn't downloaded first

    Warning

    Enabling WifiOnly is strongly recommended when using Stream to avoid high mobile data costs

    Examples
    public void StreamFirstVideo()
    {
        string id = App.GetProjects()[0];
        App.Play(id, true, true, onEnd);
    }
    public void onEnd(bool succes, string error)
    {
        print("Video has finished playing!");
    }

    Prepare(String, Boolean, Boolean, OnEnd, Int64)

    Declaration
    public static void Prepare(string ProjectId, bool Stream, bool WifiOnly, OnEnd onEnd = null, long VideoTime = 0L)
    Parameters
    Type Name Description
    System.String ProjectId
    System.Boolean Stream
    System.Boolean WifiOnly
    OnEnd onEnd
    System.Int64 VideoTime

    ProjectIsDownloading(String)

    Check if a project is currently downloading

    Declaration
    public static bool ProjectIsDownloading(string ProjectId)
    Parameters
    Type Name Description
    System.String ProjectId

    Project to check

    Returns
    Type Description
    System.Boolean

    True if a project is currently downloading

    Remarks
    Note

    To get the progress, use GetProjectProgress(String)

    Examples
    public float GetProgress(string projectid)
    {
        if (App.ProjectIsDownloading(projectid))
        {
            return App.GetProjectProgress(projectid);
        }
        else
        {
            return -1;
        }
    }

    ProjectIsLiveStream(String)

    Check if a project contains a live stream

    Declaration
    public static bool ProjectIsLiveStream(string ProjectId)
    Parameters
    Type Name Description
    System.String ProjectId
    Returns
    Type Description
    System.Boolean

    true if the project contains a live stream

    Examples
    public string CheckIfLiveStream(ProjectId)
    {
        if(App.ProjectIsLiveStream(ProjectId))
        {
            return "Livestream!";
        } else {
            return "No Livestream";
        }
    }

    Recenter(Boolean)

    Recenter orientation and position on your device

    Declaration
    public static void Recenter(bool allowRoomScaleHeight = true)
    Parameters
    Type Name Description
    System.Boolean allowRoomScaleHeight

    When true, (0,0,0) will be at floor level

    Examples
    // Recenter when playing a video
    void PlayVideo(string id)
    {
        App.Recenter();
        App.Play(id, true, true, null);
    }

    RegisterCinemaListener(String, PushEvent)

    Register listener for a named event from the live Cinema feature

    Declaration
    public static void RegisterCinemaListener(string eventName, PushEvent listener)
    Parameters
    Type Name Description
    System.String eventName

    Event name listener will be associated with

    PushEvent listener

    This delegate will be invoked when event with eventName is activated

    Remarks
    Note

    The listener takes a parameter, which contains an array of event arguments

    Cinema default events: "changeAlias": string parameter is new device name/alias "download": download project, string parameter is project ID "play": play project, string parameter is project ID "delete": delete project, string parameter is project ID "stop": stop playback, no parameters "pause": pause playback, no parameters "resume": resume playback, no parameters "view": show project details, string parameter is project ID "stream": stream from url, string parameter is stream url "message": show message to user, string parameter is message

    Examples
    public void Start() {
        App.RegisterCinemaListener("pause", HandleCinemaPause);
    }
    // pause video playback
    public void HandleCinemaPause() {
        if (App.Player != null) {
            App.Player.Pause();
        }
    }

    RemoveCinemaListener(String, PushEvent)

    Remove a listener for a named Cinema event

    Declaration
    public static void RemoveCinemaListener(string eventName, PushEvent listener)
    Parameters
    Type Name Description
    System.String eventName

    Event name listener is associated with

    PushEvent listener

    This delegate will be removed from the event's listeners

    Remarks
    Note

    See RegisterCinemaListener(String, PushEvent) for more information.

    Examples
    PushEvent previouslyRegisteredListener;
    // remove previouslyRegisteredListener from "pause" event listeners
    public void RemoveListener() {
        App.RemoveCinemaListener("pause", previouslyRegisteredListener);
    }

    Reset()

    Resets the initialization and configuration to allow for a different app initialization

    Declaration
    public static void Reset()

    SendCinemaStatus(String, String, Single, Single, String)

    Send an updated status to the Cinema server

    Declaration
    public static void SendCinemaStatus(string statusType, string message, float progressCurrent = -1F, float progressTotal = -1F, string progressUnit = "%")
    Parameters
    Type Name Description
    System.String statusType

    One of several pre-defined status type names

    System.String message

    A message further detailing the status

    System.Single progressCurrent

    Generic current progress (e.g. download or playback progress)

    System.Single progressTotal

    Max value of progressCurrent

    System.String progressUnit

    String indicating which unit progressCurrent should be displayed in

    Remarks

    Pre-defined status types: "error": error occurred, message contains details "playing": currently playing a project "paused": playback of a project is paused "downloading": downloading project/media "idle": nothing active, waiting for command

    Examples
    // register listener to "pause" event that sends "paused" status back
    public void RegisterPauseListener() {
        App.RegisterCinemaListener("pause", delegate {
            if (App.Player != null) {
                App.Player.Pause();
                App.SendCinemaStatus("paused", "Paused playback of " +
                    App.GetProjectMetadata(App.CurrentProject).Title);
            } else {
                App.SendCinemaStatus("idle", "Nothing to pause");
            }
        });
    }

    SendVideoEvent(App.VideoEventType, String)

    Send manual video playback analytics event

    Declaration
    public static void SendVideoEvent(App.VideoEventType eventType, string projectId)
    Parameters
    Type Name Description
    App.VideoEventType eventType

    The type of analytics event to record

    System.String projectId

    The project ID to attribute the analytics event to

    Remarks
    Warning

    Do not use this function when playing video with the regular Play(String, Boolean, Boolean, OnEnd) or Prepare(String, Boolean, Boolean, OnEnd, Int64) functions as these already automatically record video playback analytics. Only use this function to record analytics when using your own custom video player logic and automatic analytics recording is not working.

    Note

    Sending the EndVideo event at the end of video playback is optional, but not sending it will result in the view duration analytics data being inaccurate.

    SetCamera(Boolean, Boolean)

    Enable or Disable the default Headjack VR Camera and switch VR mode on Cardboard

    Declaration
    public static void SetCamera(bool visible = true, bool vrMode = true)
    Parameters
    Type Name Description
    System.Boolean visible

    Enable or Disable the VR Camera

    System.Boolean vrMode

    (Cardboard) Enable or Disable VR mode

    Examples
    public void GoFullScreen()
    {
        App.SetCamera(true,false);
    }

    SetCameraBackground(Color)

    Set background color

    Declaration
    public static void SetCameraBackground(Color backgroundColor)
    Parameters
    Type Name Description
    Color backgroundColor

    UnityEngine.Color object containing new background color

    Remarks
    Note

    This sets the background color of the active VR camera, and persists between Unity scenes.

    Examples
    // Set backgound color to red
    public void SetRedBackground()
    {
        Headjack.App.SetCameraBackground(Color.red);
    }

    SetCameraBackground(Material)

    Set background skybox

    Declaration
    public static void SetCameraBackground(Material skybox)
    Parameters
    Type Name Description
    Material skybox

    UnityEngine.Material object containing new skybox

    Remarks
    Note

    This sets the background skybox of the active VR camera, and persists between Unity scenes.

    Examples
    // Set the default Unity Skybox to the headjack camera
    public void SetDefaultSkybox()
    {
        Headjack.App.SetCameraBackground(RenderSettings.skybox);
    }

    SetTrackingOrigin(App.TrackingOrigin)

    Sets whether to Unity scene is centered on the floor level or the eye level

    Declaration
    public static bool SetTrackingOrigin(App.TrackingOrigin origin)
    Parameters
    Type Name Description
    App.TrackingOrigin origin
    Returns
    Type Description
    System.Boolean

    True if Tracking origin was successfully set

    Remarks
    Note

    For VR platforms that do not have an internal floor height, using 1.6m below current eye height

    ShowMessage(String, Single, OnEnd)

    PopUp Messages for displaying a text

    Declaration
    public static void ShowMessage(string Message, float TimeInSeconds = 3F, OnEnd onEnd = null)
    Parameters
    Type Name Description
    System.String Message
    System.Single TimeInSeconds
    OnEnd onEnd
    Examples
    public void SayHello()
    {
        App.ShowMessage("Hello world", 1f);
    }

    UpdateAvailable(String)

    Check if a project or media file has an update available

    Declaration
    public static bool UpdateAvailable(string Id)
    Parameters
    Type Name Description
    System.String Id

    Id to check

    Returns
    Type Description
    System.Boolean

    True if there is an update available

    Remarks
    Note

    Will also return True if the files are not yet downloaded

    Examples
    public void CheckForUpdates()
    {
        string[] projects = App.GetProjects();
        foreach (string project in projects)
        {
            if(App.UpdateAvailable(project))
            {
                print(project + " has an update available!");
            }
        }
    }

    UpdateAvailableMedia(String)

    Check if an update is available for media with given id

    Declaration
    public static bool UpdateAvailableMedia(string MediaId)
    Parameters
    Type Name Description
    System.String MediaId
    Returns
    Type Description
    System.Boolean
    In This Article
    Back to top