This is a Visual Studio 2010 C# Windows Form Project that demonstrates the usage of the LPFM Last.fm Scrobbler API with a Windows Media Player control. Requires Windows Media Player version 9 or greater to be installed on your PC, and .NET Framework 4.
You will need to hardcode your Last.fm API Key and Secret into PlayerForm.cs before running. Apply for a key at http://www.last.fm/api/account
The application demonstrates the desktop application authentication process
by requesting a session key from the Last.fm webservice, and if none found, opening a browser so that the user can authorise the application. Once a valid session key is obtained, it is saved in the registry.
The player form offers a File > Open... menu with which you can select a media file. When you press play, the TagLibSharp library is used to obtain meta-data from the file and a NowPlaying request is queued for processing. The Queue is backed by the new .NET 4.0 ConcurrentQueue
, a thread-safe first in-first out (FIFO) collection. A delegate is used to asynchronously invoke the processing of the Scrobble, which calls the Last.fm on a seperate thread so that the form can continue with its processing.
This demonstrates asynchronous scrobbling that does not block the form at any stage.Note:
This sample project was updated to demonstrate a better way of async processing. See the discussions