-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaSoundExample.java
More file actions
80 lines (65 loc) · 2.66 KB
/
Copy pathJavaSoundExample.java
File metadata and controls
80 lines (65 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package java1_3.sound;
/**
* Java 1.3 JavaSound API Example Demonstrates audio capabilities
* NOTE: This is a conceptual example. Actual audio playback requires audio files.
*/
public class JavaSoundExample
{
public static void main(String[] args)
{
System.out.println("=== Java 1.3 JavaSound API ===\n");
System.out.println("JavaSound provides audio capabilities for Java applications.\n");
System.out.println("Example code structure:");
System.out.println("""
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
public class JavaSoundExample {
public static void main(String[] args) {
try {
// 1. Load audio file
File soundFile = new File("sound.wav");
AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
// 2. Get clip
Clip clip = AudioSystem.getClip();
// 3. Open audio stream
clip.open(audioIn);
// 4. Play audio
clip.start();
// 5. Wait for playback to complete
Thread.sleep(clip.getMicrosecondLength() / 1000);
// 6. Close resources
clip.close();
audioIn.close();
} catch (UnsupportedAudioFileException e) {
System.err.println("Unsupported audio file: " + e.getMessage());
} catch (IOException e) {
System.err.println("IO Error: " + e.getMessage());
} catch (LineUnavailableException e) {
System.err.println("Line unavailable: " + e.getMessage());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
""");
System.out.println("\nKey Features:");
System.out.println("- Audio playback");
System.out.println("- Audio recording");
System.out.println("- Audio format support (WAV, AIFF, etc.)");
System.out.println("- MIDI support");
System.out.println("- Sound mixing");
System.out.println("\nSupported Formats:");
System.out.println("- WAV");
System.out.println("- AIFF");
System.out.println("- AU");
System.out.println("- MIDI");
System.out.println("\nUse Cases:");
System.out.println("- Game audio");
System.out.println("- Media players");
System.out.println("- Sound effects");
System.out.println("- Music applications");
System.out.println("\nNote: This example is conceptual.");
System.out.println("Actual implementation requires audio files and proper format support.");
}
}