{"id":326,"date":"2006-08-23T21:18:52","date_gmt":"2006-08-23T21:18:52","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2006\/08\/itunes_auto_updating_now_playing_in_vb2005-shtml\/"},"modified":"2006-08-23T21:18:52","modified_gmt":"2006-08-23T21:18:52","slug":"itunes_auto_updating_now_playing_in_vb2005-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/","title":{"rendered":"iTunes Auto Updating Now Playing in VB2005"},"content":{"rendered":"<p>\nPreviously I&#8217;ve covered how to link into the iTunes COM library from VB 2005 to show now playing information. This article assumes you have already read that, or have it to hand.\n<\/p>\n<p>\nTaking this application further, wouldn&#8217;t it be useful for our application to automatically update itself when a track changes takes place on iTunes?\n<\/p>\n<p>\nWell I hope you are saying yes, as it&#8217;s what I&#8217;m going to cover now.\n<\/p>\n<p>\niTunes can inform our application of changes of track if we choose to listen for it&#8217;s <code>OnPlayerPlayEvent<\/code> event.\n<\/p>\n<p>\nIf you are not sure what an event is, it&#8217;s basically a way for one program to tell another that something has happened in that program and the other program may wish to react to it. In this case, a different track has started playing in iTunes.\n<\/p>\n<p>\nSo how can we get our application to listen out for this? Well firstly we need to say that our programme is interested in these events. We do this by using VB 2005&#8217;s <code>WithEvents<\/code> keyword when we create our interface into iTunes.\n<\/p>\n<p>\nSo previously we did this using the following code.\n<\/p>\n<div class=\"code\"><code>Dim app As New iTunesApp()<br \/>\n<\/code><\/div>\n<p>\nNow we have to add in the <code>WithEvents<\/code> keyword as follows.\n<\/p>\n<div class=\"code\"><code>Private WithEvents app As New iTunesApp<br \/>\n<\/code><\/div>\n<p>\nNow our program can listen out for events from iTunes. You may have noticed I&#8217;ve changed <code>Dim<\/code> to <code>Private<\/code>. This is because for this example I&#8217;m going to use a Windows Application and not a Console application as before.\n<\/p>\n<p>\nNext we have to create our event handler so we can react to the events iTunes is sending us.\n<\/p>\n<p>\nThe easiest way to do this is use the method generator at the top of the code view in Visual Basic 2005 Express Edition. My iTunes object is called <var>app<\/var> so we select this, then OnPlayerPlayEvent to create our event handler stub.\n<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/robblog\/images\/vb_itunes_event.gif\" alt=\"Creating an iTunes event in VB2005\" class=\"newblogimage,clear\" width=\"394\" height=\"47\" \/>\n<\/p>\n<p>\nThis passes in the variable <var>iTrack<\/var> as an <code>Object<\/code>. We know this is really an <var>IITTrack<\/var> object, so we need to cast it as such.\n<\/p>\n<div class=\"code\"><code>Dim track As IITTrack<br \/>\ntrack = CType(iTrack, IITTrack)<br \/>\n<\/code><\/div>\n<p>This creates a new varible called <var>track<\/var> and casts the existing <var>iTrack<\/var> variable as an <code>IITTrack<\/code> using CType.<br \/>\nDoing this, we have easy access to the track data passed to us by iTunes in the event.<br \/>\nWe need to do something with this information seeing as we&#8217;ve gone to all the trouble of asking iTunes for it. The easiest thing to do is to just display a small window with the name of the current track.<\/p>\n<div class=\"code\"><code>MsgBox(track.name)<br \/>\n<\/code><\/div>\n<p>\nObviously this is a simplified version of a real program, but it should give you an idea of how to get events from a remote program into your VB2005 application.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously I&#8217;ve covered how to link into the iTunes COM library from VB 2005 to show now playing information. This article assumes you have already read that, or have it to hand. Taking this application further, wouldn&#8217;t it be useful for our application to automatically update itself when a track changes takes place on iTunes? &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;iTunes Auto Updating Now Playing in VB2005&#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-326","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 Auto Updating Now Playing in VB2005 - 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_auto_updating_now_playing_in_vb2005-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"iTunes Auto Updating Now Playing in VB2005 - Robert Price\" \/>\n<meta property=\"og:description\" content=\"Previously I&#8217;ve covered how to link into the iTunes COM library from VB 2005 to show now playing information. This article assumes you have already read that, or have it to hand. Taking this application further, wouldn&#8217;t it be useful for our application to automatically update itself when a track changes takes place on iTunes? &hellip; Continue reading &quot;iTunes Auto Updating Now Playing in VB2005&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2006-08-23T21:18:52+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_auto_updating_now_playing_in_vb2005-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_auto_updating_now_playing_in_vb2005-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"iTunes Auto Updating Now Playing in VB2005\",\"datePublished\":\"2006-08-23T21:18:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_auto_updating_now_playing_in_vb2005-shtml\\\/\"},\"wordCount\":435,\"keywords\":[\".NET\",\"Dev\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_auto_updating_now_playing_in_vb2005-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_auto_updating_now_playing_in_vb2005-shtml\\\/\",\"name\":\"iTunes Auto Updating Now Playing in VB2005 - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2006-08-23T21:18:52+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_auto_updating_now_playing_in_vb2005-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_auto_updating_now_playing_in_vb2005-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/itunes_auto_updating_now_playing_in_vb2005-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"iTunes Auto Updating Now Playing in VB2005\"}]},{\"@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 Auto Updating Now Playing in VB2005 - 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_auto_updating_now_playing_in_vb2005-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"iTunes Auto Updating Now Playing in VB2005 - Robert Price","og_description":"Previously I&#8217;ve covered how to link into the iTunes COM library from VB 2005 to show now playing information. This article assumes you have already read that, or have it to hand. Taking this application further, wouldn&#8217;t it be useful for our application to automatically update itself when a track changes takes place on iTunes? &hellip; Continue reading \"iTunes Auto Updating Now Playing in VB2005\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/","og_site_name":"Robert Price","article_published_time":"2006-08-23T21:18:52+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_auto_updating_now_playing_in_vb2005-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"iTunes Auto Updating Now Playing in VB2005","datePublished":"2006-08-23T21:18:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/"},"wordCount":435,"keywords":[".NET","Dev"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/","name":"iTunes Auto Updating Now Playing in VB2005 - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2006-08-23T21:18:52+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/itunes_auto_updating_now_playing_in_vb2005-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"iTunes Auto Updating Now Playing in VB2005"}]},{"@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\/326","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=326"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/326\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}