Exemplo n.º 1
0
    /// <summary>
    /// Is called after a connection event is thrown by the SDK. Is used to wait for and manage
    /// asynchronous events.
    /// </summary>
    /// <param name="handle">The connection handle. See DZConnection.</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 DZConnection.</param>
    public static void ConnectionOnEventCallback(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);

        DZConnectionEvent connectionEvent = DZConnection.GetEventFromHandle(eventHandle);

        //if (connectionEvent == DZConnectionEvent.USER_LOGIN_OK)
        if (connectionEvent == DZConnectionEvent.USER_LOGIN_FAIL_USER_INFO)
        {
            if (app.Player.Handle.ToInt64() != 0)
            {
                app.Player.Shutdown(PlayerOnDeactivateCallback, app.SelfPtr);
            }
            else if (app.Connection.Handle.ToInt64() != 0)
            {
                app.Connection.Shutdown(ConnectionOnDeactivateCallback, app.SelfPtr);
            }
        }
    }
Exemplo n.º 2
0
    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);
    }