|
Dear Michael,
We do not have this method in Itunes actually.
I want to create a playlist of my own and add tracks to it.
Then i want to show those tracks in lvtracks with checkbox added for selection.
I want to rename track name as well corresponding file name - to remove track number.
Please assist how to achieve this.
I am not able to trace your codes, how actually it adds tracks to lvtracks list box.
thank you
|
|
|
|
|
I was not trying to rewrite iTunes, just play with it's interface...
If you download the SDK all the information you need is there.
Dim mypl As iTunesLib.IITLibraryPlaylist = iTunesApp.CreatePlaylist("Name")
mypl.AddTrack(an IITTrack object)
|
|
|
|
|
Hi Michael,
I understand, Adding a playlist that is ok. I will find the SDK too thanks
I just wanted to perform a task which itunes do no provide.
Well, I am able to crack the code myself, just see and suggest me if I should do it better.
Me.Cursor = Cursors.WaitCursor
If Not tvPlayLists.SelectedNode Is Nothing Then
Dim objPlaylist As iTunesLib.IITPlaylist
Dim lvi As ListView.SelectedListViewItemCollection
Dim iTags As idTags
objPlaylist = LibPlaylists.ItemByName(tvPlayLists.SelectedNode.Text)
lvi = lvTracks.SelectedItems
If lvi Is Nothing Then
MsgBox("No tracks selected") 'Control is not actually coming here.. why.?
End If
For Each i As ListViewItem In lvi
iTags = i.Tag
For Each track As iTunesLib.IITFileOrCDTrack In objPlaylist.Tracks 'Can I do something better here.?
If iTags.TrackDatabaseID = track.TrackDatabaseID Then
Dim tempName As String = track.Name
If IsNumeric(Mid(tempName, 1, 1)) Then
Dim newName As String = RemoveTrackNumber(tempName) 'function to rename
track.name = newName ' Track name renamed
End If
End If
Next
Next
End If
|
|
|
|
|
My basic requirement is to transfer music files to my android device or USB drive.
I don't want to copy all files from ITUNES library but want to filter using the playlists on itunes.
So that I copy only the music files which i added to the playlist.
I want to add code to your Play button click event-
lvi = lvTracks.SelectedItems
If lvi Is Nothing Then
lvTracks.Focus()
lvTracks.Items(0).Selected = True
lvi = lvTracks.SelectedItems
End If
For Each i As ListViewItem In lvi
iTags = i.Tag
For Each track As iTunesLib.IITTrack In objPlaylist.Tracks
If iTags.TrackDatabaseID = track.TrackDatabaseID Then
Try
track.Play()
track.
Catch ex As Exception
End Try
Exit For
End If
Please help to get the codes.
|
|
|
|
|
Hello,
You need to use the IITFileOrCDTrack to get to the .Location method.
This will not work on the Playlist, when the Play button is clicked a check is made to see if there is a selected track on the playlist, if not it just plays the playlist from the top.
To replace actually playing with copying:
Private Sub bnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnPlay.Click
If tvPlayLists.SelectedNode IsNot Nothing Then
Dim objPlaylist As iTunesLib.IITPlaylist
objPlaylist = LibPlaylists.ItemByName(tvPlayLists.SelectedNode.Text)
For Each track As iTunesLib.IITFileOrCDTrack In objPlaylist.Tracks
MsgBox("File: " + Track.Location)
Next
End If
End Sub
Hope it helps.
modified 11-Jun-16 2:49am.
|
|
|
|
|
Hi, Michael.
Thank you very much . It really helped me.
Great contribution.
thank you
|
|
|
|
|
Dear Michael,
Is there any ways to count the number of music files on iTunes library.?
If its possible please assist the method to use.
Can we count the number of songs on selected playlist.
Thanks
Vivian
|
|
|
|
|
A playlist has a collection called Tracks, Tracks has a method Count which returns the number of tracks on the playlist.
I think iTunesApp.LibraryPlaylist.Tracks.Count is the entire library track count.
|
|
|
|
|
Thank you Michael,
That method is working.

