On this blog I regularly publish articles with tips and tricks for the programming language C# .Net.
C# is a modern, object-oriented programming language, which fully ultilizes the possibilites of the .Net framework. I also write about app programming for Android via C#, as well as PHP and Matlab. The difficulty of this blog is supposed to be variable, I hope for beginners and experts there is always something to look for.
If you have questions or suggestions, I am happy about your emails.

Thursday, February 24, 2011

In the previous post was shown how to search songs in iTunes, today I want to describe explictely one time, how to play songs and navigate in playlists, switch to the next song etc ...
For playing a song the function Play() is needed, which is called from an object of the type IITTrack. As described in the previous post, we now know how to look for a song and then play it with Play().
The following code plays the 10th song from the music library:

A complete playlist can be played via the function PlayFirstTrack(), which is called from a playlist (an object of the type IITPlaylist).
The following function looks for a playlist matching the name given as the parameter, and then returns it:

Wednesday, February 23, 2011

After I showed in the previous post how to traverse the library of iTunes, I now want to show a possibility to search specific titles. For that we traverse as described the library or specific playlists and check, if our search criteria are met.
The function shown below looks for artist and title and then returns the desired track. In the case of a complete search of course multiple results can be found, a list might be a good solution for that.

Thursday, February 17, 2011

In this post I want to show, how to traverse the complete iTunes music library or single playlists using C#.
The previous post is required for that (including iTunes in C#).
Now let iTunesPlayer again be an object of the type iTunesApp, referencing iTunes. Then the property iTunesPlayer.LibraryPlaylist.Tracks returns all media files loaded by iTunes as objects of type IITTrack.
The following sample code writes all titles to a textbox (which is textBox1, Multiline has to be true and Scrollbars enabled):

But also specific playlists can be addressed. With the property iTunesPlayer.LibrarySource.Playlists all playlists can be accessed. Every playlist again has the property Tracks, which contains the media files in it.
The following sample code output all playlits from iTunes with all their titles (the first playlist is the complete library):

The next post series will cover the music program iTunes by Apple.
For that I will publish multiple posts, explaining different functions of the embedding.
In the first post I show, how to include iTunes to a C# program in general - therefor even no external software like the iTunes SDK is needed, already the "normal" iTunes installation will install the needed COM object.
To add such a reference to your C# project, click Project - Add Reference. There switch to the tab COM and select the object iTunes x.xx Type Library. And that is it, iTunes is ready.
For simplicity we import the corresponding library with using:

using iTunesLib;

In the program then an instance of the iTunes player can for example be instanced like this:

I want to show in this post, how to include Google Earth in a C# application. As for many programs, there is a library provided by Google for that purpose, the Google Earth API.
But for the simple basics used here, we don't even need this API, because Google provides an online plugin, which can be viewed in the browser.
This plugin is available on the URL http://earth-api-samples.googlecode.com/svn/trunk/demos/desktop-embedded/pluginhost.html, we just have to open this page with a Webbrowser control on the form and immediately get the globe known of Google Earth.
A little downer is, that the end users have to install the plugin, luckily though a message with a download link is displayed in the Webbrowser, if it is missing.
The following code calls the plugin: