Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ohLibSpotify
18-04-2013, 01:05 PM
Post: #1
ohLibSpotify
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!!!
Find all posts by this user
19-04-2013, 09:02 AM (This post was last modified: 19-04-2013 09:02 AM by andreww.)
Post: #2
RE: ohLibSpotify
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 README.md? 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.)

Code:
[64|v32]W:\# git clone git@github.com:openhome/ohLibSpotify.git
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 git@github.com:openhome/ohdevtools.git
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')
default
Performing step 'fetch' (reason: 'default')
Fetching 'NuGet'
  from 'http://openhome.org/releases/artifacts/AnyPlatform/NuGet.1.7.30402.9028.tar.gz' (web)
  unpacking to 'W:\ohLibSpotify\dependencies\AnyPlatform'
  OK
Fetching 'libspotify'
  from 'http://developer.spotify.com/download/libspotify/libspotify-12.1.51-win32-release.zip' (cache)
  unpacking to 'W:\ohLibSpotify\dependencies\Windows-x86\libspotify'
  OK
Successfully installed 'MSBuildTasks 1.4.0.45'.
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.

Regards,

Andrew.
Visit this user's website Find all posts by this user
19-04-2013, 09:51 AM
Post: #3
RE: ohLibSpotify
(19-04-2013 09:02 AM)andreww Wrote:  Hi mfacer,
Did you follow the instructions in README.md?

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...

Code:
if defined PYTHONPATH (
    set PYTHONPATH=%OHDEVTOOLS_ROOT%;%PYTHONPATH%
) else (
    set PYTHONPATH="C:\Python27"
)

Any ideas? thanks!
Find all posts by this user
19-04-2013, 10:28 AM
Post: #4
RE: ohLibSpotify
(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:

Code:
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.
Visit this user's website Find all posts by this user
19-04-2013, 10:34 AM
Post: #5
RE: ohLibSpotify
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?

Code:
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\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Documents and Settings\matt\ohdevtools\commands\hudson_build.py", lin
e 30, in <module>
    hudson_build()
  File "C:\Documents and Settings\matt\ohdevtools\commands\hudson_build.py", lin
e 27, in hudson_build
    run(buildname, sys.argv[1:])
  File "C:\Documents and Settings\matt\ohdevtools\ci_build.py", line 806, in run

    builder.run(argv)
  File "C:\Documents and Settings\matt\ohdevtools\ci_build.py", line 285, in run

    step.run(self._context)
  File "C:\Documents and Settings\matt\ohdevtools\ci_build.py", line 92, in run
    return self.action(context)
  File "C:\Documents and Settings\matt\ohdevtools\ci_build.py", line 169, in f_p
rime
    f(*args, **kwargs)
  File "C:\Documents and Settings\matt\ohdevtools\ci_build.py", line 541, in pas
sthrough
    getattr(self, name)()
  File "C:\Documents and Settings\matt\ohdevtools\ci_build.py", line 623, in ope
nhome_setup
    vsvars = not program_exists('cl')
  File "C:\Documents and Settings\matt\ohdevtools\ci_build.py", line 439, in win
dows_program_exists
    return subprocess.call(["where", "/q", program], shell=False)==0
  File "c:\Python27\lib\subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "c:\Python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "c:\Python27\lib\subprocess.py", line 948, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

C:\Documents and Settings\matt\ohLibSpotify>
Find all posts by this user
19-04-2013, 10:38 AM
Post: #6
RE: ohLibSpotify
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.

Code:
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)
            {
                form.InvokeProcessEvents(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)
            {
                form.logMessages.Enqueue(data);
                NotifyMainThread(session);
            }
        }
        SynchronizationContext syncContext;
        SpotifySession session;
        System.Threading.Timer timer;
        ConcurrentQueue<string> logMessages;
        public Form1()
        {
            InitializeComponent();
            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: https://developer.spotify.com/technologi...backs.html It seems they don't mention LogMessage, but I do believe it will be called from another thread.
Visit this user's website Find all posts by this user
19-04-2013, 10:40 AM
Post: #7
RE: ohLibSpotify
(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!
Find all posts by this user
19-04-2013, 10:41 AM (This post was last modified: 19-04-2013 10:55 AM by andreww.)
Post: #8
RE: ohLibSpotify
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:

Code:
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.
Visit this user's website Find all posts by this user
19-04-2013, 10:56 AM (This post was last modified: 19-04-2013 10:56 AM by mfacer.)
Post: #9
RE: ohLibSpotify
not having much luck I'm afraid...! I ran vsvars32.bat

Code:
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....
Find all posts by this user
19-04-2013, 11:07 AM
Post: #10
RE: ohLibSpotify
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?
Visit this user's website Find all posts by this user


Forum Jump: