void Start() { try { // Creation of the NexPlayer instance player = NexPlayerFactory.GetNexPlayer(); // Register to the events of NexPlayer player.OnEvent += EventNotify; // Initialize NexPlayer with an URI player.Init(URL, autoPlay, extendedLogs); // Change the text informing the status of the player status.text = "Opening..."; // The coroutine needs to be started after the player is created an initialized StartCoroutine(player.CoroutineEndOfTheFrame()); } catch (System.Exception e) { Debug.LogError("Error while initializing the player. Please check that your platform is supported."); Debug.LogError("Exception: " + e); status.text = "Error"; player = null; } }
void OnDisable() { if (player != null) { StopCoroutine(player.CoroutineEndOfTheFrame()); player = null; } }
/// <summary> /// Creates an instance of NexPlayerBase for the currently selected platform. This allows to use one API for all the supported platforms. /// It's recommended to use this and not instantiate directly a class that extends NexPlayerBase. /// </summary> /// <returns>A NexPlayerBase instance.</returns> public static NexPlayerBase GetNexPlayer() { NexPlayerBase player = null; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN player = new NexPlayerWindows(); #endif #if !UNITY_EDITOR && UNITY_IOS player = new NexPlayeriOS(); #endif #if !UNITY_EDITOR && UNITY_ANDROID player = new NexPlayerAndroid(); #endif #if !UNITY_EDITOR && UNITY_WEBGL player = new NexPlayerWebGL(); #endif return(player); }
void EventNotify(NexPlayerEvent paramEvent, int param1, int param2) { if (paramEvent != NexPlayerEvent.NEXPLAYER_EVENT_ON_TIME) { Debug.Log("EventNotify: " + paramEvent + ", param1: " + param1 + ", param2: " + param2); } switch (paramEvent) { case NexPlayerEvent.NEXPLAYER_EVENT_TEXTURE_CHANGED: // It's important to change the texture of every Unity object that should display the video frame when this callback is called if (GetComponent <Renderer>()) { GetComponent <Renderer>().material.mainTexture = player.GetTexture(); } else { GetComponent <RawImage>().texture = player.GetTexture(); } if (rendererToUpdate != null) { foreach (Renderer renderer in rendererToUpdate) { renderer.material.mainTexture = player.GetTexture(); } } break; case NexPlayerEvent.NEXPLAYER_EVENT_ON_TIME: SetCurrentTime(); break; case NexPlayerEvent.NEXPLAYER_EVENT_TRACK_CHANGED: SetVideoSize(); break; case NexPlayerEvent.NEXPLAYER_EVENT_INIT_COMPLEATE: { status.text = "Opened"; playPauseImage.sprite = playSprite; } break; case NexPlayerEvent.NEXPLAYER_EVENT_PLAYBACK_STARTED: { SetTotalTime(); status.text = "Playing"; playPauseImage.sprite = pauseSprite; } break; case NexPlayerEvent.NEXPLAYER_EVENT_PLAYBACK_PAUSED: { status.text = "Pause"; playPauseImage.sprite = playSprite; } break; case NexPlayerEvent.NEXPLAYER_EVENT_END_OF_CONTENT: { status.text = "Pause"; playPauseImage.sprite = playSprite; ToogleQuit(); } break; case NexPlayerEvent.NEXPLAYER_EVENT_BUFFERING_STARTED: status.text = "Buffering..."; break; case NexPlayerEvent.NEXPLAYER_EVENT_BUFFERING_ENDED: { NexPlayerStatus statusPlayer = player.GetStatusPlayer(); if (statusPlayer == NexPlayerStatus.NEXPLAYER_STATUS_PLAYING) { status.text = "Playing"; } else if (statusPlayer == NexPlayerStatus.NEXPLAYER_STATUS_PAUSED) { status.text = "Pause"; } } break; case NexPlayerEvent.NEXPLAYER_EVENT_ERROR: { status.text = "Error"; player = null; switch (param1) { case (int)NexPlayerError.NEXPLAYER_ERROR_GENERAL: Debug.LogError("NEXPLAYER_ERROR_GENERAL"); break; case (int)NexPlayerError.NEXPLAYER_ERROR_SRC_NOT_FOUND: Debug.LogError("NEXPLAYER_ERROR_SRC_NOT_FOUND"); break; } } break; case NexPlayerEvent.NEXPLAYER_EVENT_CLOSED: { player = null; GoBack(); } break; } }