首页 文章

在轮播选项卡中显示不同类型的文件

提问于
浏览
1

我需要实现一个轮播来显示images / video / pdf / ppt文件 . 我使用Tab组件来实现它 . 但它没有按预期工作 . 第一个选项卡正确显示图像,但同时打开pdf文件,该文件位于第三个选项卡上 . 第二个标签视频无法播放 . 我尝试在选项卡选择上调用这些事件但仍然无效 . 我的代码如下 .

Form hi = new Form("Swipe Tabs", new LayeredLayout());

    Tabs t = new Tabs();
    t.hideTabs();

    container1 = BoxLayout.encloseY();
    container2 = BoxLayout.encloseY();
    container3 = BoxLayout.encloseY();

    InputStream is = null; 
    ImageViewer iv = null;

    try{
        is = Display.getInstance().getResourceAsStream(getClass(), "/Img1.png");
        iv = new ImageViewer(Image.createImage(is));
    }catch(Exception exc){
        exc.printStackTrace();
    }

    container1 = BoxLayout.encloseY(iv);


    FileSystemStorage fs = FileSystemStorage.getInstance();
    fs.mkdir(fs.getAppHomePath());

    String fileName = fs.getAppHomePath() + "test.mp4";

    if(!fs.exists(fileName)) {
        Util.downloadUrlToFile("http://localhost/app/test.mp4", fileName, true);
    }
    try{
        Media video = MediaManager.createMedia(fileName, true);
        video.setNativePlayerMode(true);
        container2 = BoxLayout.encloseY(new MediaPlayer(video));       
        video.play();
    }catch(Exception exc){
        exc.printStackTrace();
    }


    fs = FileSystemStorage.getInstance();
    fs.mkdir(fs.getAppHomePath());
    final String fileName1 = fs.getAppHomePath() + "file1.pdf";
    if(!fs.exists(fileName1)) {
        Util.downloadUrlToFile("http://localhost/app/file1.pdf", fileName1, true);
    }
    container3 = BoxLayout.encloseY();
    Display.getInstance().execute(fileName1);


    t.addTab("Tab1", container1);
    t.addTab("Tab2", container2);
    t.addTab("Tab3", container3);

    new ButtonGroup(firstTab, secondTab, thirdTab);
    firstTab.setSelected(true);
    Container tabsFlow = FlowLayout.encloseCenter(firstTab, secondTab, thirdTab);

    hi.add(t);
    hi.add(BorderLayout.south(tabsFlow));
    hi.show();

1 回答

  • 1

    Display.execute 启动外部查看器以显示内容 . 它不支持嵌入PDF,因为它在Android上不可用,并且在iOS上有点不稳定 . 如果您只关心iOS,可以使用 BrowserComponent 来显示PDF . 您可以使用按钮并在按下按钮时调用 execute 以显示PDF .

    改变这个:

    container2 = BoxLayout.encloseY(new MediaPlayer(video));       
        video.play();
    

    至:

    MediaPlayer mp = new MediaPlayer(video);
        container2 = mp;       
        mp.setAutoplay(true);
        mp.setLoop(true);
    

    最后,我建议使用 Log.e() 而不是 printStackTrace() .

相关问题