|
|
|
|
|
As this is your program and I am probably to 'Dumb' to have found it somewhere on here.
If we were to edit the program in certain ways, for it to be suited to our 'Standards' or 'liking' would we have to email you personally telling you we have edited if we were going to upload it to our website?
I spend a lot of time on the computer.
|
|
|
|
|
you may use and modify the code as you see fit.
good luck
|
|
|
|
|
Hi,
Can you please explain how you created the file Interop.iTunesLib.dll ?
I'm trying to list the playlists using C#. When I add a reference to iTunes.exe, I see that Visual Studio does not recognize many of the types like IITPlayList. However, when I compile anyway using types like IITPlayList, I get errors. I think this is because my Reference to "iTunes.exe" may not be the correct approach. I am therefore wondering how you created Interop.iTunesLib.dll.
Thanks,
Sumedha
|
|
|
|
|
you need to add the itunes files as references to your project.
open your project, click the project menu and select add reference. on the COM tab you should see the itunes interfaces. add the "iTunes 1.13 Type Library" and the "ITDetector 1.0 Type Library", the version numbers seem to stay the same across versions, i have v10 installed and it still exposes them as 1.13 and 1.0, however the detector lib is now and OCX file not DLL.
not certain whether you will then need the include files for C which come with the SDK, to get that if you have not already got it you will have to register on the apple developer site, link address below, once in select downloads, developer tools and scroll for the itunes sdk for windows.
https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/promo?source=ADCLOG&code=ADCLOG-NEX
good luck.
Rabtok.
|
|
|
|
|
I'm not sure if any of you guys have noticed, but the track name doesn't update itself when the song switches
To control things like that (as well as like, resetting the trackbar of the current time w/o getting a null response)
all i did was set a timer to tick with a frequency of 10, then put in an if statement like so:
For the sake of convenience, we'll call the timer Timer1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Timer1.Tick
If iTunesApp.PlayerState = ITPlayerState.ITPlayerStatePlaying Then
lInfo.Text = iTunesApp.CurrentTrack.Name
Else
lInfo.Text = ""
End If
If you neglect to include that particular if statement, the program will be very unhappy with you
Seeing as, upon loading the program, the 'Current Song' doesn't always exist, it's rather understandable
I decided to sit down and figure this out due to my OCD haha it just wouldn't let me leave it alone.
Now you don't have to rely on the relatively useless Play or TrackChange events or whatever
-Courtesy of I, the Deceiver
|
|
|
|
|
Great code, I am using this in a touch screen hardware project as well.
Would you be able to provide some code/ideas on listing all songs in the library and not just specific playlists?
|
|
|
|
|
Here is a block of code that will do it for you. The order the tracks enumerate in appears to be either backwards or random so you need to sort any lists to make them sensible.
The code uses IITTrack (had to stop visual studio from selecting IITTrackCollection by default as IITTrack is not available but it is a valid type). You do not have to use IITTrack you can do it long hand as AllTracks.Item(i).{paramtername} instead if you want, just simplifies and makes readable.
This will get you started but i will play with it a bit more as not sure this strictly answers the question because it accesses tracks on libraryplaylists, my library is over 7000 tracks and all are on playlists need to know if a track is not on a list will it appear in this list - takes so long to load... maybe you can have a go and share.
Dim AllTracks As IITTrackCollection = iTunesApp.LibraryPlaylist.Tracks
Dim aTrack As IITTrack
For i = 1 To AllTracks.Count
aTrack = AllTracks.Item(i)
'
' Put your code here us aTrack.Name etc. to get track paramters
'
Next
Michael.
|
|
|
|
|
|
This isn't really an article since you don't explain any of the code, iTunes object model, concepts, ... nothing really.
|
|
|
|
|
the itunes sdk does all the explaining but is very short on examples, you can get it from itunes site if you hunt for it.
|
|
|
|
|
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.
|
|
|
|
|