OpenHome Forum
ohLibSpotify - Printable Version

+- OpenHome Forum (
+-- Forum: OpenHome (/forumdisplay.php?fid=1)
+--- Forum: LibSpotify (/forumdisplay.php?fid=6)
+--- Thread: ohLibSpotify (/showthread.php?tid=1113)

Pages: 1 2

ohLibSpotify - mfacer - 18-04-2013 01:05 PM

Hi - I've just downloaded the ohLibSpotify files from git. I'm currently trying to compile it - but failing MISERABLY.

On the GIT page it says that all I need is the ohLibSpotify.dll reference. I cannot find that.

I've tried loading (in to c# Visual Studio Express 2010) your "/src/" project but there were errors on that. I fixed the majority as it was simply referencing dlls that were not there (json & moq for example).

I was hoping to get a simply application - a windows form application - together where I can enter a term to search for, then use your wrapper to query and process results... but I am SO far away from that it's killing me....!!!

How would I go about using ohLibSpotify with a brand new (empty) c# forms project? (ie: reference the DLL for example).

Thanks for *any* help!!!

RE: ohLibSpotify - andreww - 19-04-2013 09:02 AM

Hi mfacer,

Sorry to hear you're having trouble. When you successfully build the project you should find the DLL is at build/bin/Release/ohLibSpotify.dll. Did you follow the instructions in The missing referenced DLLs you mention should have been fetched for you when you run the "go build" script.

Here's an example. (I'm using Powershell, but it should work the same from cmd.exe.)

[64|v32]W:\# git clone
Cloning into 'ohLibSpotify'...
remote: Counting objects: 612, done.
remote: Compressing objects: 100% (196/196), done.
Receiving objects:  84% (515/612), 124.00 KiB | 70 KiB/s
Receiving objects: 100% (612/612), 162.76 KiB | 70 KiB/s, done.
Resolving deltas: 100% (449/449), done.
[64|v32]W:\# git clone
Cloning into 'ohdevtools'...
remote: Counting objects: 350, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 350 (delta 224), reused 259 (delta 133)
Receiving objects: 100% (350/350), 82.91 KiB | 61 KiB/s, done.
Resolving deltas: 100% (224/224), done.
[64|v32]W:\# cd ohLibSpotify
[64|v32]W:\ohLibSpotify# go build
Performing step 'process_options' (reason: 'required')
Performing step 'setup' (reason: 'required')
Performing step 'openhome_setup' (reason: 'required')
Performing step 'fetch' (reason: 'default')
Fetching 'NuGet'
  from '' (web)
  unpacking to 'W:\ohLibSpotify\dependencies\AnyPlatform'
Fetching 'libspotify'
  from '' (cache)
  unpacking to 'W:\ohLibSpotify\dependencies\Windows-x86\libspotify'
Successfully installed 'MSBuildTasks'.
Successfully installed 'Moq 4.0.10827'.
Successfully installed 'NUnit 2.6.2'.
Successfully installed 'NUnit.Runners 2.6.1'.
Successfully installed 'Newtonsoft.Json 4.5.11'.
Performing step 'configure' (reason: 'default')
Performing step 'clean' (reason: 'default')
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.296]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 2013-04-19 09:55:26.

[...lots of msbuild output...]

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.94
Skipping step 'test' (reason: 'not default')
Skipping step 'publish' (reason: 'not default')
[64|v32]W:\ohLibSpotify# dir build\bin\Release

    Directory: W:\ohLibSpotify\build\bin\Release

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        2013-04-19     09:55      37888 ApiParser.exe
-a---        2013-04-19     09:54        144 ApiParser.exe.config
-a---        2013-04-19     09:55      67072 ApiParser.pdb
-a---        2013-04-19     09:55    1509376 libspotify.dll
-a---        2013-04-19     09:55      52736 ManagedApiBuilder.exe
-a---        2013-04-19     09:54        144 ManagedApiBuilder.exe.config
-a---        2013-04-19     09:55     130560 ManagedApiBuilder.pdb
-a---        2013-04-19     09:55     488448 Moq.dll
-a---        2013-04-19     09:55     343552 Moq.pdb
-a---        2013-04-19     09:55     297196 Moq.xml
-a---        2013-04-19     09:55     391680 Newtonsoft.Json.dll
-a---        2013-04-19     09:55     440219 Newtonsoft.Json.xml
-a---        2013-04-19     09:55     147456 nunit.framework.dll
-a---        2013-04-19     09:55     579843 nunit.framework.xml
-a---        2013-04-19     09:55      78848 ohLibSpotify.dll
-a---        2013-04-19     09:55     194048 ohLibSpotify.pdb
-a---        2013-04-19     09:55     425067 parsed-api.json
-a---        2013-04-19     09:55      34816 SpShellSharp.exe
-a---        2013-04-19     09:55      67072 SpShellSharp.pdb
-a---        2013-04-19     09:55      58368 ToolTests.dll
-a---        2013-04-19     09:55     103936 ToolTests.pdb

