日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java jpanel 分层显示_java – 向JPanel显示视频

發(fā)布時間:2024/10/5 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java jpanel 分层显示_java – 向JPanel显示视频 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我正在創(chuàng)建一個簡單的視頻播放器,但我有問題顯示要在JPanel中流式傳輸?shù)囊曨l文件.我創(chuàng)建并設計了一個JFrame,并在表單中放置了一個方形大小的JPanel.

到目前為止,這是我的代碼:

package SoundsTrip;

import java.awt.BorderLayout;

import java.awt.Component;

import java.io.IOException;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.media.CannotRealizeException;

import javax.media.Manager;

import javax.media.NoPlayerException;

import javax.media.Player;

import javax.swing.JFileChooser;

import javax.swing.JOptionPane;

/**

*

* @author jmoreno

*/

public class VideoFrame extends javax.swing.JFrame {

/** Creates new form VideoFrame */

public VideoFrame() {

initComponents();

//this.setExtendedState(VideoFrame.MAXIMIZED_BOTH);

this.setSize(650, 500);

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

//

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

getContentPane().setLayout(null);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 450, Short.MAX_VALUE)

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 330, Short.MAX_VALUE)

);

getContentPane().add(jPanel1);

jPanel1.setBounds(10, 10, 450, 330);

jButton1.setText("Open Video/Movie");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

}

});

getContentPane().add(jButton1);

jButton1.setBounds(470, 10, 160, 23);

pack();

}//

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

try {

openMedia();

} catch (IOException ex) {

Logger.getLogger(SoundBytePlaying.class.getName()).log(Level.SEVERE, null, ex);

} catch (CannotRealizeException ex) {

Logger.getLogger(SoundBytePlaying.class.getName()).log(Level.SEVERE, null, ex);

}

}

public void openMedia() throws IOException, CannotRealizeException{

JFileChooser fileChooser = new JFileChooser();

int result = fileChooser.showOpenDialog(null);

if(result == JFileChooser.APPROVE_OPTION){

URL mediaURL = null;

try{

mediaURL = fileChooser.getSelectedFile().toURL();

}catch(MalformedURLException malformedURLException){

JOptionPane.showMessageDialog(null, "Could not create URL for the file");

}

if(mediaURL != null){

**showVideo() //some error here**

}

}

}

public void showVideo(URL mediaURL){

Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );

try{

//create a player to play the media specified in the URL

Player mediaPlayer = Manager.createRealizedPlayer( mediaURL );

//get the components for the video and the playback controls

Component video = mediaPlayer.getVisualComponent();

Component controls = mediaPlayer.getControlPanelComponent();

if ( video != null )

add( video, BorderLayout.CENTER ); //add video component

if ( controls != null )

add( controls, BorderLayout.SOUTH ); //add controls

mediaPlayer.start(); //start playing the media clip

} //end try

catch ( NoPlayerException noPlayerException ){

JOptionPane.showMessageDialog(null, "No media player found");

} //end catch

catch ( CannotRealizeException cannotRealizeException ){

JOptionPane.showMessageDialog(null, "Could not realize media player.");

} //end catch

catch ( IOException iOException ){

JOptionPane.showMessageDialog(null, "Error reading from the source.");

} //end catch

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new VideoFrame().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JPanel jPanel1;

// End of variables declaration

}

非常感謝我能得到的任何想法和幫助…… 🙂

總結

以上是生活随笔為你收集整理的java jpanel 分层显示_java – 向JPanel显示视频的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。