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

Error if user is not using Premium #9

Closed Eyliess closed 5 years ago

Eyliess commented 5 years ago

If the user is not using Spotify Premium and an advertisement starts playing, the SpotifyService will generate this error each update cycle:

Spotify4Unity - SpotifyService internal Update loop exception - 'System.NullReferenceException: Object reference not set to an instance of an object at Spotify4Unity.SpotifyServiceBase.UpdateTrackInfo () [0x000e0] in <50fdd6859f05420bae70081e223c8d15>:0 at Spotify4Unity.SpotifyServiceBase.UpdateInternal () [0x00008] in <50fdd6859f05420bae70081e223c8d15>:0 ' UnityEngine.Debug:LogError(Object) Spotify4Unity.Analysis:LogError(String, LogLevel) Spotify4Unity.SpotifyServiceBase:UpdateInternal() System.Threading.ThreadHelper:ThreadStart()

This doesn't really cause any major issues and the service starts working properly as soon as the ad is over - but I actually think this could actually be useful for implementing some kind of boolean or way to check if Spotify is playing an ad - in my use case, it would be quite useful.

I know that you use premium so you wouldn't have noticed 😅

JoshLmao commented 5 years ago

I know support for Free users isn't good right now and I plan on working on that once I have iOS support done (which is the next update). I did originally plan to include it in the first release but didn't.

I'll try to sneak in a little fix in the next version that will stop it from spamming that message. Leave this open and i'll update when I get to it 😊

JoshLmao commented 5 years ago

I've pushed an update (v.1.4.1) where you can detect what type of media is being played. I've also updated the ExamplePlayerController with how to handle it by overriding the "OnMediaTypeChanged" in SpotifyUIBase and making the media control buttons to show red if a free user is trying to change their playback.

Unfortunately, through the web api, we're unable to get the advert information like name and picture so you will need to display a default icon and name, like I have in the example