|
Hi Michael,
I'm using your example to develop my custom itunes client.
I've only a problem; when I run my example (in VS 2005 using C#), system opens iTunes main windows and I don't know a trick to solve this problem.
In my code I put this line:
app.BrowserWindow.Visible = true;
but I've Exception:
System.InvalidCastException not managed
Message="Cast specified not valid"
Source="Interop.iTunesLib"
StackTrace:
in iTunesLib.IITBrowserWindow.set_Visible(Boolean isVisible)
in iTunesSample.Form1.cmdExit_Click(Object sender, EventArgs e) in C:\Documents and Settings\valeriose\Documenti\Visual Studio 2005\Projects\iTunesSample\iTunesSample\Form1.cs:riga 203
in System.Windows.Forms.Control.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.ButtonBase.WndProc(Message& m)
in System.Windows.Forms.Button.WndProc(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
in System.Windows.Forms.Application.Run(Form mainForm)
in iTunesSample.Program.Main() in C:\Documents and Settings\valeriose\Documenti\Visual Studio 2005\Projects\iTunesSample\iTunesSample\Program.cs:riga 17
in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart()
|
|
|
|
|
hi,
just tried to use the visible property in the VB code and i get same exception, seems that though the property is declared as boolean it does not like false or true. tried a number and anything but zero works but has no effect... go figure. there is nothing of any detail in the sdk either
found several articles where people are using this property and no complaints.
there is a forum in japanese that has an example C code on it that uses the property, not sure as i can not see your start up code to see if there is a difference in approach but here is the url:
http://www11.ocn.ne.jp/~ikalu/cs_itunes/code/csit_code003.html
the comments are in japanese but the code parts are english so you can make sense of it.
in my code i just set the browser window to minimised so never hit the issue.
good luck
michael.
|
|
|
|
|
further to my other reply...
realised i had old sdk files so downloaded the latest and found details on browserwindow which may help, it does make a statement about the property and i do not think it will do what you want, it is simply there to bring itunes to the foreground if it is minimised not actually hide the window. (get the sdk from the apple site (google "itunes sdk" it is quicker)).
to hide the window you would have to locate the iTunes process and set the visible attribute manually remembering to put it back before you exit.
anyhwo here is the sdk statement.
HRESULT IITWindow::Visible ( [in] VARIANT_BOOL shouldBeVisible )
Hide or show the window.
Note that the main browser window cannot be hidden using COM. However, if the user has minimized the main browser window to the system tray, it will appear to be hidden (as well as minimized). In this case, the main browser window can be restored by setting either the IITWindow::Visible property to true or the IITWindow::Minimized property to false.
Parameters:
shouldBeVisible True if the window should be shown.
Return values:
S_OK The operation was successful.
E_NOINTERFACE This is the main browser window.
ITUNES_E_OBJECTDELETED This window has been deleted.
E_FAIL An unexpected error occurred.
HRESULT IITWindow::Visible ( [out, retval] VARIANT_BOOL * isVisible )
Returns true if the window is visible.
Parameters:
isVisible Returns true if the window is visible.
Return values:
S_OK The operation was successful.
E_POINTER isVisible is NULL.
ITUNES_E_OBJECTDELETED This window has been deleted.
E_FAIL An unexpected error occurred.
|
|
|
|
|
Hi there. I spent all day procrastinating making a VB.net app to make two itunes on two computers play the same song at the same time, Finaly got the network code done then hit a block
Is there a way to play a specific song without all that complicated library extraction stuff?
IE just a iTunes.Play(TrackID) kind of thing
it would be most helpfull indeed
Thanks a Mill
Theron Burger
|
|
|
|
|
Hi,
I have not used it before but you can get an object using an ID. So your source machine would get the ID of the next track to play and send it to the target, the target can then find the track object using the ID information.
So long as your two libraries were the same it should work, otherwise a different track would play on the target.
I do not know if you have it or not but the iTunes SDK might help, a little...
For the Source use the following function:
HRESULT IITObject::GetITObjectIDs ( [out] long * sourceID,
[out] long * playlistID,
[out] long * trackID,
[out] long * databaseID
)
Returns the four IDs that uniquely identify this object.
This method is not usable from scripting clients, since it returns multiple output parameters. Scripting clients must use the IITObject::SourceID(), IITObject::PlaylistID(), IITObject::TrackID(), and IITObject::TrackDatabaseID() properties instead.
These are runtime IDs, they are only valid while the current instance of iTunes is running.
Parameters:
sourceID Returns the ID that identifies the source. Valid for a source, playlist, or track.
playlistID Returns the ID that identifies the playlist. Valid for a playlist or track. Will be zero for a source.
trackID Returns the ID that identifies the track within the playlist. Valid for a track. Will be zero for a source or playlist.
databaseID Returns the ID that identifies the track, independent of its playlist. Valid for a track. Will be zero for a source or playlist.
Return values:
S_OK The operation was successful.
E_POINTER sourceID, playlistID, trackID, or databaseID is NULL.
ITUNES_E_OBJECTDELETED The source, playlist, or track corresponding to this object has been deleted.
E_FAIL An unexpected error occurred.
For the target use to following function:
HRESULT IiTunes::GetITObjectByID ( [in] long sourceID,
[in] long playlistID,
[in] long trackID,
[in] long databaseID,
[out, retval] IITObject ** iObject
)
Returns an IITObject corresponding to the specified IDs.
The object may be a source, playlist, or track.
Parameters:
sourceID The ID that identifies the source. Valid for a source, playlist, or track.
playlistID The ID that identifies the playlist. Valid for a playlist or track. Must be zero for a source.
trackID The ID that identifies the track within the playlist. Valid for a track. Must be zero for a source or playlist.
databaseID The ID that identifies the track, independent of its playlist. Valid for a track. Must be zero for a source or playlist.
iObject Returns an IITObject object corresponding to the specified IDs. Will be set to NULL if no object could be retrieved.
Return values:
S_OK The operation was successful.
S_FALSE An object with the specified IDs could not be found.
E_INVALIDARG Invalid combination of IDs.
E_POINTER iObject is NULL.
E_FAIL An unexpected error occurred.
Cast the iObject to an IITTrack and execute the play method.
Good luck.
M.
|
|
|
|
|
Thanks for the speedy reply Michael
Ill give it a try as asap.
|
|
|
|
|
Actually, no matter if the two libraries are the same, this will NOT work.
The ID's you list here are runtime, session specific - they exist only for the session that iTunes is running. They are different each time iTunes loads its library.
There is an invariant, persistent identifier for a track, but it exists only in the XML library itself, and it's not available through the COM API, neither for reading or executing, so it's not going to help you.
If the files have exact same path of both computers, or if both paths are known to you, you could use PlayFile:
HRESULT IiTunes::PlayFile ( [in] BSTR filePath )
Play the specified file path, adding it to the library if not already present.
Parameters:
filePath Full path to the file to be played.
Return values:
S_OK The operation was successful.
E_POINTER filePath is NULL.
E_INVALIDARG filePath is invalid.
E_FAIL An unexpected error occurred.
If not, there's also a Find API where you specify a Source (Library, Playlist, etc) and some song specifics. If you know something unique about both songs (ie, if the search is only going to return one song on each computer), you could use that. You'll need to do some work, though. First, you need to get the iTunes COM SDK and read the documentation .
|
|
|
|
|
nice work, i like it! and, i just need an itunes control that makes only play/pause and volume control.but i wanna control running itunes, not in my exe. and, a big problem is, i'm using visual basic 6. can you help me how to do this?
|
|
|
|
|
Hi,
Never used VB6, so not much help there, there is a posting in messages for this source titled iTDetector who is using VB6 he may be useful.
Sorry I can not help.
Michael.
|
|
|
|
|
Hi, thanks for this piece of code,
Just need some work with the graphics, I am doing that, if you want I can send the graphics to you.
let me know.
|
|
|
|
|
... inspiring! can i use it?
|
|
|
|
|
Sorry been away in India...
Yep, no restrictions this end, no need even to mention my name...

|
|
|
|
|
This is great code. I'm working with Visual Basic 6 for various reasons. Anyone know how to access this ITDETECTORLib feature to detect if iTunes is running via VB6? I can't seem to get it to work. Thanks!
(FYI: I don't know VB.NET so I could be missing something obvious).
|
|
|
|
|
Hi,
Glad you like it, hope you find it useful. What version of itunes do you have installed, itdetector appeared somewhere around version 7.
I am not familiar with VB6 I am afraid so I do not know how you import a reference, guess you must have imported iTunes library and then done the same for itdetector.
Whereas iTunes library refers to the executable iTunes.exe, iTdetector is an activex control, check you can see the file ITDetector.ocx in your iTunes install directory then do what needs to be done for VB6 to use an activex control.
I have also added an update to the code to fix a bug I introduced when I put the try blocks in, not online yet, at the end of the form load remove the iTunesApp=Nothing.
Let me know the outcome.
M.
-- modified at 6:30 Monday 27th November, 2006
|
|
|
|
|
Hey. In the interim I discovered that ITDetector was an activex control (tha part was not clear to me). However, I also figured it's much easier to just determine if the process itunes.exe is running, so I used this latter approach rather than ITDetector.
|
|
|
|
|
Excellent, more than one way to skin a cat as they say.
|
|
|
|
|
iTunesApp is set to Nothing in the Load event and its properties are accessed in later events (specifically the tree view's AfterSelect).
|
|
|
|
|
Quite right there is no test, have already added a try block to the iTunesDetector initialise in my application as all should be well if iTunesDetector works as iTunes is then known to be installed but I guess there could be other reasons why it does not initialise so will add a try block to the app initialise as well.
Thanks.
|
|
|
|
|
Sorry but I gotta ask, why would I want to develop such a program when there is a free iTunes program?
|
|
|
|
|
iTunes is great, love it.
I have an application that runs on a touch screen system and they wanted to have music from the same computer. I used iTunes at first, just supplied a button that brought it to the foreground for them to select their music, unfortunately iTunes has a drag and drop feature : if you pick up a playlist and drop it on another playlist it copies itself into the dropped list even if those tracks are already there from a previous accident. You can not turn off or control this behaviour and it is fine with a mouse but a nightmare with a touch screen.
I make this statement in the blurb with the code so I am surprised you ask, guess you did not read it.
Having played with the interface and found the documentation poor I thought I would share it for anyone else who might want to tackle it.
The other reason for ever wanting to use it is if you want to provide music from your app without having to switch away from it, which is what mine now does so now client has music and no accidentally expanding playlists and my app stays in control.
|
|
|
|
|