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

前端 未结 3 774
执笔经年
执笔经年 2020-11-29 10:59

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 t

相关标签:
3条回答
  • 2020-11-29 11:07

    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();
      }
    }
    
    0 讨论(0)
  • 2020-11-29 11:11

    Although I have not had any problems with formats compatibility o JMF you can take a look in JavaFX that was designed to be a competitor to Flash, so should support all media formats and codecs. You can also embed Flash player into java application using JNI/JNA but it seems too complicated. I'd recommend you to start with JMF and look for other solution only if you really have problems.

    0 讨论(0)
  • 2020-11-29 11:18

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

    You are right about the lack of support for modern codecs, but it works just fine for older codecs. It might be a viable option if:

    1. You control the format (as opposed to the user opening 'any old video' in it). Which you apparently do.
    2. Bandwidth is not a huge problem. The more modern codecs improved compression markedly.

    While the 'performance pack' version of the JMF which uses natives supports more formats, the core Java JMF API also provides some basic formats.

    0 讨论(0)
提交回复
热议问题