Repository navigation
Expand file tree
/
Copy pathMediaApplet.java
More file actions
78 lines (68 loc) · 2.85 KB
/
Copy pathMediaApplet.java
File metadata and controls
78 lines (68 loc) · 2.85 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
import java.applet.Applet;
import java.awt.*;
import java.net.URL;
/*
<applet code="MediaApplet" width="400" height="300">
<param name="imageURL" value="your_image.jpg">
<param name="audioURL" value="your_audio.wav">
<param name="videoURL" value="your_video.mp4">
</applet>
*/
public class MediaApplet extends Applet {
private Image image;
private AudioClip audioClip;
private URL videoURL;
@Override
public void init() {
try {
// Load Image
String imagePath = getParameter("imageURL");
if (imagePath != null && !imagePath.isEmpty()) {
URL imageURL = new URL(getDocumentBase(), imagePath);
image = getImage(imageURL);
}
// Load Audio
String audioPath = getParameter("audioURL");
if (audioPath != null && !audioPath.isEmpty()) {
URL audioURL = new URL(getDocumentBase(), audioPath);
audioClip = getAudioClip(audioURL);
}
// Load Video URL (Applets have limited built-in video support)
String videoPath = getParameter("videoURL");
if (videoPath != null && !videoPath.isEmpty()) {
videoURL = new URL(getDocumentBase(), videoPath);
// For actual video playback in a modern web environment,
// you'd typically use HTML5 <video> tag or external libraries.
System.out.println("Video URL loaded: " + videoURL);
// Displaying video directly in a simple Applet is complex.
// We'll just load the URL for demonstration.
}
} catch (Exception e) {
System.err.println("Error loading media: " + e.getMessage());
}
}
@Override
public void paint(Graphics g) {
// Display Image
if (image != null) {
g.drawImage(image, 10, 10, this);
} else {
g.drawString("Image not loaded.", 10, 30);
}
// Provide a button to play audio
if (audioClip != null) {
Button playButton = new Button("Play Audio");
playButton.setBounds(10, 50 + (image != null ? image.getHeight(this) : 0), 100, 30);
add(playButton);
playButton.addActionListener(e -> audioClip.play());
} else {
g.drawString("Audio not loaded.", 10, 80 + (image != null ? image.getHeight(this) : 0));
}
// Indicate video URL (actual playback requires more complex handling)
if (videoURL != null) {
g.drawString("Video URL loaded. Playback requires external handling.", 10, 110 + (image != null ? image.getHeight(this) : 0));
} else {
g.drawString("Video not loaded.", 10, 140 + (image != null ? image.getHeight(this) : 0));
}
}
}