Once that's done, you can create a new project and reference ohLibSpotify.dll. You'll need to make sure that you copy libspotify.dll into your project's output directory as well.

Let me know if you're still having trouble.



RE: ohLibSpotify - mfacer - 19-04-2013 09:51 AM

(19-04-2013 09:02 AM)andreww Wrote:  Hi mfacer,
Did you follow the instructions in

Yep I have done now... Blush ... I get an error saying 'python' is not recognised as an internal or external command, operable program or batch file.

I have installed Python 2.7.x on my windows machine but continue to get the error. I tried editing the "go" batch file to manually enter the path, but nothing I try works!

This is the line I am editing...

if defined PYTHONPATH (
) else (
    set PYTHONPATH="C:\Python27"

Any ideas? thanks!

RE: ohLibSpotify - andreww - 19-04-2013 10:28 AM

(19-04-2013 09:51 AM)mfacer Wrote:  Any ideas? thanks!

It sounds like Python isn't in your system path. You can do this:

set PATH=%path%;c:\Python27

That will add it temporarily for that console session. To set it permanently you can go do this:

1. Press windows+break or right-click on "Computer" and choose properties.
2. Choose "Advanced system settings"
3. Click the "Environment Variables..." button
4. In "User variables for NAME", if there's an entry called PATH edit it, otherwise created a new one.
5. Add c:\Python27 to the path. If you're adding it to an existing path, use a semicolon to separate it.
6. Click OK.

RE: ohLibSpotify - mfacer - 19-04-2013 10:34 AM

Thanks for the reply.. I've added the PATH variable and it's starting to work.. now there's an error when it's building. Not sure where the error is... maybe you know?

C:\Documents and Settings\matt\ohLibSpotify>go build
Performing step 'process_options' (reason: 'required')
Performing step 'setup' (reason: 'required')
Performing step 'openhome_setup' (reason: 'required')
Traceback (most recent call last):
  File "c:\Python27\lib\", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\Python27\lib\", line 72, in _run_code
    exec code in run_globals
  File "C:\Documents and Settings\matt\ohdevtools\commands\", lin
e 30, in <module>
  File "C:\Documents and Settings\matt\ohdevtools\commands\", lin
e 27, in hudson_build
    run(buildname, sys.argv[1:])
  File "C:\Documents and Settings\matt\ohdevtools\", line 806, in run
  File "C:\Documents and Settings\matt\ohdevtools\", line 285, in run
  File "C:\Documents and Settings\matt\ohdevtools\", line 92, in run
    return self.action(context)
  File "C:\Documents and Settings\matt\ohdevtools\", line 169, in f_p
    f(*args, **kwargs)
  File "C:\Documents and Settings\matt\ohdevtools\", line 541, in pas
    getattr(self, name)()
  File "C:\Documents and Settings\matt\ohdevtools\", line 623, in ope
    vsvars = not program_exists('cl')
  File "C:\Documents and Settings\matt\ohdevtools\", line 439, in win
    return["where", "/q", program], shell=False)==0
  File "c:\Python27\lib\", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "c:\Python27\lib\", line 711, in __init__
    errread, errwrite)
  File "c:\Python27\lib\", line 948, in _execute_child
WindowsError: [Error 2] The system cannot find the file specified

C:\Documents and Settings\matt\ohLibSpotify>

RE: ohLibSpotify - andreww - 19-04-2013 10:38 AM

