/// <summary> /// Is called after a player event is thrown by the SDK. Is used to wait for and manage /// asynchronous events. /// </summary> /// <param name="handle">The player handle. See DZPlayer.</param> /// <param name="eventHandle">A pointer to a structure representing the event.</param> /// <param name="userData">A pointer to the context given when initializing the DZPlayer.</param> public static void PlayerOnEventCallback(IntPtr handle, IntPtr eventHandle, IntPtr userData) { // We get the object that was given as context from the IntPtr (in that case the ApplicationMainScript itself) GCHandle selfHandle = GCHandle.FromIntPtr(userData); ApplicationMainScript app = (ApplicationMainScript)selfHandle.Target; DZPlayerEvent playerEvent = DZPlayer.GetEventFromHandle(eventHandle); app.IndexInPlaylist = app.Player.GetIndexInQueulist(eventHandle); switch (playerEvent) { case DZPlayerEvent.QUEUELIST_LOADED: app.Player.Play(); break; case DZPlayerEvent.QUEUELIST_TRACK_RIGHTS_AFTER_AUDIOADS: app.Player.PlayAudioAds(); break; case DZPlayerEvent.RENDER_TRACK_END: app.isStopped = true; if (app.IndexInPlaylist == -1) { app.PlayPause(); } break; } app.DispatchEvent(playerEvent, app.IndexInPlaylist); }
void Awake() { Debug.Log(Screen.currentResolution.width + "x" + Screen.currentResolution.height); //contentLink = "track/10287076"; //contentLink = "album/607845"; // contentLink = "playlist/1363560485"; // FIXME: choose your content here string userAccessToken = "fr49mph7tV4KY3ukISkFHQysRpdCEbzb958dB320pM15OpFsQs"; string userApplicationid = "190262"; string userApplicationName = "UnityPlayer"; string userApplicationVersion = "00001"; // TODO: system-wise cache path #if UNITY_STANDALONE_WIN string userCachePath = "c:\\dzr\\dzrcache_NDK_SAMPLE"; #else string userCachePath = "/var/tmp/dzrcache_NDK_SAMPLE"; #endif dz_connect_configuration config = new dz_connect_configuration( userApplicationid, userApplicationName, userApplicationVersion, userCachePath, ConnectionOnEventCallback, IntPtr.Zero, null ); IndexInPlaylist = 0; Connection = new DZConnection(config); GCHandle selfHandle = GCHandle.Alloc(this); SelfPtr = GCHandle.ToIntPtr(selfHandle); Player = new DZPlayer(Connection.Handle); Connection.Activate(SelfPtr); Player.Activate(SelfPtr); Player.SetEventCallback(PlayerOnEventCallback); Connection.CachePathSet(config.user_profile_path); Connection.SetAccessToken(userAccessToken); Connection.SetOfflineMode(false); }