Пример #1
0
    /// <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);
    }
Пример #2
0
    public static void ConnectionOnDeactivateCallback(IntPtr delegateFunc, IntPtr operationUserData, int status, int result)
    {
        GCHandle selfHandle       = GCHandle.FromIntPtr(operationUserData);
        ApplicationMainScript app = (ApplicationMainScript)(selfHandle.Target);

        if (app.Connection.Handle.ToInt64() != 0)
        {
            app.Connection.Active = false;
            app.Connection.Handle = IntPtr.Zero;
        }
    }
Пример #3
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);
            }
        }
    }
Пример #4
0
    /// <summary>
    /// Loads the track list by retrieving the content json from the API.
    /// </summary>
    /// <param name="contentURL">The id of the content that will be sent as requet to the API.</param>
    public void LoadTrackList(string contentURL)
    {
        if (contentURL == null || contentURL.Length == 0)
        {
            return;
        }
        contentURL = "https://api.deezer.com/" + contentURL;
        Debug.Log(contentURL);
        string jsonContent = ApplicationMainScript.GetContentJson(contentURL);

        Debug.Log(jsonContent);
        if (contentURL.Contains("album"))
        {
            AlbumInfo albumInfo = JsonUtility.FromJson <AlbumInfo> (jsonContent);
            contentURL += "/tracks";
            jsonContent = ApplicationMainScript.GetContentJson(contentURL);
            jsonContent = jsonContent.Substring(jsonContent.IndexOf('['));
            jsonContent = jsonContent.Substring(0, jsonContent.LastIndexOf(']') + 1);
            jsonContent = "{\"Items\":" + jsonContent + "}";
            TrackInfo[] tracks = JsonListParser.FromJson <TrackInfo> (jsonContent);
            if (tracks.Length == 0)
            {
                return;
            }
            Debug.Log(tracks.Length);
            for (int i = 0; i < tracks.Length; i++)
            {
                tracks [i].album = albumInfo;
                AddTrackToList(tracks [i]);
            }
            TrackSelectPanelScript firstChild = transform.GetChild(0).gameObject.GetComponent <TrackSelectPanelScript> ();
            PlayingTrack.UpdateInfo(firstChild.trackName.text, firstChild.artistName.text, tracks [0].album.cover_small);
        }
        else if (contentURL.Contains("track"))
        {
            TrackInfo trackInfo = JsonUtility.FromJson <TrackInfo> (jsonContent);
            AddTrackToList(trackInfo);
            TrackSelectPanelScript firstChild = transform.GetChild(0).gameObject.GetComponent <TrackSelectPanelScript> ();
            PlayingTrack.UpdateInfo(firstChild.trackName.text, firstChild.artistName.text, trackInfo.album.cover_small);
        }
        else if (contentURL.Contains("playlist") || contentURL.Contains("radio"))
        {
            contentURL += "/tracks";
            jsonContent = ApplicationMainScript.GetContentJson(contentURL);
            jsonContent = jsonContent.Substring(jsonContent.IndexOf('['));
            jsonContent = jsonContent.Substring(0, jsonContent.LastIndexOf(']') + 1);
            jsonContent = "{\"Items\":" + jsonContent + "}";
            TrackInfo[] tracks = JsonListParser.FromJson <TrackInfo> (jsonContent);
            if (tracks.Length == 0)
            {
                return;
            }
            for (int i = 0; i < tracks.Length; i++)
            {
                AddTrackToList(tracks [i]);
            }
        }
        else
        {
            return;
        }
        Tracks [0].SetSelected();
    }