Miscellaneous improvements

This commit is contained in:
2014-10-18 17:17:08 +01:00
parent eb10af1659
commit c3eded904d
4 changed files with 95 additions and 8 deletions

View File

@@ -4,14 +4,14 @@ apply plugin: 'eclipse'
group = 'com.dt' group = 'com.dt'
archivesBaseName = 'iTunesController' archivesBaseName = 'iTunesController'
version = '0.2' version = '0.3'
repositories { repositories {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
compile 'net.sf.jacob-project:jacob:1.+' compile 'net.sf.jacob-project:jacob:1.14.3'
} }
uploadArchives { uploadArchives {

View File

@@ -117,6 +117,14 @@ public class ITPlaylist extends ITObject {
Dispatch.put(object, "SongRepeat", repeatMode.ordinal()); Dispatch.put(object, "SongRepeat", repeatMode.ordinal());
} }
/**
* Cycle repeat modes.
*/
public void cycleSongRepeat() {
int repeat = Dispatch.get(object, "SongRepeat").getInt();
Dispatch.put(object, "SongRepeat", (repeat + 1) % 3);
}
/** /**
* Returns the playback repeat mode. * Returns the playback repeat mode.
* @return Returns the playback repeat mode. * @return Returns the playback repeat mode.
@@ -150,4 +158,23 @@ public class ITPlaylist extends ITObject {
Dispatch tracks = Dispatch.get(object, "Tracks").toDispatch(); Dispatch tracks = Dispatch.get(object, "Tracks").toDispatch();
return new ITTrackCollection(tracks); return new ITTrackCollection(tracks);
} }
/**
* Returns the shuffle state.
* @return true if current state is shuffle.
*/
public boolean getShuffle() {
return Dispatch.get(object, "Shuffle").getBoolean();
}
/**
* Toggle the shuffle state.
*/
public void toggleShuffle() {
setShuffle(!getShuffle());
}
public boolean containsTrack(ITTrack track) {
return getTracks().containsTrack(track);
}
} }

View File

@@ -88,4 +88,12 @@ public class ITTrackCollection {
return new ITTrack(item); return new ITTrack(item);
} }
public boolean containsTrack(ITTrack track) {
String name = track.getName();
try {
return ItemByName(name).getName().equals(name);
} catch (IllegalStateException e) {
return false;
}
}
} }

View File

@@ -1,5 +1,7 @@
package com.dt.iTunesController; package com.dt.iTunesController;
import com.jacob.activeX.ActiveXComponent; import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch; import com.jacob.com.Dispatch;
import com.jacob.com.DispatchEvents; import com.jacob.com.DispatchEvents;
@@ -13,15 +15,15 @@ import com.jacob.com.DispatchEvents;
* @version 0.2 * @version 0.2
*/ */
public class iTunes { public class iTunes {
ActiveXComponent iTunes; ActiveXComponent iTunes;
iTunesEvents iTunesEvents; iTunesEvents iTunesEvents;
DispatchEvents dispatchEvents; DispatchEvents dispatchEvents;
/** /**
* Initiate iTunes Controller. * Initiate iTunes Controller.
* @return
*/ */
public iTunes() { public void connect() {
iTunes = new ActiveXComponent("iTunes.Application"); iTunes = new ActiveXComponent("iTunes.Application");
} }
@@ -32,7 +34,7 @@ public class iTunes {
public void addEventHandler(iTunesEventsInterface itef) { public void addEventHandler(iTunesEventsInterface itef) {
iTunesEvents = new iTunesEvents(itef); iTunesEvents = new iTunesEvents(itef);
dispatchEvents = new DispatchEvents(iTunes, iTunesEvents); dispatchEvents = new DispatchEvents(iTunes, iTunesEvents);
System.out.println("New event handler added."); //System.out.println("New event handler added.");
} }
/** /**
@@ -334,6 +336,20 @@ public class iTunes {
return iTunes.getPropertyAsBoolean("Mute"); return iTunes.getPropertyAsBoolean("Mute");
} }
/**
* Toggle the mute state.
*/
public void toggleMute() {
setMute(!getMute());
}
/**
* Toggle the shuffle state.
*/
public void toggleShuffle() {
getCurrentPlaylist().toggleShuffle();
}
/** /**
* Returns the current player state. * Returns the current player state.
* @return Returns the current player state. * @return Returns the current player state.
@@ -484,4 +500,40 @@ public class iTunes {
Dispatch window = iTunes.getProperty("BrowserWindow").toDispatch(); Dispatch window = iTunes.getProperty("BrowserWindow").toDispatch();
return new ITBrowserWindow(window); return new ITBrowserWindow(window);
} }
public void cycleSongRepeat() {
getCurrentPlaylist().cycleSongRepeat();
}
public ITPlaylist getPlaylist(String name) {
ITPlaylistCollection playlistCollection = getLibrarySource().getPlaylists();
ITPlaylist playlist = playlistCollection.ItemByName(name);
try {
playlist.getName();
} catch (IllegalStateException e) {
playlist = createPlaylist(name);
}
return playlist;
}
public ITUserPlaylist getUserPlaylist(String name) {
ITPlaylist playlist = getPlaylist(name);
ITUserPlaylist userPlaylist = new ITUserPlaylist(playlist.fetchDispatch());
return userPlaylist;
}
public void playlistAddTrack(String name, ITTrack track) {
ITUserPlaylist userPlaylist = getUserPlaylist(name);
if (!userPlaylist.containsTrack(track)) {
userPlaylist.addTrack(track);
}
}
public void playlistAddCurrentTrack(String name) {
playlistAddTrack(name, getCurrentTrack());
}
public void release() {
ComThread.Release();
}
} }