0

我试图实现一个具有以下结构的java应用程序。

在此处输入图像描述

我的问题是

  1. 当我从 videoplayer 线程调用引号线程时,视频仍然在引号表单的顶部播放。

  2. 当我使用动作事件更改视频 url 时,它只会将新播放器附加到当前播放器。前任。当我按下视频 2 按钮时,视频 2 与当前正在运行的视频 1 一起附加

.

  class VideoPlayer implements Runnable,ActionListener{
      private videoappMidlet MIDlet;
      VideoComponent vc;
      Button Videos,quotes,video1,video2,video3;
      Form videoplayer;
      Thread thread;
      public VideoPlayer(videoappMidlet MIDlet){
        this.MIDlet = MIDlet;
      }

      public void run(){
      try{
        videoplayer=new Form();
        video1=new Button("video1");
        .......

        vc = VideoComponent.createVideoPeer("http://localhost/video1.mpg");
        vc.start();

        quotes.addActionListener((ActionListener) this);
        ........

        videoplayer.addComponent(vc);
        ........

        videoplayer.show();

       }catch(Exception error){
        System.err.println(error.toString());
       }
      }

      public void start(){
       thread = new Thread(this);
       try{ thread.start();}
       catch(Exception error){}
      }

      public void actionPerformed(ActionEvent ae) {
          if((ae.getSource()==Quotes))
          {
              Quotes tp = new Quotes(this.MIDlet);
              tp.start();
          }
          if(ae.getSource()==video1)
          {
                try {
                    vc = VideoComponent.createVideoPeer("http://localhost/video1.mpg");
                    vc.start();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
          }
          ....
      }

    }


    class Quotes implements Runnable,ActionListener {
      private videoappMidlet MIDlet;
      Button Videos,quotes;
      Form quote;
      Thread thread;
      public Quotes(videoappMidlet MIDlet){
        this.MIDlet = MIDlet;
      }

      public void run(){
      try{
        quote=new Form();
        Videos=new Button("Videos");
        ........

        quote.addComponent(Videos);
        ........

        Videos.addActionListener(this);
        ........

        quote.show();
       }catch(Exception error){
        System.err.println(error.toString());
       }
      }

      public void start(){
       thread = new Thread(this);
       try{ thread.start();}
       catch(Exception error){}
      }

      public void actionPerformed(ActionEvent ae) {
          if(ae.getSource()==Videos)
          {
             VideoPlayer vp = new VideoPlayer(this.MIDlet);
             vp.start();
          }
      }
    }


    public class videoappMidlet extends MIDlet implements ActionListener{
        Button play,quote;
        Form home;
        public void startApp() {
            Display.init(this);
            home=new Form();

            play.addActionListener(this);
            quote.addActionListener(this);
            home.show();
        }
        public void actionPerformed(ActionEvent ae) {     
          if(ae.getSource()==play)
          {
            VideoPlayer vp = new VideoPlayer(this);
            vp.start();
          }
          if(ae.getSource()==quote)
          {
            Quotes tp = new Quotes(this);
            tp.start();
          }
        }
     }
4

1 回答 1

2

JavaME 中的视频通常不保证它正在播放的层。LWUIT 尝试无缝暂停视频播放器,例如 UI 顶部的对话框。

作为旁注,LWUIT 不是线程安全的,您不能使用单独的线程来访问 UI,因为它在不同的平台上中断。

于 2011-09-04T11:20:15.690 回答