2009-08-07 2 views
0

JMF를 사용하여 Java 응용 프로그램에서 비디오를 재생하려고합니다. 동영상이 잘 재생되지만 동영상을 더 크게하려고합니다. 아래 코드는 격자 무늬 레이아웃이있는 다른 jpanel 안에 배치됩니다.JMF를 사용하여 비디오 크기 조정

현재 FILL 제약 조건없이 추가되어 있으므로 일반 크기로 표시해야합니다.

필 제한을 추가하면 가로 세로 비뚤어진 비디오가 늘어납니다.

나는 사람이 수동으로 영상의 크기를 조정하는 방법을 알거나 가로 세로 비율

public class VideoPanel extends JPanel{ 
private Player mediaPlayer; 
private File file; 

public VideoPanel(String videoFile, String path){ 
    setOpaque(false); 
    file = new File(path+"/video/"+videoFile); 

    URL mediaURL = null; 
    try { 
     mediaURL = file.toURI().toURL(); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } 
    setLayout(new BorderLayout());  
    Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true); 
    try{ 
     mediaPlayer = Manager.createRealizedPlayer(mediaURL); 
     Component video = mediaPlayer.getVisualComponent(); 
     Component controls = mediaPlayer.getControlPanelComponent(); 

     double scale = getScale(this.getWidth(),this.getHeight(),video.getWidth(),video.getHeight()); 

     video.setPreferredSize(new Dimension((int)scale*video.getWidth(),(int)scale*video.getHeight())); 



     if(video != null) 
      add(video,BorderLayout.CENTER); 
     if(controls != null) 
      add(controls,BorderLayout.SOUTH); 
    } 
    catch (NoPlayerException noPlayerException){ 
     System.err.println("No media player found"); 
    } 
    catch (CannotRealizeException cannotRealizeException){ 
     System.err.println("Could not realize media player"); 
    } 
    catch (IOException iOException){ 
     System.err.println("Error reading from the source"); 
    } 
} 

private double getScale(int panelWidth, int panelHeight, int imageWidth, int imageHeight) { 
    double scale = 1; 
    double xScale; 
    double yScale; 

    xScale = (double) panelWidth/imageWidth; 
    yScale = (double) panelHeight/imageHeight; 
    scale = Math.min(xScale, yScale); 
    return scale; 
} 

public void stopPlay(){  
    mediaPlayer.stop(); 
} 

}

+0

누구든지 해결 했습니까? JMF를 통해 동영상을 재생할 수 없습니다. (사실 http://fmj-sf.net/을 사용하고 있지만 API는 동일합니다.) – petersaints

답변

2

당신은 또 다른 컨테이너 패널에서 비디오 구성 요소를 throw 할 수 있습니다를 잠그는 방법 및 여부를 묻는 메신저를 추측 컨테이너에서 크기를 제어하십시오. 내 응용 프로그램에서 비디오 구성 요소를 JFrame에 설정하고 비디오의 크기를 조정하기 위해 컨테이너의 크기를 간단히 조정합니다.