0

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();
          }
        }
     }
ArK
  • 20,698
  • 67
  • 109
  • 136

1 Answers1

2

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • thanks shai. do you have any other suggestion for this scenario which may help me to improve it. – ArK Sep 05 '11 at 04:48
  • Try reading about the EDT, you can use threads freely but make sure to mutate LWUIT only from the LWUIT thread which you can reach using Display.callSerially(). You can also create more dynamic code using invokeAndBlock but that is a subject of its own (read about it in the blog). Googling for LWUIT EDT should get you pretty far. – Shai Almog Sep 05 '11 at 07:54