Added global keyboard controls/
This commit is contained in:
parent
2ae4ca1402
commit
0401c626e2
13
pom.xml
13
pom.xml
@ -85,6 +85,11 @@
|
|||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>lc.kra.system</groupId>
|
||||||
|
<artifactId>system-hook</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -97,6 +102,14 @@
|
|||||||
<id>jaudiotagger-repository</id>
|
<id>jaudiotagger-repository</id>
|
||||||
<url>https://dl.bintray.com/ijabz/maven</url>
|
<url>https://dl.bintray.com/ijabz/maven</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>system-hook-mvn-repo</id>
|
||||||
|
<url>https://raw.github.com/kristian/system-hook/mvn-repo/</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<updatePolicy>always</updatePolicy>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -1,5 +1,8 @@
|
|||||||
package musicplayer;
|
package musicplayer;
|
||||||
|
|
||||||
|
import lc.kra.system.keyboard.GlobalKeyboardHook;
|
||||||
|
import lc.kra.system.keyboard.event.GlobalKeyAdapter;
|
||||||
|
import lc.kra.system.keyboard.event.GlobalKeyEvent;
|
||||||
import musicplayer.callbacks.LibraryCallbackInterface;
|
import musicplayer.callbacks.LibraryCallbackInterface;
|
||||||
import musicplayer.callbacks.PlayerCallbackInterface;
|
import musicplayer.callbacks.PlayerCallbackInterface;
|
||||||
import musicplayer.db.DatabaseManager;
|
import musicplayer.db.DatabaseManager;
|
||||||
@ -14,10 +17,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
|||||||
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
import javax.swing.tree.TreeNode;
|
import javax.swing.tree.TreeNode;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.awt.event.MouseListener;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -55,6 +55,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
}
|
}
|
||||||
}, "seekbar");
|
}, "seekbar");
|
||||||
seekBarUpdater.start();
|
seekBarUpdater.start();
|
||||||
|
GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook();
|
||||||
|
keyboardHook.addKeyListener(new GlobalKeyboardShortcuts());
|
||||||
refreshLibrary();
|
refreshLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,4 +501,49 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {}
|
public void mouseExited(MouseEvent e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class GlobalKeyboardShortcuts extends GlobalKeyAdapter {
|
||||||
|
final int modifierKey = 93;
|
||||||
|
final int playPause = 116;
|
||||||
|
final int stop = 117;
|
||||||
|
final int previous = 118;
|
||||||
|
final int next = 119;
|
||||||
|
boolean modified = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(GlobalKeyEvent event) {
|
||||||
|
if(event.getVirtualKeyCode() == modifierKey)
|
||||||
|
modified = true;
|
||||||
|
else if(modified){
|
||||||
|
switch(event.getVirtualKeyCode()){
|
||||||
|
case playPause:
|
||||||
|
if(player.isPlaying()){
|
||||||
|
player.pause();
|
||||||
|
setSongHighlighting(player.getCurrentSong()); // Resume won't function if a different song is selected.
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (playList.getRowCount() > 0) {
|
||||||
|
if (playList.getSelectedRowCount() > 0)
|
||||||
|
player.playSong(playlistTableModel.getSong(playList.getSelectedRow()));
|
||||||
|
else
|
||||||
|
player.playSong(playlistTableModel.getFirst());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case stop:
|
||||||
|
player.stop(); break;
|
||||||
|
case previous:
|
||||||
|
playPreviousSong(); break;
|
||||||
|
case next:
|
||||||
|
playNextSong(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(GlobalKeyEvent event) {
|
||||||
|
if(event.getVirtualKeyCode() == modifierKey)
|
||||||
|
modified = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user