开发者

j2me Threading with video component

开发者 https://www.devze.com 2023-04-01 06:46 出处:网络
i have tried to implement an java app which have following structure. my problems are when i invoke quotes thread from videoplayer thread the video still plays on top of the quotes form.

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

j2me Threading with video component

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(ActionEve开发者_开发知识库nt 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();
          }
        }
     }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消