Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

Any simple (and up to date) Java frameworks for embedding movies within a Swing Application?

I am building a small Swing application that I would like to embed a movie within. Importantly, this application is a WebStart application - and the library should be able to be packaged within the jnlp that I launch -i.e, not dependent on native libraries.

I am aware of and have tried JMF but the format compatibility I believe to be relatively poor when compared to other frameworks out there.

Could someone please provide a sample code snippet of a simple implementation using their recommended library?

Many thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Some considerations for JavaFX as a solution as a Java based media playback framework.

  1. As of Jdk7u4, JavaFX is co-bundled with the jdk for Mac and Windows (XP, Vista, 7, 32 and 64 bit).
  2. JavaFX can be embedded in a Swing App.
  3. JavaFX includes native libraries, but any Java Framework is going to need native libraries to do video well.
  4. A comprehensive deployment toolkit is included with the JavaFX SDK and/or includes the ability to generate jnlp based deployments.
  5. JavaFX 2.1 supports vp6 encoded flvs (older format) as well as some more modern and oft-used encoding formats such as mp4/aac/mp3.
  6. JavaFX only supports limited media codecs and container formats, e.g. if you have a codec installed on your machine and can play a file encoded in that format in, for example chrome, windows media player, or flash that does not guarantee that the same file will play in JavaFX.
  7. Playback of mp4 on XP or Linux requires a user to manually install the necessary codec, but other platforms (osx, win7, vista) do not require manual mp4 codec install.
  8. Use of JavaFX on a mac requires the user to use OpenJDK 7 for Mac, not the Apple JDK.
  9. JavaFX support for jnlp launched apps on Macs won't be available until later this year (2012) and similarly for Linux.
  10. You could probably bundle the entire JavaFX platform with your app in a jnlp (though I haven't seen anybody do that yet).
  11. The recommended method for a jnlp deployment would be to add a specification of a minimum JavaFX environment to the jnlp and have the JavaFX deployment toolkit and webstart take care of ensuring that it was present and installed correctly on the user's machine.
  12. Interaction between Swing and JavaFX requires some inconvenience and care around threading and also a slightly different app launching code between Swing and JavaFX. Some people have complained about this on forums, most don't seem to have had too many issues.
  13. For better or for worse (I believe better), JavaFX is likely the only media and client development framework from Oracle which is receiving ongoing major development and new features.
  14. Eventually (this year or next) JavaFX will included in all new Java runtimes for all major consumer platforms which run modern versions of Java SE.
  15. Community support for development in JavaFX from Oracle and 3rd parties is (I believe) good.

Here is a sample JavaFX app which plays a video:

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class VideoPlayerExample extends Application {
  public static void main(String[] args) throws Exception { launch(args); }
  @Override public void start(final Stage stage) throws Exception {
    final MediaPlayer oracleVid = new MediaPlayer(
      new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv")
    );
    stage.setScene(new Scene(new Group(new MediaView(oracleVid)), 540, 208));
    stage.show();

    oracleVid.play();
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...