{"id":328,"date":"2006-08-22T20:45:35","date_gmt":"2006-08-22T20:45:35","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2006\/08\/itunes_now_playing_in_vb_2005-shtml\/"},"modified":"2006-08-22T20:45:35","modified_gmt":"2006-08-22T20:45:35","slug":"itunes_now_playing_in_vb_2005-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/","title":{"rendered":"iTunes Now Playing in VB 2005"},"content":{"rendered":"<p>\nAs I&#8217;ve been using VB 2005 a lot more a work the past few weeks, I thought I&#8217;d rewrite my iTunes Now Playing console app in VB.\n<\/p>\n<p>\nIt does the same as the previous C# example, and again I&#8217;ve chosen to use the free version of the language and Microsoft&#8217;s Visual Basic 2005 Express Edition.\n<\/p>\n<p>\nThe first thing to do, is to make sure you have downloaded the <a href=\"http:\/\/developer.apple.com\/sdk\/itunescomsdk.html\">iTunes <acronym title=\"Software Development Kit\">SDK<\/acronym><\/a> from Apple.\n<\/p>\n<p>\nIn Visual Basic, create a new Console Application. We need to add a reference to the iTunes COM library, so we do this by right clicking over our application in the Solution Explorer, and selecting &#8220;Add Reference&#8230;&#8221;. Select the COM tab, and scroll down to find the iTunes library. Mine was called &#8220;iTunes 1.7 Type Library&#8221;.\n<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/robblog\/images\/vb_itunes_reference.gif\" alt=\"adding the iTunes COM object to VB 2005\" class=\"newblogimage,clear\" width=\"473\" height=\"387\" \/>\n<\/p>\n<p>\nNow for some code.\n<\/p>\n<p>\nFirstly, like all good programmers we turn on VB&#8217;s strict mode to make sure we&#8217;re not using too many bad programming practices.\n<\/p>\n<div class=\"code\"><code>Option Strict On<br \/>\n<\/code><\/div>\n<p>\nNext we need to import the libraries we want to use. In this case, <code>System<\/code>> and <code>iTunesLib<\/code>.\n<\/p>\n<div class=\"code\"><code>Imports System<br \/>\nImports iTunesLib<br \/>\n<\/code><\/div>\n<p>\nAs we&#8217;ve created a Console App in VB, we can just drop the following code into the <code>Main<\/code> sub.\n<\/p>\n<p>\nFirstly we need to create an iTunesApp object so we can get talk to iTunes. After that we need to get the current track.\n<\/p>\n<div class=\"code\"><code>Dim app As New iTunesApp()<br \/>\nDim track As IITTrack = app.CurrentTrack<br \/>\n<\/code><\/div>\n<p>\nWe should now have the details of the current track in the <code>track<\/code> object so we just need to print these to the console.\n<\/p>\n<div class=\"code\"><code>Console.WriteLine(\"Current Track: {0}\", track.Name)<br \/>\nConsole.WriteLine(\"Current Artist: {0}\", track.Artist)<br \/>\n<\/code><\/div>\n<p>\nFinally, just so we can see the result we need to wait for the user to press return before we exit.\n<\/p>\n<div class=\"code\"><code>Console.ReadLine()<br \/>\n<\/code><\/div>\n<p>\nFire up iTunes if it&#8217;s not already on and start a track playing. Now start your VB program, and it should tell you the current track title and artist as shown below.\n<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/robblog\/images\/vb_itunes_result.gif\" width=\"668\" height=\"338\" alt=\"iTunes now playing script\" class=\"newblogimage,clear\" \/>\n<\/p>\n<p>\nIt&#8217;s as simple as that. Obviously I&#8217;m not checking for exceptions and errors as this is just an basic example.\n<\/p>\n<p>\nYour final code should look something like this.\n<\/p>\n<div class=\"code\"><code>Option Strict On<br \/>\nImports System<br \/>\nImports iTunesLib<br \/>\nModule Module1<br \/>\nSub Main()<br \/>\nDim app As New iTunesApp()<br \/>\nDim track As IITTrack = app.CurrentTrack<br \/>\nConsole.WriteLine(\"Current Track: {0}\", track.Name)<br \/>\nConsole.WriteLine(\"Current Artist: {0}\", track.Artist)<br \/>\nConsole.ReadLine()<br \/>\nEnd Sub<br \/>\nEnd Module<br \/>\n<\/code><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I&#8217;ve been using VB 2005 a lot more a work the past few weeks, I thought I&#8217;d rewrite my iTunes Now Playing console app in VB. It does the same as the previous C# example, and again I&#8217;ve chosen to use the free version of the language and Microsoft&#8217;s Visual Basic 2005 Express Edition. &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;iTunes Now Playing in VB 2005&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[7,17],"class_list":["post-328","post","type-post","status-publish","format-standard","hentry","category-dev","tag-net","tag-dev"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>iTunes Now Playing in VB 2005 - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"iTunes Now Playing in VB 2005 - Robert Price\" \/>\n<meta property=\"og:description\" content=\"As I&#8217;ve been using VB 2005 a lot more a work the past few weeks, I thought I&#8217;d rewrite my iTunes Now Playing console app in VB. It does the same as the previous C# example, and again I&#8217;ve chosen to use the free version of the language and Microsoft&#8217;s Visual Basic 2005 Express Edition. &hellip; Continue reading &quot;iTunes Now Playing in VB 2005&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2006-08-22T20:45:35+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"iTunes Now Playing in VB 2005\",\"datePublished\":\"2006-08-22T20:45:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/\"},\"wordCount\":327,\"keywords\":[\".NET\",\"Dev\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/\",\"name\":\"iTunes Now Playing in VB 2005 - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2006-08-22T20:45:35+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_now_playing_in_vb_2005-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"iTunes Now Playing in VB 2005\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"iTunes Now Playing in VB 2005 - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"iTunes Now Playing in VB 2005 - Robert Price","og_description":"As I&#8217;ve been using VB 2005 a lot more a work the past few weeks, I thought I&#8217;d rewrite my iTunes Now Playing console app in VB. It does the same as the previous C# example, and again I&#8217;ve chosen to use the free version of the language and Microsoft&#8217;s Visual Basic 2005 Express Edition. &hellip; Continue reading \"iTunes Now Playing in VB 2005\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/","og_site_name":"Robert Price","article_published_time":"2006-08-22T20:45:35+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"iTunes Now Playing in VB 2005","datePublished":"2006-08-22T20:45:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/"},"wordCount":327,"keywords":[".NET","Dev"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/","name":"iTunes Now Playing in VB 2005 - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2006-08-22T20:45:35+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_now_playing_in_vb_2005-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"iTunes Now Playing in VB 2005"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=328"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/328\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}