【问题标题】:Unable to play swf file using Transform API无法使用转换 API 播放 swf 文件
【发布时间】:2014-06-30 20:09:47
【问题描述】:

我尝试使用 Transform API Transform SWF for Java 播放 swf 文件,但失败了。我厌倦了 movie.decodeFromFile()、loadMovieNum() 等。

Movie movie = new Movie();
movie.add(Place2.show(2, 3, 2, 2));

//movie.decodeFromFile(new File("test.swf"));
loadMovieNum("test.swf",1); 

如果我能找到此任务的示例代码,那就太好了。

(更新)

@Josef:您刚刚从网站复制/粘贴代码。其实我想知道如何只播放一个 swf 文件。该代码包含播放 swf 文件不需要的其他不必要的东西,如字体、字体颜色等。

我认为只有以下语句与播放swf文件有关-

Movie movie = new Movie();
movie.add(Place2.show(text.getIdentifier(), layer++, xpos, ypos));
movie.add(ShowFrame.getInstance());
movie.encodeToFile("example.swf");

但我的问题是——我应该不需要使用 JPlane 来添加这个电影对象来播放 swf 文件吗?

【问题讨论】:

    标签: java swing flash


    【解决方案1】:

    以下是使用变换播放swf 的示例:

    int uid = 1;
    int layer = 1;
    
    final String str = "The quick, brown fox jumped over the lazy dog."
    final Color color = WebPalette.BLACK.color();
    
    final String fontName = "Arial";
    final int fontSize = 24;
    final int fontStyle = java.awt.Font.PLAIN;
    
    // Load the AWT font.
    final AWTDecoder fontDecoder = new AWTDecoder();
    fontDecoder.read(new java.awt.Font(fontName, fontStyle, fontSize));
    final Font font = fontDecoder.getFonts().get(0);
    
    // Create a table of the characters displayed.
    final CharacterSet set = new CharacterSet();
    set.add(str);
    
    // Define the font containing only the characters displayed.
    DefineFont2 fontDef = font.defineFont(uid++, set.getCharacters());
    
    // Generate the text field used for the button text.
    final TextTable textGenerator = new TextTable(fontDef, fontSize * 20);
    DefineText2 text = textGenerator.defineText(uid++, str, color);
    
    // Set the screen size to match the text with padding so the
    // text does not touch the edge of the screen.
    int padding = 1000;
    int screenWidth = text.getBounds().getWidth() + padding;
    int screenHeight = text.getBounds().getHeight() + padding;
    
    // Position the text in the center of the screen.
    final int xpos = padding / 2;
    final int ypos = screenHeight / 2;
    
    MovieHeader header = new MovieHeader();
    header.setFrameRate(1.0f);
    header.setFrameSize(new Bounds(0, 0, screenWidth, screenHeight));
    
    // Add all the objects together to create the movie.
    Movie movie = new Movie();
    movie.add(header);
    movie.add(new Background(WebPalette.LIGHT_BLUE.color()));
    movie.add(fontDef);
    movie.add(text);
    movie.add(Place2.show(text.getIdentifier(), layer++, xpos, ypos));
    movie.add(ShowFrame.getInstance());
    
    movie.encodeToFile("example.swf");
    


    编辑

    Embed .swf file to JFrame

    希望有帮助!

    【讨论】:

    • 你能告诉我如何在 Swing JFrame 中播放 swf 文件吗?
    • @user3717550 我为你添加了答案链接:)
    • 谢谢 Josef 这些看起来都很复杂。能否请您展示如何在 JFrame 中使用 Transform API 来嵌入 swf?
    猜你喜欢
    • 2012-09-15
    • 2012-01-26
    • 1970-01-01
    • 2013-04-24
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多