Build a C# application based on Deezer Native SDK with Unity

The Unity sample

Bringing music everywhere

Deezer offers developers various SDK (Software Development Kit) in order to include Deezer music in their applications.

The Native SDK is one of these and mainly allows Deezer services like playback and offline synchronization.

By integrating this SDK you can address the three major platforms: Linux, MacOS and Windows.

(1) Mac OS X 10.8 or upper. (2) Windows7 or upper. (3) Validated with Fedora23 and Raspbian Jessie

Since the release of the Native SDK on March the 30th, Deezer tries to provide more and more sample applications in different languages in order to help developers make their own applications in their favorite one.

In that context I was hired to develop the first sample apps and wrappers for some popular languages, so I created two wrappers and an example application, in C# and Python respectively. Here we will focus on the C# sample app and wrapper.

C# and NativeSDK

After I did my first sample app and wrapper in Python2. The team started to wonder If we could embed the SDK in a game engine such as Unity. This was also a good occasion to build a C# wrapper and allow C# developers to make their own applications. The sample I made features a player interface and allows to load a playlist, toggle shuffle mode and repeat mode, etc. Plus it looks pretty cool:

The whole program is written in C# and provides a C# wrapper that can be used for any other C# application with or without Unity. I used DLLImport to convert the SDK’s C-functions into C# code, and Unity3D to make the UI shown above. There are two major flaws in this application: First I couldn’t implement radio support as the tracklist display is based on its length, which does not exist for that kind of content. Second is the scaling to any resolution. Fell free to rearrange the UI elements to fit to your screen if you want to build the app and use it fullscreen.

The sample app I provided contains only its own internal logic, so you can perfectly replace it with your own app and use only the C# wrapper. Even with a non Unity project.

One quick note about authentication

Note that this sample does not implement the OAuth2 authentication process (this process is required to identify yourself and your application when using the Deezer API). It uses instead an already generated access token for demonstration purpose. For more information about how to generate your access token, read this article. If you do not feel comfortable with this process or just want to test the sample, you can use the given access token. See “How to use this sample” for details.

How to only use the wrapper

If you just want the C# wrapper tu build your own C# application, you can find it under Assets/Scripts/Wrapper as shown below:

<native-sdk-samples>
├── UnitySample
│ └── Assets
│ └── Scripts
│ └── Wrapper
...

How to use the sample app

First you need the to clone or download the sdk samples repository along with the Native SDK, and of course Unity (the free version will do fine).

Then in the Bin subfolder of the SDK, move the lib corresponding to your platform and architecture into the Assets folder of the Unity sample.

If you are running on MacOSX, rename it “libdeezer.bundle”, and on Windows “libdeezer.dll”.

Note that you can modify the OAuth2 information given the the sample to use it for your own account and not the default free user provided. Go into Assets/Scripts/ApplicationMainScript.cs and modify these data accordingly. If you don’t know OAuth2 process and just want to test the sample, leave the data as it is given.

string userAccessToken = “”;
string userApplicationid = “”;
string userApplicationName = “”;
string userApplicationVersion = “”;

All set. Now do the following:

  • Start Unity
  • Go to File > Open Project
  • Select the folder UnityPlayer
  • After the project is loaded, go to the Project panel
  • Got into the folder Scenes and click Interface.scene
  • Feel free to rearrange the UI elements if they do not fit with your screen resolution
  • Click Play to test the sample, or File > Build and Run to build it and run it like a real app.

You can now play around with the app like every other player. You can change the content in the field above the track list. If it is available for the user, the track list will change accordingly.

Limitations

The application itself does not allow to play a radio or flow, as this type of content does not contain a fixed size track list. It is however possible to build your own app that will manage that, as the appropriate functions are available in the wrapper and the Deezer Native SDK.

Also note that the sample (and more generally the SDK) should be able to work together with Unity and Hololens, as long as UWP integration will be resolved.

Article written by: LEANDRI Aurélien