mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
Rudimentary audio file processing.
This commit is contained in:
committed by
Bas Antonius de Jong
parent
4ea2bb96a6
commit
a957195514
1
.idea/compiler.xml
generated
1
.idea/compiler.xml
generated
@@ -7,7 +7,6 @@
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="pism_framework" />
|
||||
<module name="pis" />
|
||||
<module name="pism_game" />
|
||||
<module name="pism_app" />
|
||||
</profile>
|
||||
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -13,7 +13,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,86 +1,27 @@
|
||||
package org.toop;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.toop.app.gui.LocalServerSelector;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.networking.NetworkingClientManager;
|
||||
import org.toop.framework.networking.NetworkingInitializationException;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.framework.audio.AudioFilesManager;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
static void main(String[] args) {
|
||||
static void main(String[] args) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
|
||||
AudioFilesManager audioFiles = new AudioFilesManager("app/src/main/resources/audio/");
|
||||
String aFile = audioFiles.getAudioFile("hdchirp_88k_log.wav");
|
||||
AudioInputStream audioStream = AudioSystem.getAudioInputStream(new File(aFile));
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(audioStream);
|
||||
clip.start();
|
||||
initSystems();
|
||||
|
||||
EventFlow a =
|
||||
new EventFlow()
|
||||
.addPostEvent(NetworkEvents.StartClient.class, "127.0.0.1", 7789)
|
||||
.onResponse(Main::login)
|
||||
// .onResponse(Main::sendCommand)
|
||||
// .onResponse(Main::closeClient)
|
||||
.asyncPostEvent();
|
||||
|
||||
new Thread(
|
||||
() -> {
|
||||
while (a.getResult() == null) {
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
long clid = (Long) a.getResult().get("clientId");
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
new NetworkEvents.SendSubscribe(clid, "tic-tac-toe"))
|
||||
.listen(
|
||||
NetworkEvents.PlayerlistResponse.class,
|
||||
response -> {
|
||||
if (response.clientId() == clid)
|
||||
System.out.println(
|
||||
Arrays.toString(response.playerlist()));
|
||||
})
|
||||
.listen(
|
||||
NetworkEvents.ChallengeResponse.class,
|
||||
response -> {
|
||||
if (response.clientId() == clid)
|
||||
System.out.println(response.challengeId());
|
||||
})
|
||||
.listen(
|
||||
NetworkEvents.ChallengeCancelledResponse.class,
|
||||
response -> {
|
||||
if (response.clientId() == clid)
|
||||
System.out.println(response.challengeId());
|
||||
})
|
||||
.listen(
|
||||
NetworkEvents.GamelistResponse.class,
|
||||
response -> {
|
||||
if (response.clientId() == clid)
|
||||
System.out.println(
|
||||
Arrays.toString(response.gamelist()));
|
||||
})
|
||||
.asyncPostEvent();
|
||||
})
|
||||
.start();
|
||||
|
||||
new Thread(() -> javax.swing.SwingUtilities.invokeLater(LocalServerSelector::new)).start();
|
||||
}
|
||||
|
||||
private static void login(NetworkEvents.StartClientResponse event) {
|
||||
new Thread(
|
||||
() -> {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
new NetworkEvents.SendCommand(
|
||||
event.clientId(), "login bas"))
|
||||
.asyncPostEvent();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
})
|
||||
.start();
|
||||
javax.swing.SwingUtilities.invokeLater(LocalServerSelector::new);
|
||||
}
|
||||
|
||||
private static void initSystems() throws NetworkingInitializationException {
|
||||
new NetworkingClientManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/resources/audio/hdchirp_88k_log.wav
Normal file
BIN
app/src/main/resources/audio/hdchirp_88k_log.wav
Normal file
Binary file not shown.
@@ -0,0 +1,55 @@
|
||||
package org.toop.framework.audio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.nio.file.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AudioFilesManager {
|
||||
|
||||
private Set<String> audioFiles;
|
||||
private String audioDirectory;
|
||||
|
||||
public AudioFilesManager(String audioDirectory) throws NotDirectoryException {
|
||||
if (!audioDirectory.endsWith("/") && !audioDirectory.endsWith("\\")) {
|
||||
throw new NotDirectoryException(audioDirectory);
|
||||
}
|
||||
this.audioFiles = AudioFilesManager.getAllAudioFiles(audioDirectory);
|
||||
this.audioDirectory = audioDirectory;
|
||||
}
|
||||
|
||||
public Set<String> getAudioFiles() {
|
||||
return this.audioFiles;
|
||||
}
|
||||
|
||||
public String getAudioFile(String file) {
|
||||
if (!audioFiles.contains(file)) {
|
||||
return null;
|
||||
}
|
||||
return audioDirectory + file;
|
||||
}
|
||||
|
||||
private static Set<String> getAllAudioFiles(String audioDirectory) {
|
||||
Set<String> fileSet = new HashSet<>();
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(audioDirectory))) {
|
||||
for (Path path : stream) {
|
||||
if (!Files.isDirectory(path)) {
|
||||
String extension = "";
|
||||
|
||||
int i = path.getFileName().toString().lastIndexOf('.');
|
||||
if (i > 0) {
|
||||
extension = path.getFileName().toString().substring(i+1);
|
||||
}
|
||||
if (extension.equalsIgnoreCase("wave") || extension.equalsIgnoreCase("wav")
|
||||
|| extension.equalsIgnoreCase("mp3"))
|
||||
fileSet.add(path.getFileName()
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return fileSet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.toop.framework.audio;
|
||||
|
||||
public class AudioPlayer {
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user