iTunes interface

speakers_86

Registered User.
Local time
Today, 00:39
Joined
May 17, 2007
Messages
1,919
I am trying to manipulate iTunes through vba. I am trying to add all records in a record set to a playlist, and then start playing that playlist starting with me.songname. I have thought of 2 ways to do this.

Have a user playlist (not smart) where each song can be added to that user playlist, then play starting with me.songname.

or

Have a smart playlist in iTunes that contains all songs where composer or grouping or some not needed field contains some word. In VBA, for each record in the record set, composer can be made to equal that word. Then, start playing the smart playlist beginning with me.songname.


An SDK is available for iTunes online. Although, it doens't offer examples. There are some examples online, but almost nothing written in vba. :(
 
That was my inspiration. I have already seen that. Thanks though!
 
Heres most of the answer.

Code:
Private Sub SongName_Click()

Set objApp = CreateObject("iTunes.Application")
Set colSources = objApp.Sources

Set objSource = colSources.ItemByName("Library")
Set colPlaylists = objSource.Playlists
Set objPlaylist = colPlaylists.ItemByName("Controller")
Set objLibrary = objApp.LibraryPlaylist
Set colTracks = objLibrary.tracks
Set objsong = colTracks.ItemByName(Me.SongName)

objPlaylist.Delete
Set objPlaylist = objApp.CreatePlaylist("Controller")
objPlaylist.AddTrack (objsong)

End Sub

The only other thing that this should do is this line
Code:
objplaylist.addtrack (objsong)
needs to itterate through out the entire recordset, starting with me.songname, and ending one record above me.songname. Can anyone show me how this is done?
 
I've believe I've got my code, but I know there are 2 errors in it.

Code:
Private Sub SongName_Click()

Set objApp = CreateObject("iTunes.Application")
Set colSources = objApp.Sources

'Delete any leftover tracks, in any
Set objSource = colSources.ItemByName("Library")
Set colPlaylists = objSource.Playlists
Set objPlaylist = colPlaylists.ItemByName("Controller")
Set objLibrary = objApp.LibraryPlaylist
Set colTracks = objLibrary.tracks
objPlaylist.Delete

'Create Playlist
Set objPlaylist = objApp.CreatePlaylist("Controller")

'Add tacks starting with me.songname
Set mydb = CurrentDb()
Set rs = Me.Recordset
Dim varbookmark As Variant
varbookmark = rs.bookmark
Do Until rs.EOF
Set objsong = colTracks.ItemByName(Me.SongName)
objPlaylist.AddTrack (objsong)
Loop

'Add tracks from beginning to me.songname
rs.MoveFirst
Do Until rs.EOF
Set objsong = colTracks.ItemByName(Me.SongName)
objPlaylist.AddTrack (objsong)
Loop

'Play playlist Controller
Dim itunes As iTunesApp
Set itunes = New iTunesApp
itunes.LibrarySource.Playlists(Controller).PlayFirstTrack


'Clean up
rs.Close
mydb.Close
Set rs = Nothing
Set mydb = Nothing

End Sub


At this part:
Code:
'Add tacks starting with me.songname
Instead of adding track after track, it adds the same track over and over. I have to break to make it stop.

EDIT- Solved. Forgot rs.movenext



At this part:
Code:
'Add tracks from beginning to me.songname
rs.MoveFirst
Do Until rs.EOF
How can I make it stop at the record that was originally clicked, not at the end?




At this part:
Code:
Set objsong = colTracks.ItemByName(Me.SongName)
it seems to be treating me.songname as what was originally clicked. How can I make it go down one for every rs.movenext. I have tried changing it to somthing like rs.field(songname).value, but that gave an error.

EDIT- The correct reference was rs!songname.value


Any help is appreciated.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom