JoshLmao / Spotify4Unity

🎮🎵 Add the SpotifyAPI.NET library into Unity, enabling access to the Spotify Web API, allowing for control of Spotify and accessing the world of music
https://assetstore.unity.com/packages/tools/integration/spotify4unity-ui-tools-spotify-authorization-129028
MIT License
94 stars 8 forks source link

Lots of errors logged on Android on 1.4.5 & 1.4.6 #17

Closed timendez closed 4 years ago

timendez commented 4 years ago

Describe the bug When I try to connect to the SpotifyService on Android, I receive the following:

EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.ConnectingChanged
Spotify4Unity - Has old authentification saved. Reaquiring new authorization
Spotify4Unity - Beginning Implicit Auth on Android
Spotify4Unity - Recieved Inplicit authorization on Mobile, Expires at '01/01/0001 00:00:00'
Spotify4Unity - Successfully connected to the Spotify Web API
Unable to find libc
Plugins: Couldn't open c, error: dlopen failed: library "c" not found
Plugins: Couldn't open c, error: dlopen failed: library "c" not found
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.DevicesChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.PlayStatusChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.ShuffleChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.VolumeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.MuteChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.ConnectingChanged
Spotify4Unity - Saved auth token to reuse
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.MediaTypeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.UserInfoLoaded
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.RepeatChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
EventManager: QueueEvent failed due to no listeners for event: Spotify4Unity.Events.TrackTimeChanged
...

And the TrackTimeChanged event error keeps logging indefinitely. I was able to still accurately get information about the current track I was listening to, so the connection is still solid.

However, since this bug has shown up (since I upgraded from v1.4 to v1.4.5), I haven't been able to switch scenes or manually switch to VR mode. In fact, after coming back from the browser, the Update() function in my scripts no longer fires, even though myScriptInstance.enabled returns true.

To Reproduce:

public class SpotifyController : MonoBehaviour { public SpotifyServiceBase SpotifyService; public Button LoginButton; public SceneController sceneController;

void Awake() { // Prevent the gameobject from being destroyed when the scene changes DontDestroyOnLoad(gameObject); }

void Start() { Login(); // Or call it from a button in your scene. I am calling it from a button. }

private void Login() { if (SpotifyService != null) { StartCoroutine(asyncConnect()); } else { Debug.LogError("SpotifyService hasn't been set!"); } }

private IEnumerator asyncConnect() { SpotifyService.Connect(); yield return new WaitForSeconds(0.3f); if (SpotifyService.IsConnected) { sceneController.ChangeScene(); } } }

- Add the following script to a different gameobject in the scene:
```c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneController : MonoBehaviour {
  void Update() {
    Debug.Log("updating");
  }

  public void ChangeScene() {
    SceneManager.LoadScene("Scene2");
  }
}

Expected behavior I expect no errors to log from Spotify4Unity, and the ability to change scenes

Platform:

Unity Version:

Spotify4Unity Version: v1.4.5 & v1.4.6

If there's a way to try versions before v1.4.5 I'll try that, too

Edit: Tested on multiple devices, same behavior

timendez commented 4 years ago

Changed the Log Level to All and didn't gain any insight.

timendez commented 4 years ago

Same errors even when upgraded to Unity 2019.2.0f1

JoshLmao commented 4 years ago

Hey, thanks for the awesome report. I currently don't have an Android phone on me so I can't test and fix it for a while (cause I'm current away from my main computer).

Does this occur within the Editor or only on Android builds? Also, are you building with scripting backend Mono or IL2CPP? I've had some other problems come up recently from others who are using IL2CPP and didn't realise that was something that could break everything.

timendez commented 4 years ago

I've been using Mono, I get an error when building with IL2CPP

timendez commented 4 years ago

I get a different error when trying to login within the editor:

IndexOutOfRangeException: Index was outside the bounds of the array.
Spotify4Unity.MobileSpotifyService.GetArgs () (at <0bd7703ae3e94409b241057c87cbc69e>:0)
Spotify4Unity.MobileSpotifyService.Connect () (at <0bd7703ae3e94409b241057c87cbc69e>:0)
SpotifyController+<asyncConnect>d__9.MoveNext () (at Assets/Scripts/SpotifyController.cs:53)

It occurs when I try to Connect() - the SpotifyService is still not null. I might be doing something wrong still, but I followed the instructions here for setup.

JoshLmao commented 4 years ago

The only reason that can crash is if you're supplying a different url than it's expecting into URL Authentification. It should be similar to "http://localhost:4002/#access_token=abcdefg123456.......". You should put the WHOLE of the url inside that box, not just the part after "access_token=...".

Also check that the authentification worked. If you haven't done step 1 correctly (added another redirect url to your spotify dashboard), the url won't contain an access token, which then causes it to fail

timendez commented 4 years ago

Ah that's it, where do you get the access token? When I press authorize I get the following URL, which I then copied into my URL Authentification box:

https://accounts.spotify.com/authorize?client_id={redacted}&response_type=token&redirect_uri=http%3A%2F%2Flocalhost%3A4002&scope=playlist-modify-public%20playlist-modify-private%20playlist-read-private%20streaming%20user-read-private%20user-read-email%20user-library-read%20user-library-modify%20user-follow-modify%20user-follow-read%20user-read-birthdate%20user-top-read%20playlist-read-collaborative%20user-read-recently-played%20user-read-playback-state%20user-modify-playback-state%20user-read-currently-playing%20
timendez commented 4 years ago

Ok I had read the instructions wrong and created a new app to try and get it working in the editor. I got the correct URL Authentification URL and am able to connect within the editor. I still receive the following warnings:

Screen Shot 2019-08-02 at 1 48 18 PM

Thanks for your help - I'm going to continue trying to make progress from within the editor now, but let me know if you have any more insight

JoshLmao commented 4 years ago

Yep, you figured it out. I also understand why you're getting the EventManager warnings. It's because the SpotifyService is firing those events however there isn't any listeners (Any scripts inheriting from SpotifyUIBase, since it will listen for those). I was thinking of hiding this warning actually since it's not a major problem if there isn't anything listening

For now I suggest doing changing your SpotifyController to this. It hides the warnings and I'll change that warning message to appear less, while still being useful.

using Spotify4Unity;
using Spotify4Unity.Events;
using UnityEngine.UI;

public class SpotifyController : SpotifyUIBase
{
    public Button LoginButton;
    public SceneController sceneController;

    protected override void Awake()
    {
        base.Awake();
        // Prevent the gameobject from being destroyed when the scene changes
        DontDestroyOnLoad(gameObject);
    }

    void Start()
    {
        //Login(); // Or call it from a button in your scene. I am calling it from a button.
    }

    public void Login()
    {
        SpotifyService.Connect();
    }

    protected override void OnConnectedChanged(ConnectedChanged e)
    {
        base.OnConnectedChanged(e);
        if (e.IsConnected)
        {
            sceneController.ChangeScene();
        }
    }
}
timendez commented 4 years ago

Okay thanks! That's helped me narrow down the bug - I think it's a problem with my current Unity version mixed with my Google VR version. I'm going to go ahead and close this out as I really doubt this package is the culprit.