2011-02-05 35 views

回答

0

我想你已經使用特殊的框架來做到這一點。例如,您可以使用Java Media Framework您可以在oracle主頁上下載它。

+3

如果檢查JMF 2.1.1 - 支持的格式(http://www.oracle.com/technetwork/java/javase/formats -138492.html)你可能會注意到「mp4」在它不在時顯眼。或者換一種說法 - JMF不支持MP4。 – 2011-02-06 02:46:53

1

「固定大小(1)JFrame」很容易,或者至少應該是。你有一個特定的問題嗎? (我問,因爲它似乎很奇怪,你應該提到它。)

至於支持MP4,JMF不會處理它。你最好的選擇是看看谷歌拋出的java+mp4。在瀏覽一些排名最高的點擊之後,看起來這些產品並不是很好。

MP4是不可改變的要求嗎? JMF可以很好地處理許多其他較簡單(較舊)的格式。

如果在標準的媒體播放器打開MP4是不是出了問題 - 這是一樣容易:

Desktop.getDesktop().open(new File("the.mp4")); 

(1),作爲最終用戶,有評論說我憎恨有人將視頻內容提供給我的桌面,無法調整大小。這是我的(當然)桌面 - 我應該能夠選擇視頻涵蓋多少內容!

1

我想你可以將你的視頻轉換成.gif文件,然後從該視頻獲取音頻並在後臺播放,它可能會降低質量,但它適用於簡單的事情。

`import java.io.File; 

import javax.sound.sampled.AudioSystem; 
import javax.sound.sampled.Clip; 
import javax.swing.ImageIcon; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 

    public class Main { 

     public static void audio() { 
      try { 
       File file = new File("audio.wav"); 
       Clip clip = AudioSystem.getClip(); 
       clip.open(AudioSystem.getAudioInputStream(file)); 
       clip.loop(Clip.LOOP_CONTINUOUSLY); 
       clip.start(); 
      } catch (Exception e) { 
       System.err.println("Put the music.wav file in the sound folder if you want to play background music, only optional!"); 
      } 
     } 


     private static String arg; 

     public static void main(String[] args){ 


     arg = "background.gif"; 
     JFrame f = new JFrame(); 
     JPanel p = new JPanel(); 
     JLabel l = new JLabel(); 
     ImageIcon icon = new ImageIcon(arg);  
     f.setSize(480, 360); 
     f.setVisible(true); 
     l.setIcon(icon); 
     p.add(l); 
     f.getContentPane().add(p); 
     f.setLocationRelativeTo(null); 
     f.setResizable(false); 
     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     audio(); 

      } 
     } 

https://www.mediafire.com/?18n4iluk9hwitlb Audio.wav

http://www.mediafire.com/view/jx7vogxzsbor0j4/background.gif Background.gif