Moved callback interfaces.

This commit is contained in:
neviyn 2016-02-23 17:33:51 +00:00
parent 0ba7ba8760
commit 75f310e140
5 changed files with 41 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package musicplayer; package musicplayer;
import musicplayer.callbacks.LibraryCallbackInterface;
import musicplayer.db.Gateway; import musicplayer.db.Gateway;
import musicplayer.model.ExtractedMetadata; import musicplayer.model.ExtractedMetadata;
import org.jaudiotagger.audio.AudioFileIO; import org.jaudiotagger.audio.AudioFileIO;
@ -12,25 +13,51 @@ import org.jaudiotagger.tag.TagException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public final class LibraryUtils { public final class LibraryUtils {
static final String musicFileExtensionRegex = ".*\\.(mp3|mp4|flac)"; static final String musicFileExtensionRegex = ".*\\.(mp3|mp4|flac)";
public static void processSongsWithCallback(List<Path> rootDirectory, LibraryCallbackInterface callbackInterface){
Thread thread = new Thread(() -> {
try {
processSongs(rootDirectory);
callbackInterface.libraryUpdated(true);
} catch (IOException e) {
callbackInterface.libraryUpdated(false);
}
});
thread.start();
}
public static void processSongsWithCallback(Path rootDirectory, LibraryCallbackInterface callbackInterface){
Thread thread = new Thread(() -> {
try {
processSongs(rootDirectory);
callbackInterface.libraryUpdated(true);
} catch (IOException e) {
callbackInterface.libraryUpdated(false);
}
});
thread.start();
}
public static void processSongs(List<Path> rootDirectories) throws IOException {
for(Path rootDirectory: rootDirectories)
processSongs(rootDirectory);
}
/** /**
* Walk through all files and directories recursively and index any music files with a correct extension * Walk through all files and directories recursively and index any music files with a correct extension
* *
* @param rootDirectory Directory from which to start searching * @param rootDirectory Directory from which to start searching
*/ */
public static void processSongs(Path rootDirectory) { public static void processSongs(Path rootDirectory) throws IOException {
try { Files.walk(rootDirectory)
Files.walk(rootDirectory) .filter(f -> f.toString().matches(musicFileExtensionRegex))
.filter(f -> f.toString().matches(musicFileExtensionRegex)) .map(LibraryUtils::autoParse).filter(Optional::isPresent).map(Optional::get).forEach(Gateway::addSong);
.map(LibraryUtils::autoParse).filter(Optional::isPresent).map(Optional::get).forEach(Gateway::addSong);
} catch (IOException e) {
e.printStackTrace();
}
} }
/** /**

View File

@ -1,5 +1,6 @@
package musicplayer; package musicplayer;
import musicplayer.callbacks.PlayerCallbackInterface;
import musicplayer.model.Song; import musicplayer.model.Song;
import org.gstreamer.ElementFactory; import org.gstreamer.ElementFactory;
import org.gstreamer.Gst; import org.gstreamer.Gst;

View File

@ -1,5 +1,7 @@
package musicplayer; package musicplayer;
import musicplayer.callbacks.LibraryCallbackInterface;
import musicplayer.callbacks.PlayerCallbackInterface;
import musicplayer.db.DatabaseManager; import musicplayer.db.DatabaseManager;
import musicplayer.db.Gateway; import musicplayer.db.Gateway;
import musicplayer.model.Album; import musicplayer.model.Album;
@ -12,7 +14,7 @@ import javax.swing.tree.TreeNode;
import java.awt.event.*; import java.awt.event.*;
import java.util.*; import java.util.*;
public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterface{ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterface {
private JTree libraryView; private JTree libraryView;
private JTable playList; private JTable playList;
private JPanel mainPanel; private JPanel mainPanel;

View File

@ -1,4 +1,4 @@
package musicplayer; package musicplayer.callbacks;
public interface LibraryCallbackInterface { public interface LibraryCallbackInterface {

View File

@ -1,4 +1,4 @@
package musicplayer; package musicplayer.callbacks;
import musicplayer.model.Song; import musicplayer.model.Song;