I'm afraid there are no examples of using ohLibSpotify with WinForms. I've knocked up a quick and rough example that logs in and puts log messages in a text box, but not much more.

using System;
using System.Collections.Concurrent;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using SpotifySharp;

namespace SpotifyTestApp
    public partial class Form1 : Form
        class Listener : SpotifySessionListener
            Form1 form;
            public Listener(Form1 form)
                this.form = form;
            public override void NotifyMainThread(SpotifySession session)
            public override void LoggedIn(SpotifySession session, SpotifyError error)
                form.textBox1.AppendText("Logged in!\n");
            public override void ConnectionError(SpotifySession session, SpotifyError error)
                form.textBox1.AppendText(String.Format("ConnectionError: {0}\n", error));
            public override void LogMessage(SpotifySession session, string data)
        SynchronizationContext syncContext;
        SpotifySession session;
        System.Threading.Timer timer;
        ConcurrentQueue<string> logMessages;
        public Form1()
            syncContext = SynchronizationContext.Current;
            logMessages = new ConcurrentQueue<string>();
            var config = new SpotifySessionConfig();
            config.ApiVersion = 12;
            config.CacheLocation = "spotifydata";
            config.SettingsLocation = "spotifydata";
            config.ApplicationKey = File.ReadAllBytes("spotify_appkey.key");
            config.UserAgent = "My Spotify Test App";
            config.Listener = new Listener(this);
            timer = new System.Threading.Timer(obj=>InvokeProcessEvents(session), null, Timeout.Infinite, Timeout.Infinite);
            session = SpotifySession.Create(config);
            session.Login(<INSERT USERNAME HERE>, <INSERT PASSWORD HERE>, false, null);
        void InvokeProcessEvents(SpotifySession session)
            syncContext.Post(obj=>ProcessEvents(session), null);
        void ProcessEvents(SpotifySession session)
            this.session = session;
            int timeout = 0;
            string message;
            while (logMessages.TryDequeue(out message))
                textBox1.AppendText(message + "\n");
            while (timeout == 0)
                session.ProcessEvents(ref timeout);
            timer.Change(timeout, Timeout.Infinite);

That gives you some idea of how to work with Spotify. Most of the callbacks it makes to your code happen inside your call to ProcessEvents, so they will be safely on your UI thread. However, some aren't, such as NotifyMainThread and LogMessage, so you need to be careful that they communicate safely back to the UI thread. You can mostly find out which callbacks behave like that in the libspotify docs: It seems they don't mention LogMessage, but I do believe it will be called from another thread.

RE: ohLibSpotify - mfacer - 19-04-2013 10:40 AM

(19-04-2013 10:38 AM)andreww Wrote:  I'm afraid there are no examples of using ohLibSpotify with WinForms. I've knocked up a quick and rough example that logs in and puts log messages in a text box, but not much more.

That's great thank you.. Once I've got the build sorted I'll have a play.

Thank you!

RE: ohLibSpotify - andreww - 19-04-2013 10:41 AM

Ah, I think Visual Studio Express doesn't set some environment variables that let us know where to find it. You should find and run the "vsvars32.bat" script that's somewhere in the Visual Studio directory.

Actually, I might be misreading that error. It looks like it can't find "where.exe", which is in c:\Windows\System32\where.exe for me. I have Windows 7. Is that program not present for you? What happens if you just type "where" at the command-prompt?

You can work around that problem by doing this:

go build --vsvars=no

That should tell the script that it doesn't need to find and run vsvars32.bat, but you will need to have run it yourself beforehand, in order to set up the necessary environment variables for the script to find and invoke msbuild.

Once the script has fetched those dependencies, from then on you can build in Visual Studio.

RE: ohLibSpotify - mfacer - 19-04-2013 10:56 AM

not having much luck I'm afraid...! I ran vsvars32.bat

C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools>vsvars32
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

Still get the same errors on "go build"...

- just spotted your other reply! I typed "where" and it doesn't find it. Not a recognised file....

RE: ohLibSpotify - andreww - 19-04-2013 11:07 AM

I think your post crossed with my last update. Try the --vsvars=no flag and see if it works for you.

I'll need to have a look at making the script compatible with older versions of Windows. Are you using XP?