Miscellaneous improvements
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,18 +15,18 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an event handler to the iTunes controller.
|
* Add an event handler to the iTunes controller.
|
||||||
* @param itef The class that will handle the iTunes events.
|
* @param itef The class that will handle the iTunes events.
|
||||||
@@ -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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -333,7 +335,21 @@ public class iTunes {
|
|||||||
public boolean getMute() {
|
public boolean getMute() {
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user