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

Work in editor but not in Android device #23

Open yuanchicai opened 4 years ago

yuanchicai commented 4 years ago

When I run in android device, the authorized website pop up successfully and then I press agree, it jump back to my app. But no music information shows up.

It works in editor only if I log in to the spotify account and keep it open, I am not sure why but is working.

JoshLmao commented 4 years ago

There is a system for debugging in Editor using the MobileSpotifyService, info here

Are you building the demo scene onto your android device? Or is it a custom scene? If you could try building the demo scene and see if the error still occurs. If so, a debug message would be a lot more helpful that just a generic "not working". Make sure you've followed the setup instructions for your platform and read the FAQ incase that covers your question

yuanchicai commented 4 years ago

For the editor mode, it works fine. I build it from the mobile demo scene to my android devices. I think is the AUTHENTICATION problem maybe cause by VPN. In the test user's account, my test app already show up in "Apps with access to your Spotify information"

The Error Log:

10-17 11:20:47.160 16989-16989/? E/WebViewLibraryLoader: can't load with relro file; address space not reserved 10-17 11:20:52.232 16914-17029/? E/Unity: Unable to find libc 10-17 11:20:56.260 16914-16929/? E/Unity: PlatformNotSupportedException: Operation is not supported on this platform. at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner) [0x00018] in :0 at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T] (System.Type type) [0x00010] in :0 at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System.Type createdType) [0x00005] in :0 at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00093] in :0 at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00007] in :0 at Newtonsoft.Json.Serialization.DefaultContractResolver.Crea 10-17 11:20:56.287 658-1093/? E/volume_listener: check_and_set_gain_dep_cal: Failed to set gain dep cal level 10-17 11:20:56.290 1863-1869/? E/ANDR-PERF-OPTSHANDLER: Warning: Resource [2, 0] not supported for core 1. Instead use resource for core 0 10-17 11:20:56.290 1863-1869/? E/ANDR-PERF-RESOURCEQS: Failed to apply optimization [2, 2, 0] 10-17 11:21:32.181 892-1533/? E/NotificationService: Suppressing notification from package by user request. 10-17 11:21:40.794 1780-1791/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: , App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/games ryu: Long live credential not available. at hay.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):131) at izb.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):114) at iye.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):2) at iyc.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):17) at iyc.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):11) at gxj.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):44) at gxj.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):97) at gxt.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):3) at gxq.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):3) at gxq.c(:com.google.android.gms@19420028@19.4.20 (090400-271418971):6) at gzo.getAuthToken(:com.google.android.gms@19420028@19.4.20 (090400-271418971):10) at android.accounts.AbstractAccountAuthenticator$Transport.getAuthToken(AbstractAccountAuthenticator.java:244) at android.accounts.IAccountAuthenticator$Stub.onTransact(IAccountAuthenticator.java:113) at android.os.Binder.transact(Binder.java:627) at dxw.onTransact(:com.google.android.gms@19420028@19.4.20 (090400-271418971):3) at android.os.Binder.transact(Binder.java:627) at aams.onTransact(:com.google.android.gms@19420028@19.4.20 (090400-271418971):18) at android.os.Binder.execTransact(Binder.java:697) 10-17 11:21:40.850 1780-1791/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: , App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/games ryu: Long live credential not available. at hay.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):131) at izb.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):114) at iye.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):2) at iyc.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):17) at iyc.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):11) at gxj.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):44) at gxj.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):97) at gxt.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):3) at gxq.a(:com.google.android.gms@19420028@19.4.20 (090400-271418971):3) at gxq.c(:com.google.android.gms@19420028@19.4.20 (090400-271418971):6) at gzo.getAuthToken(:com.google.android.gms@19420028@19.4.20 (090400-271418971):10) at android.accounts.AbstractAccountAuthenticator$Transport.getAuthToken(AbstractAccountAuthenticator.java:244) at android.accounts.IAccountAuthenticator$Stub.onTransact(IAccountAuthenticator.java:113) at android.os.Binder.transact(Binder.java:627) at dxw.onTransact(:com.google.android.gms@19420028@19.4.20 (090400-271418971):3) at android.os.Binder.transact(Binder.java:627) at aams.onTransact(:com.google.android.gms@19420028@19.4.20 (090400-271418971):18) at android.os.Binder.execTransact(Binder.java:697)

JoshLmao commented 4 years ago

Okay, that's more info. However, it seems like there's two problems. First one being with Newtonsoft.Json having "Platform not supported.". I suggest swapping out Newtonsoft with Json.NET. This step is usually only required for iOS, however it seems like it could fix your problem here. Check out step 7 and step 8 of the iOS setup steps on how to do it

Second seems to be authorization to Google failing. I have no idea how to fix that one. However fixing the above might fix that 🤷‍♂️

yuanchicai commented 4 years ago

After I fixed the first one, it's working on devices and player panel. But the profiler panel info is missing:

Spotify4Unity - Can't load Private Profile information of authorized user - System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.Collections.Generic.Dictionary`2+Enumerator[TKey,TValue].MoveNext () [0x00016] in :0 at System.Net.Http.Headers.HttpHeaders+d__19.MoveNext () [0x000ac] in <563a3e1913224be7a9f3b1f34e6e98a7>:0 at System.Net.Http.Headers.HttpRequestHeaders.AddHeaders (System.Net.Http.Headers.HttpRequestHeaders headers) [0x00025] in <563a3e1913224be7a9f3b1f34e6e98a7>:0 at System.Net.Http.HttpClient.SendAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x000be] in <563a3e1913224be7a9f3b1f34e6e98a7>:0 at System.Net.Http.HttpClient.SendAsync

I have two more questions, can I pause or play songs in my app? And can I just provide several songs as options for my user?

JoshLmao commented 4 years ago

Sorry for the late response. That problem is one that I know about and trying to fix

  1. Yes you can play/pause songs in your app. But just as stated on the asset store page, the user must have Spotify Premium to control playback.
  2. You can display multiple songs in your app and as long as you pass the Song Uri to the Play() function of the service, it will begin to play. Check out the IntelliSense of the function for more help
o-litnon commented 4 years ago

Hey there!

We're enjoying the functionality of your plugin.

On this bug... This issue does not present itself when build using the mono scripting back end. We have full Spotify control with this build (send & receive data).

However...

This issue is still persisting while building with the following setup: Back end: IL2CPP Architecture: x64

We can send Spotify instructions. But we cannot receive Spotify data (e.g. Track info, Play State...)

Any help would be much appreciated!

Solved: https://github.com/JoshLmao/Spotify4Unity/issues/23#issuecomment-559748577

JoshLmao commented 4 years ago

Hi, the "Unable to find constructor..." is fixable like said above, by using Json.NET. Unless you wish to clone SpotifyAPI.NET and add in the constructors 🤷‍♂️

However, the NotSupportedException is a new one for me. Is it related to this? Also, which version of Unity are you working in? I'm not too knowledgeable about the Android build process but there are a couple other people who had the same error and had it fixed