这是我的Flash
Player,改编自其网站上的示例。BCframe本质上是一个JInternalframe。您可以扩展它。它需要稍作修改才能起作用,但应该向前迈进。您可以剔除任何不存在的内容。
其他可能的解决方案是:
jffmpeg-搜索它
http://www.humatic.de/htools/dsj/samplepre.php?WebM.java
http://pre.google.com/p/gstreamer-java/
http ://www.xuggle.com/xuggler/
http://www.theregister.co.uk/2010/08/20/flash_in_java/
package Components.FlashPlayer;import Components.BCframe;import GUI.BCApp.DataTypeEnum;import Logging.LogRunner;import Properties.Basic.FlashPlayer_Prop;import XMLProcessing.Helpers.XMLActionInfoHolder;import XMLProcessing.XMLUtilities;import java.awt.*;import java.awt.event.*;import java.util.ArrayList;import java.util.HashMap;import javax.swing.*;import javax.swing.filechooser.FileFilter;import java.io.*;// import the JFlashPlayer packageimport com.jpackages.jflashplayer.*;import java.net.URL;import org.w3c.dom.document;import org.w3c.dom.Element;public class FlashPlayer extends BCframe implements FlashPanelListener { FlashPanel flashPanel; final Label currentframeLabel = new Label("frame: N/A"); final JProgressBar progressBar = new JProgressBar(); JButton playButton,stopButton,forwardButton,rewindButton,backButton; JCheckBox loopCheckBox; private boolean isMovieSet = false; frameMonitorThread fmt; boolean loop = false; boolean playonStart = true; public enum Actions { Loop, Stop, Play } public FlashPlayer() { } public FlashPlayer(int x, int y, GUI.Window mainWindow) { this(x, y, 600, 400, mainWindow); } public FlashPlayer(int x, int y, int w, int h, GUI.Window mainWindow) { super(x, y, w, h, mainWindow); initComponents(); this.getContentPane().setLayout(new BorderLayout()); createButtons(); addCurrCompSetter(flashPanel,progressBar,currentframeLabel,playButton,stopButton,forwardButton,rewindButton,loopCheckBox,backButton); } @SuppressWarnings("unchecked") // private void initComponents() { videoPanel = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); videoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("")); javax.swing.GroupLayout videoPanelLayout = new javax.swing.GroupLayout(videoPanel); videoPanel.setLayout(videoPanelLayout); videoPanelLayout.setHorizontalGroup( videoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 381, Short.MAX_VALUE) ); videoPanelLayout.setVerticalGroup( videoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 247, Short.MAX_VALUE) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(videoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(videoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// // Variables declaration - do not modify private javax.swing.JPanel videoPanel; // End of variables declaration public void FSCommand(String command, String arg) { System.out.println("FlashPlayer (ignoring): FSCommand event received: " + command + " " + arg); } private void creatFlashPlayerWorker() { // add the FlashPanel to the frame this.getContentPane().add(flashPanel, BorderLayout.CENTER); // specify the object for Flash ExternalInterface.call events to search for the called method on flashPanel.setFlashCallObject(this); // specify the FlashPanelListener in case a movie is using the older FSCommand event flashPanel.addFlashPanelListener(this); // specify variables for a flash movie which are available from the start of the // movie as long as this is called before the FlashPanel is visible flashPanel.setVariables("myGreeting=hi&myNumber=1&myVar=good%20job"); isMovieSet = true; centerAndDisplay(); fmt = new frameMonitorThread(flashPanel); fmt.start(); revalidate(); if(!playOnStart) { stop(); } setLoop(loop); } public void createFlashPanel(String url) { // install Flash 10 if Flash 6 or greater is not present //FlashPanel.installFlash("6"); dataSource = dataSource.url; setData("Path",url.toString()); String flashVersionRequired = "9"; try { FlashPanel.setRequiredFlashVersion(flashVersionRequired); flashPanel = new FlashPanel(new URL(url));//new File(flashFilePath)); } catch (JFlashLibraryLoadFailedException e) { exitError("A required library (DLL) is missing or damaged."); } catch(JFlashInvalidFlashException e) { exitError("Required version " + flashVersionRequired + " of Flash is not installed. "); } catch (Exception e) { exitError("Something went wrong!n" + e.toString()); } creatFlashPlayerWorker(); } public void createFlashPanel(File file) { // install Flash 10 if Flash 6 or greater is not present //FlashPanel.installFlash("6"); //http://samples.mplayerhq.hu/SWF/flash_adpcm_testfiles/stereo_22.swf dataSource = dataSource.file; setData("Path",file.getAbsolutePath()); String flashVersionRequired = "9"; try { FlashPanel.setRequiredFlashVersion(flashVersionRequired); flashPanel = new FlashPanel(file);//new File(flashFilePath)); } catch (JFlashLibraryLoadFailedException e) { exitError("A required library (DLL) is missing or damaged."); } catch(JFlashInvalidFlashException e) { exitError("Required version " + flashVersionRequired + " of Flash is not installed. "); } catch (Exception e) { exitError("Something went wrong!n" + e.toString()); } creatFlashPlayerWorker(); } public boolean isMovieSet() { return isMovieSet; } public boolean isPlayonStart() { return playOnStart; } public boolean isLoop() { return loop; } public void setPlayonStart(boolean dis) { playonStart = dis; } public void setIsLoop(boolean dis) { loop = dis; } public void setMovie(URL url) { if(!isMovieSet) { createFlashPanel(url.toString()); return; } setData("Path",url.toString()); dataSource = dataSource.url; flashPanel.setMovie(url); } public void setMovie(String url) { if(!isMovieSet) { createFlashPanel(url); return; } setData("Path",url); dataSource = dataSource.url; try { flashPanel.setMovie(new URL(url)); revalidate(); } catch(Exception e) { LogRunner.dialogMessage(this.getClass(),"Could not play Flash Movie at " + url); } } public void setMovie(File file) { setData("Path",file.getAbsolutePath()); //setting this to absolute path might cause a problem dataSource = dataSource.file; try { if(isMovieSet) { flashPanel.setMovie(file); } else { createFlashPanel(file); } } catch(Exception e) {LogRunner.dialogMessage(this.getClass(),"Could not play Flash Movie at " + file); } } public void play() { flashPanel.play(); } public void stop() { flashPanel.stop(); } public void rewind() { rewind(1); } public void rewind(int numberOfframes) { for(int i = 0; i < numberOfframes; i++) { flashPanel.back(); } } public void forward() { forward(1); } public void forward(int numberOfframes) { for(int i = 0; i < numberOfframes; i++) { flashPanel.forward(); } } public void goBackToBegining() { flashPanel.rewind(); } public void backgroundAction(Color c) { flashPanel.setBackground(c); } void setLoop(boolean loop) { flashPanel.setLoop(loop); } void createButtons() { JPanel buttonPanel = new JPanel(); buttonPanel.setAlignmentX(Component.CENTER_ALIGNMENT); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); playButton = new JButton("Play"); playButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { play(); } }); buttonPanel.add(playButton); JButton stopButton = new JButton("Pause"); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { stop(); } }); buttonPanel.add(stopButton); backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { goBackToBegining(); } }); buttonPanel.add(backButton); forwardButton = new JButton("Forward"); forwardButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { forward(); } }); //buttonPanel.add(forwardButton); rewindButton = new JButton("Rewind"); rewindButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { rewind(); } }); buttonPanel.add(rewindButton); loopCheckBox = new JCheckBox("Loop"); loopCheckBox.setSelected(true); loopCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setLoop(loopCheckBox.isSelected()); } }); progressBar.setVisible(true); buttonPanel.add(progressBar); for (int i = 0; i screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } //this.setLocation((screenSize.width - frameSize.width) / 2, // (screenSize.height - frameSize.height) / 2); this.setVisible(true); //this.toFront(); } @Override protected void createProperties() { properties = new FlashPlayer_Prop(this); } @Override public void action(Enum a) { } @Override public Enum convertStringToActionEnumValue(String in) { return null; } @Override public void build(HashMap theDictionary, String filePath, String DataSource, ArrayList actions) { if(DataSource.equals(DataTypeEnum.url.toString())) { createFlashPanel((String) theDictionary.get("Path")); setDataSource(DataTypeEnum.url); } else { String theFile = XMLUtilities.parseFilePath(filePath) + File.separator + (String) theDictionary.get("Path"); createFlashPanel(new File(theFile)); setDataSource(DataTypeEnum.file); } playonStart = Boolean.parseBoolean(theDictionary.get("PlayOnStart")); loop = Boolean.parseBoolean(theDictionary.get("Loop")); //add actions to the component setActions(XMLUtilities.getActions(this, actions)); } @Override public Element extractData(document dom) { setData("PlayOnStart",Boolean.toString(playOnStart)); setData("Loop", Boolean.toString(loop)); return super.extractData(dom); } @Override public File[] extractFiles(String filePath) { File retVal = new File(getData("Path")); if(retVal == null) { return null; } setData("Path","files" + File.separator + retVal.getName()); return new File[]{retVal}; } @Override public void drag(File[] theFiles) { //if they dragged a one file in if(theFiles.length == 1) { //try and set it as the image of this component setMovie(new File(theFiles[0].getAbsolutePath())); } //they dragged multiple files in else { for(int i = 0; i < theFiles.length; i++) { int location = (i * 5) % mainWindow.getComponentContentPane().getHeight(); FlashPlayer temp = new FlashPlayer(location,location , mainWindow); temp.createFlashPanel(new File(theFiles[i].getAbsolutePath())); mainWindow.getCurrPage().addComponent(temp); mainWindow.getCurrPage().loadPage(); } } } @Override public BCframe copy(int x, int y) { try { FlashPlayer clone = new FlashPlayer(x,y,this.getWidth(),this.getHeight(),mainWindow); clone.setTitleBarVisible(this.isTitleBarRemoved()); clone.setActions(this.getActions()); if(dataSource == dataSource.file) { clone.setMovie(new File(this.getData("Path"))); } else { clone.setMovie(this.getData("Path")); } clone.setPlayonStart(isPlayonStart()); clone.setIsLoop(isLoop()); return clone; } catch(Exception e) { LogRunner.dialogMessage(this.getClass(),"Cant clone this compoenent"); } return null; } class frameMonitorThread extends Thread { FlashPanel flashPanel; frameMonitorThread(FlashPanel fp) { flashPanel = fp; } public void run() { while (true) { if (flashPanel != null) { final long currentframe = flashPanel.getCurrentframe(); final long totalframes = flashPanel.getTotalframes(); SwingUtilities.invokeLater(new Runnable() { public void run() { double cf = currentframe; double tf = totalframes; double result = cf/tf; int percent = (int)(100 * result); try{progressBar.setValue(percent);}catch(Exception e){} currentframeLabel.setText("frame: " + currentframe + "/" + totalframes); } }); } try { Thread.sleep(100); } catch (Exception e) { } } } } public static boolean checkDlls() { String systemFolder = "C:\WINDOWS\system32\"; String [] dlls = new String[]{"atl2k.dll","atl98.dll","jflash.dll"}; for(String x : dlls) { if(!new File(systemFolder + x).exists()) { return false; } } return true; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)