📄 videoviewer.java
字号:
}
private void openFile()
{
if (fd == null)
{
// "new Frame" should really be parent's frame, but I'm not sure how
// to do it, and this seems to work anyway.
fd = new FileDialog(new Frame(), "Open File",
FileDialog.LOAD);
//fd.setDirectory("/movies");
}
fd.show();
if (fd.getFile() != null)
{
String filename = fd.getDirectory() + fd.getFile();
videoPanel.play("file:" + filename);
}
}
// Called when button is pressed
private class ControlButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
Object btn = ae.getSource();
if (btn == startButton)
{
// Start recording
int maxTime = videoControl.getMaxRecTime();
if (maxTime < MIN_RECORDING_TIME || maxTime > MAX_RECORDING_TIME)
{
showError("Please enter a time value between " + MIN_RECORDING_TIME + " and " +
MAX_RECORDING_TIME + ".");
maxRecTimeTextField.requestFocus();
maxRecTimeTextField.selectAll();
}
else
startRecording(maxTime);
}
else if (btn == stopButton)
{
if (recording)
stopRecording();
}
else if (btn == openFileButton)
openFile();
}
}
} // end VideoControlPanel class
/********************************************************************
Inner class for displaying all archived media.
********************************************************************/
class VideoArchivePanel extends JPanel
{
private JButton viewButton, deleteButton;
private JComboBox archiveLocationsComboBox;
private VideoTable videoTable = new VideoTable();
public VideoArchivePanel()
{
setLayout(new GridBagLayout());
ArchiveButtonHandler handler = new ArchiveButtonHandler();
viewButton = new JButton("View");
viewButton.addActionListener(handler);
deleteButton = new JButton("Delete");
deleteButton.addActionListener(handler);
archiveLocationsComboBox = new JComboBox();
archiveLocationsComboBox.addItemListener(
new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
Object obj = archiveLocationsComboBox.getSelectedItem();
if (obj != null)
{
archiveCurrentLocation = obj.toString();
System.out.println("call populateVideoTable with archiveCurrentLocation= "+archiveCurrentLocation);
// Get list of videos from Server for the selected location
populateVideoTable();
}
else
archiveCurrentLocation = "";
System.out.println("Selected archive location " + archiveCurrentLocation);
}
}
);
populateArchiveLocationsComboBox();
JScrollPane scrollPane = new JScrollPane(videoTable);
// GridBagConstraints(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty,
// int anchor, int fill, Insets insets, int ipadx, int ipady)
add(new JLabel("Video Archive:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NORTH, new Insets(0, 10, 10, 0), 0, 0));
add(archiveLocationsComboBox, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NORTH, new Insets(0, 10, 10, 0), 0, 0));
add(viewButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NORTH, new Insets(0, 10, 10, 0), 0, 0));
add(deleteButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NORTH, new Insets(0, 10, 10, 0), 0, 0));
add(scrollPane, new GridBagConstraints(0, 1, 5, 1, 2.0, 2.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 10, 10, 0), 0, 0));
}
// Called when button is pressed
private class ArchiveButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
Object btn = ae.getSource();
if (btn == viewButton)
{
System.out.println("viewButton");
// Get video clip from Server using RTP
int selectedRow = videoTable.getSelectedRow();
if (selectedRow == -1)
{
showError("Please select a row from the video archive table to view.");
return;
}
// Can't be watching anything now
if (watchCheckBox.isSelected())
watchCheckBox.setSelected(false);
String videoName = videoTable.getVideoName(selectedRow);
String rtp = CamController.mediaStore.getVideoStream(archiveCurrentLocation,
videoName, CamController.hostName);
videoPlaying = true;
// Use RTPSessionManager so it will know when video is no longer available
videoPanel.playRTP(rtp);
//videoPanel.play(rtp);
}
else if (btn == deleteButton)
{
//System.out.println("deleteButton");
// Delete selected video from database and from video dir
int selectedRows[] = videoTable.getSelectedRows();
if (selectedRows.length == 0)
{
showError("Please select a row from the video archive table to delete.");
return;
}
if (JOptionPane.showConfirmDialog(null,
"Are you sure you want to permanently delete the selected video(s)?",
"Cam Controller",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
// Delete all selected videos
String videoNames[] = new String[selectedRows.length];
for (int i=0; i < selectedRows.length; i++)
{
videoNames[i] = videoTable.getVideoName(selectedRows[i]);
System.out.println("About to delete: " + videoNames[i]);
}
boolean success = CamController.mediaStore.deleteVideos(archiveCurrentLocation, videoNames);
if (!success)
showError("Error encountered while trying to delete the selected video.");
}
}
}
}
public void updateLocationList(String location)
{
System.out.println("updateLocationList called");
// Add this location to combo box if it's not already there
int items = archiveLocationsComboBox.getItemCount();
boolean found = false;
for (int i = 0; i < items && !found; i++)
{
String loc = (String) archiveLocationsComboBox.getItemAt(i);
if (loc.equals(location))
found = true;
}
if (!found)
{
System.out.println("Adding new location: " + location);
archiveLocationsComboBox.addItem(location);
}
else if (archiveCurrentLocation.equals(location))
populateVideoTable(); // Add new video to the list.
}
private void populateArchiveLocationsComboBox()
{
// Location combo box- Retrieve locations from DB
if (CamController.connectedToServer)
{
String[] loc = null;
try
{
System.out.println("Retrieving archive locations from server...");
loc = CamController.mediaStore.getArchiveLocations();
if (loc.length != 0)
{
if (!loc[0].equals(""))
{
for (int i=0; i < loc.length; i++)
archiveLocationsComboBox.addItem(loc[i]);
archiveCurrentLocation = (String) archiveLocationsComboBox.getItemAt(0);
// Show videos for this location
populateVideoTable();
}
}
else
{
lblInfo.setText("No archived video available yet.");
}
}
catch (rowc.MediaStorePackage.LocationsUnavailable e)
{
System.out.println("Unable to get locations from database.");
showError("Error retrieving locations from the Server.");
}
catch (Exception e)
{
System.out.println("Unable to get locations from Server.");
e.printStackTrace();
showError("Error retrieving locations from the Server.");
}
}
}
public void populateVideoTable()
{
System.out.println("populateVideoTable called");
if (CamController.connectedToServer)
{
videoTable.populateVideoTable(archiveCurrentLocation, CamController.mediaStore);
// update UI
//videoTable.repaint();
}
}
}
/*************************************************************************************
*
* Inner class for notification of archive media events.
*
************************************************************************************/
class MediaArchiveCallbackImpl extends MediaArchiveCallbackPOA
{
public synchronized void addVideo(String location)
{
System.out.println("\nvideoAdded called for loc=" + location + "\n");
archivePanel.updateLocationList(location);
}
public synchronized void removeVideo(String location)
{
System.out.println("\nvideoDeleted called for loc=" + location + "\n");
archivePanel.updateLocationList(location);
}
}
/**************************************************************************************
*
* Inner class for callbacks when receiving notification of new/removed web cam locations.
*
*
*************************************************************************************/
public class CamControllerCallbackImpl extends rowc.CamControllerCallbackPOA
{
// Server notifying us that new web cam is available. Add it to our list of locations.
public synchronized void addWebCam(String location)
{
System.out.println("addWebCam is adding " + location + " to locations vector.");
locationsComboBox.addItem(location); // Automatically adds to locations vector
locationsComboBox.repaint();
}
// Server notifying us that web cam is no longer available. Remove from location list.
public synchronized void removeWebCam(String location)
{
System.out.println("removeWebCam removing location: " + location);
locationsComboBox.removeItem(location); // Automatically removes from locations vector
locationsComboBox.setSelectedItem(""); // Deselects item
locationsComboBox.repaint();
}
} // end CamControllerCallbackImpl class
/*************************************************************************************
Inner class for notification of new videos.
*************************************************************************************/
class CamVideoCallbackImpl extends CamVideoCallbackPOA
{
// Called by CamProcessor when video has finished recording to file and has been
// transmitted to the Server. This notifies the CamController of the new video
// so it can tell the server to store it in the database. The new video is also
// displayed in the list of archived videos.
public void newRecording(VideoClip video)
{
// Right now if location is blank, there's a problem. Could make more robust by
// throwing an exception. ORBacus doesn't like to send "null", so exceptions are the better way to go.
if (video.location.equals(""))
{
System.out.println("Error getting video from exporter.");
lblInfo.setText("Error getting video");
recording = false;
showError("Error retrieving video.");
return;
}
System.out.println("Received new video " + video.name + " from location " + video.location);
// System.out.println("isSelected="+watchCheckBox.isSelected());
// System.out.println("videoPlaying="+videoPlaying);
lblInfo.setText("");
recording = false;
// The CamProcessor sends the video to the MediaServer via sockets but
// does not tell the server to store the video since the MediaStore object
// is not accessible to the CamProcessor. It is only instantiated by the
// CamController, and that is why it is responsible for telling the server
// to store the video.
// Store new video on the Server
CamController.mediaStore.storeVideo(video);
// Tell VideoArchivePanel to repopulate if this is a new archive location
//archivePanel.updateLocationList(video.location);
}
public void videoAvailable(String url)
{
System.out.println("Video available at url: " + url);
System.out.println("isSelected="+watchCheckBox.isSelected());
System.out.println("videoPlaying="+videoPlaying);
if (watchCheckBox.isSelected() && videoPlaying == false)
{
videoPlaying = true;
videoPanel.play(url);
}
lblInfo.setText("");
}
}
} // end VideoViewer class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -