j2me 带有视频组件的线程

发布于 2024-12-02 12:09:21 字数 3365 浏览 2 评论 0原文

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

在此处输入图像描述

我的问题是

  1. 当我从视频播放器线程调用 quotes 线程时视频仍然在报价表单上方播放。

  2. 当我使用动作事件更改视频网址时,它只会将新播放器附加到当前播放器。 前任。当我按下视频 2 按钮

    时,video2 会与当前正在运行的 video1 一起附加。

  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();
          }
        }
     }

i have tried to implement an java app which have following structure.

enter image description here

my problems are

  1. when i invoke quotes thread from videoplayer thread the video still plays on top of the quotes form.

  2. when i change video url with action event it just appends new player with current one.
    ex. video2 is append along with currently running video1 when i press video 2 button

.

  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();
          }
        }
     }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆一缕阳光ご 2024-12-09 12:09:21

一般来说,JavaME 中的视频不保证其播放的层。 LWUIT 尝试无缝暂停视频播放器,例如 UI 顶部的对话框。

附带说明一下,LWUIT 不是线程安全的,您不能使用单独的线程来访问 UI,因为它在不同平台上会中断

Generally video in JavaME makes no guarantee to the layer in which it is playing. LWUIT tries to seamlessly pause video player for things like a dialog on top of the UI.

As a side note LWUIT is not thread safe and you must not use a separate thread to access the UI since it will break on different platforms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文