Question 1: Write a Java program that plays a video clip of a concert or opera p
ID: 3832822 • Letter: Q
Question
Question 1:
Write a Java program that plays a video clip of a concert or opera performance.
Requirements:
Upon running the program a theater curtain is displayed
When the user clicks on the curtain, the curtain opens and a video clip of the concert/opera performance (complete with sound) begins.
It is acceptable to have a working console with a start, pause and stop button displayed at the bottom of the video clip, after the curtain opens.
You may need the following to complete the answer to this question:
A. An installation of the Java Media Framework (JMF). This is a Java library that enables audio, video and other time-based media to be added to Java applications and applets. You can find the appropriate links in the slides (see Presentation2.pdf above)
You have a number of ways to solve the question 1 problem. These are listed in the slides. The easiest way is probably writing a "batch file."
SOMEONE PLEASE HELP ME! I HAVE SOME FILES THAT GO ALONG WITH THIS AS WELL!
Explanation / Answer
The main required thing for running this program is that you need to setup the Java Media Framework. It enables you too play the music, pause and stop it whenever you feel to do so.
I have written the program which helps you too play the video clip of any performance. I have included the comments also for each part of the code.
Program:-
// The import statements are comprises of many classes and methods.
import java.awt.Component;
import java.io.IOException;
import java.awt.BorderLayout;
import java.net.URL;
import javax.swing.JPanel;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.Player;
import javax.media.NoPlayerException;
// Created a class by extending the Jpanel functionality
public class playVideoClip extends JPanel {
public playVideoClip(URL mediaURL) {
setLayout(new BorderLayout());
// It is a pre-defined for making it Light weight and smooth running of the performance
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
// Always use a try- catch block for checking the exception
try {
// You can place the mediapath at the top
Player setMediaPlayback = Manager.createRealizedPlayer(mediaURL);
// The component object is used to enhance the pre-defined methods of playback controls
Component setVideoPath = setMediaPlayback.getVisualComponent();
Component setControlsPlay = setMediaPlayback.getControlPanelComponent();
// It will check the Video path exist or not.
if (setVideoPath != null)
add(setVideoPath, BorderLayout.CENTER);
if (setControlsPlay != null)
add(setControlsPlay, BorderLayout.SOUTH);
// The music will start over here
setMediaPlayback.start();
}
// The catch block contains the NoPlayerException
catch (NoPlayerException noPlayerException) {
System.err.println("Sorry. I don't find any media player. Please Try Again");
}
catch (CannotRealizeException cannotRealizeException) {
System.err.println("This is not the format of the Media Player. Try a Different Media.");
}
catch (IOException iOException) {
System.err.println("You have witnessed the Error. Sorry for the Inconvenience");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.