⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playerpanel.java

📁 FMJ(freedom media for java)是java视频开发的新选择
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package net.sf.fmj.ui.application;import java.awt.BorderLayout;import java.awt.Container;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Frame;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.SystemColor;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.util.logging.Level;import java.util.logging.Logger;import javax.media.MediaLocator;import javax.media.format.AudioFormat;import javax.media.protocol.FileTypeDescriptor;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JToolBar;import javax.swing.SwingUtilities;import net.sf.fmj.ui.control.TransportControlPanel;import net.sf.fmj.ui.dialogs.RTPReceivePanel;import net.sf.fmj.ui.dialogs.URLPanel;import net.sf.fmj.ui.wizards.RTPTransmitWizard;import net.sf.fmj.ui.wizards.TrackConfig;import net.sf.fmj.ui.wizards.TranscodeWizard;import net.sf.fmj.utility.LoggerSingleton;import net.sf.fmj.utility.PathUtils;import net.sf.fmj.utility.URLUtils;/** *  * @author Warren Bloomer * */public class PlayerPanel extends JPanel {	private static final Logger logger = LoggerSingleton.logger;	private PlayerPanelPrefs prefs;		private JToolBar playerToolBar = null;	private JButton openButton = null;	private JButton openCaptureDeviceButton = null;	private TransportControlPanel transportControlPanel = null;	private JLabel statusBar = null;	private JPanel videoPanel = null;	private JComboBox addressComboBox = null;	private JButton loadButton = null;	private JPanel addressPanel = null;	private JLabel locationLabel = null;	private ContainerPlayer containerPlayer = null;  //  @jve:decl-index=0:visual-constraint="557,162"	public void addMediaLocatorAndLoad(String url) {		boolean alreadyThere = false;		for (int i = 0; i < getAddressComboBox().getItemCount(); ++i)		{	if (getAddressComboBox().getItemAt(i).equals(url))			{				alreadyThere = true;				break;			}		}		if (!alreadyThere)		{	getAddressComboBox().addItem(url);		}				if (getAddressComboBox().getSelectedItem() == null || !getAddressComboBox().getSelectedItem().equals(url))			getAddressComboBox().setSelectedItem(url);	// will auto-load		else			onLoadButtonClick();	// already selected	}			/**	 * This method initializes videoPanel		 * 		 * @return javax.swing.JPanel		 */	public JPanel getVideoPanel() {		if (videoPanel == null) {			videoPanel = new JPanel();						videoPanel.setLayout(new BorderLayout());			//videoPanel.setLayout(new FlowLayout(FlowLayout.CENTER));		    //TitledBorder	        //mediaBorder = new TitledBorder(	        //    BorderConstants.etchedBorder, "Media" );			//videoPanel.setBorder(mediaBorder);	        			videoPanel.setBackground(SystemColor.controlShadow);		}		return videoPanel;	}	/**	 * This method initializes addressComboBox		 * 		 * @return javax.swing.JComboBox		 */	private JComboBox getAddressComboBox() {		if (addressComboBox == null) {			addressComboBox = new JComboBox();			addressComboBox.setEditable(true);			addressComboBox.setPreferredSize(new Dimension(160, 27));			for (int i=0; i<prefs.recentUrls.size(); i++) {				addressComboBox.addItem((String) prefs.recentUrls.get(i));			}			addressComboBox.setSelectedIndex(-1);	// nothing selected by default.						// load an item when selected from the list 			addressComboBox.addItemListener(					new ItemListener() {						public void itemStateChanged(ItemEvent e) {							// TODO: typing in the combo and clicking load... causes this event to fire, plus loads from clicking load.							// TODO: typing in the combo and clicking tab, causes this event to fire.							logger.fine("addressComboBox state change: " + e);							if (e.getStateChange() == ItemEvent.SELECTED)								onLoadButtonClick();						}					}				);		}		return addressComboBox;	}	/**	 * This method initializes loadButton		 * 		 * @return javax.swing.JButton		 */	private JButton getLoadButton() {		if (loadButton == null) {			loadButton = new JButton();			loadButton.setToolTipText("Load selected location");			loadButton.setIcon(new ImageIcon(getClass().getResource("/net/sf/fmj/ui/images/import_wiz.png")));			loadButton.addActionListener(new java.awt.event.ActionListener() {				public void actionPerformed(java.awt.event.ActionEvent event) {					onLoadButtonClick();				}			});		}		return loadButton;	}		private void onLoadButtonClick()	{						String location = (String) getAddressComboBox().getSelectedItem();				if (location.trim().equals(""))		{			showError("No URL specified");			return;		}				setCursor(new Cursor(Cursor.WAIT_CURSOR));				try {			getContainerPlayer().setMediaLocation(location, prefs.autoPlay);		}		catch (Throwable e) {						logger.log(Level.WARNING, "" + e, e);			showError("" + e);	// normally we would just want e.getMessage(), but in many cases this can be blank, like a NoPlayerException.								// for now we'll just include the whole thing which includes the class.  A better way would be to 								// translate an empty NoPlayerException into "Player not found" - which BTW isn't that sensible to a user not familiar with JMF...												return;		}		finally		{			setCursor(new Cursor(Cursor.DEFAULT_CURSOR));		}				// update prefs with new URL		if (!prefs.recentUrls.contains(location))		{	prefs.recentUrls.add(0, location);			savePrefs();		}		else		{			// in list, make sure it is first.			if (!prefs.recentUrls.get(0).equals(location))			{				// not in first position.  remove and re-add at head.				prefs.recentUrls.remove(location);				prefs.recentUrls.add(0, location);				savePrefs();			}		}	}		private void showError(String e)	{		JOptionPane.showConfirmDialog(this, e, "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);					}			/**	 * This method initializes addressPanel		 * 		 * @return javax.swing.JPanel		 */	private JPanel getAddressPanel() {		if (addressPanel == null) {			locationLabel = new JLabel();			locationLabel.setText("Location:");			addressPanel = new JPanel();			addressPanel.setLayout(new GridBagLayout());			//addressPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));			GridBagConstraints c1 = new GridBagConstraints();			c1.insets = new Insets(0, 2, 0, 2);			addressPanel.add(locationLabel, c1);			GridBagConstraints c2 = new GridBagConstraints();			c2.fill = GridBagConstraints.HORIZONTAL;			c2.weightx = 1.0;			c2.insets = new Insets(0, 2, 0, 2);			addressPanel.add(getAddressComboBox(), c2);			//GridBagConstraints c3 = new GridBagConstraints();			//addressPanel.add(getLoadButton(), c1);					}		return addressPanel;	}	/**	 * This method initializes containerPlayer		 * 		 * @return net.sf.fmj.ui.application.ContainerPlayer		 */	private ContainerPlayer getContainerPlayer() {		if (containerPlayer == null) {			containerPlayer = new ContainerPlayer(getVideoPanel());			containerPlayer.setAutoLoop(prefs.autoLoop);			containerPlayer.setContainerPlayerStatusListener(new ContainerPlayerStatusListener() {				public void onStatusChange(final String newStatus)				{					logger.fine("Status change: " + newStatus);						SwingUtilities.invokeLater(new Runnable() {						public void run()						{							statusBar.setText(newStatus);						}					});									}							});		}		return containerPlayer;	}	/**	 * This method initializes 	 * 	 */	public PlayerPanel() {		super();		initialize();	}	/**	 * This method initializes this

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -