473,498 Members | 359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When closing iTunes or my app, errors occur

1 New Member
What I want to do is get song info from iTunes if the application is running, using the ituneslib API (from Apple).

One of the problem is that to check if iTunes is playing any songs I need to make the COM object right?
But when I make it, it starts up the iTunes.exe application if iTunes is not already running.
To counter that I made checkiTunesAlive, wich goes trough the running processes in windows and returns true if iTunes.exe is running.

The other problems are that if I close my program while iTunes is running, iTunes goes on fine until I close the iTunes app, a error telling me an unhandled exception happened in iTunes.exe. When discarding the error iTunes shuts down and then starts up again, shutting it down for the secound time goes without problems

If I close iTunes first while both programs are running, iTunes reports an error, when i go past the error iTunes shuts down and starts back up again, this is becouse my iTunes process check still reports iTunes.exe in the process list while its shutting down, and when iTunes finally closes, my code is already past the iTunes.exe process list check, and making the new iTunes COM object to check for what songs its playing. How do I solve this problem?

Some times everything works OK when shutting down my app or iTunes when both are running, but that only happens about 10% of the times I try.

When both applications are running everything works as expected!

Please advice.
Expand|Select|Wrap|Line Numbers
  1.         private string SongItunes()
  2.         {
  3.             if (checkiTunesAlive() > 0)
  4.             {
  5.                 string song = string.Empty;
  6.  
  7.                 try
  8.                 {
  9.                     iTunesLib.IiTunes iTunesApp;
  10.                     iTunesApp = new iTunesLib.iTunesAppClass();
  11.  
  12.                     if (iTunesApp.CurrentTrack.Name != null)
  13.                     {
  14.                         song += iTunesApp.CurrentTrack.Artist;
  15.  
  16.                         if (iTunesApp.CurrentTrack.Artist != null)
  17.                         {
  18.                             song += " - ";
  19.                             song += iTunesApp.CurrentTrack.Name;
  20.                         }
  21.  
  22.                     }
  23.  
  24.                     //Release COM object
  25.                     Marshal.ReleaseComObject(iTunesApp.CurrentTrack);
  26.                     Marshal.ReleaseComObject(iTunesApp);
  27.                     iTunesApp = null;
  28.                 }
  29.                 catch (Exception e)
  30.                 {
  31.                     messageSend("ERROR!", e.Message);
  32.                 }
  33.  
  34.                 return song;
  35.             }
  36.             return "N/A";
  37.         }
  38.  
  39.         private int checkiTunesAlive()
  40.         {
  41.              Process[] proc = Process.GetProcessesByName("iTunes");
  42.              return proc.Length;
  43.         }
  44.  
  45.  
Sep 16 '06 #1
0 2334

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1797
by: Colin Steadman | last post by:
Does anyone have a suggestion how I could debug this problem: 1. Data is collected from database and displayed in a form. 2. User updates data and submits it. 3. Submitted data is compared with...
4
1730
by: Aaron W. LaFramboise | last post by:
I'm seeking a solution to my C++-life long dilemma of how to deal with errors when exceptions aren't appropriate. Below I highlight two error cases, which mainly occur when trying to handle...
9
4890
by: Mairhtin O'Feannag | last post by:
Hello, We have two machines we wish to use DPF. They are both RH ES 2.1, with DB2 8.2. I read the documentation CAREFULLY, and added the following line to my db2nodes.cfg file : 1 egret 0
0
1275
by: Jake Barnes | last post by:
I've written a PHP script that makes an RSS feed for some mp3s so that the music studio I work for can offer some of its new music as a podcast. Often, after a podcast episode has gone live, and...
2
4718
by: jenann50 | last post by:
hi all, i know this is probably a silly question but i dont know how to move my limewire tunes to my itunes folder so that i can download them onto my ipod. also if i have a music cd and load it...
3
3250
by: Denrael | last post by:
I've been playing with the iTunes sdk on windows, and have come across a strange problem. With the following code: import win32com.client iTunes =...
14
1891
by: adam.timberlake | last post by:
This is a really basic question for all you people out there who know PHP. This is not a problem but just something I'm confused about. I was reading the article below and wondered why are normal...
2
1382
by: =?Utf-8?B?YmVubnlnaQ==?= | last post by:
I can't launch iTunes 7.6 using Windows Vista Ultimate. I was using it and it was working fine until it froze up. I ended the task and now it won't launch at all. Things I have tried: 1. ...
16
2047
by: william tanksley | last post by:
I'm trying to convert the URLs contained in iTunes' XML file into a form comparable with the filenames returned by iTunes' COM interface. I'm writing a podcast sorter in Python; I'm using iTunes...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.