星期五 四月 25, 2008

 


In this Demo, I introduced how to play multi-media resources using Mobility Package in Netbeans.The development enviorment are: NetBeans 5.5.1, Mobility Package


1.Display Picture


It is easy to display pictures in MobilePhone using NetBeans event without writing one code. Tha main steps are:


1) Put the pictures to the ~~/src/ folder in the program.


2) Add a Image resource ,and set the resource path as one picture resource.


3) Add a ImageItem to the form, and set the image as the images in the resources.


Run the porgram and we can find the picture has been displayed.


 


2.Play Audio


MMAPT is a option package in J2ME, which provides a standard API that can display some media based on time, such as audio and video.


In this Demo I use the MMAPI1.1, and it can support the follow media type:


MIME Type                                     Description


audio/midi                                        MIDI file


audio/sp-midi                                          MIDI


audio/x-tone-seq                              MIDP2.0


audio/x-wav                                      WAV PCM


image/gif                                          FIG89a


video/mpeg                                      MPEG


video/vnd.sun.rgb565                      video record


It can not support other media type such as MP4 ,3gp, but it is believe that the day will be coming.


The mainly step of developing audo play are:


1)       Get the resources from file


2)      Create a Player object


3)      play the audio


The mainly code discription of program are


1)       Get the audio resources and create Player


try{


InputStream in = getClass().getResourceAsStream("qhc.wav");


music = Manager.createPlayer(in,"audio/x-wav");


} catch (Exception e) { e.printStackTrace(); }


2)       Start playing the audio


try {                 


        music.start();        //Start Play


        ticker1.setString("Playing… ");        //set the ticker to display text


      } catch (Exception e) { e.printStackTrace(); }


3)       Continue playing after pause               


   try {


        music.setMediaTime(pauseTime);


              music.start();    //Continue play after pause


        ticker1.setString("Playing… ");


      } catch (Exception e) { e.printStackTrace(); }


4)       Pause playing the audio


try {


        pauseTime = music.getMediaTime();      //pause play


            music.stop();


      } catch (Exception e) { e.printStackTrace(); }


5)       Stop playing


try {


          music.stop();        //stop play


        music.close();


          } catch (Exception e) { e.printStackTrace(); }


 


3.Play Video


The main step of playing video is same to that playing audio, the difference is that the VideoControl object must be create to set the display mode.


The mainly code discription of program are


1)       Get the video resources and create Player


try{


InputStream iv = getClass().getResourceAsStream("sun.mpg");


video = Manager.createPlayer(iv,"video/mpeg");


    video.realize();      //different from the audio play


} catch (Exception e) { e.printStackTrace(); }


2)       create a VideoControl object, different from the audio play


VideoControl vc = (VideoControl)video.getControl("VideoControl");


  //Create a Item to display video


Item videoItem = (Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,null);


   form3.append(videoItem);


3)       Start playing the audio


try {                


        video.start();        //Start play


        ticker2.setString("Video playing…");       //set the ticker to display text


      } catch (Exception e) { e.printStackTrace(); }


4)       Continue playing after pause               


   try {


        video.setMediaTime(pauseTime);   


        video.start();               //Continue play after pause


         ticker2.setString("Video playing…");


      } catch (Exception e) { e.printStackTrace(); }


5)       Pause playing the audio


try {


        pauseTime = video.getMediaTime();      //Pause play


        video.stop();                        


      } catch (Exception e) { e.printStackTrace(); }


6)       Stop playing


try {


          video.stop();  //Stop play


        video.close();


     } catch (Exception e) { e.printStackTrace(); }


 


4.Notes:


We must focus on the media size and the memory in Emulator and MobilePhone. We can change the memory size in Emulator if exists OutOfMemory Error when the program 


is correct without some mistake such as not to release the memory resources. And we shoule note that the memory size in emulator must low than that in MobilePhone will be


deployed.




You can download the demo result and the source code from the follow link:


http://blogs.sun.com/Chinese_Functional_CA/resource/j2meVideoDemo_HongBingfeng.wmv


http://blogs.sun.com/Chinese_Functional_CA/resource/SourceCode_J2MEVideoDemo_HongBingfeng.zip


评论:

i can't find the Chinese article~

发表于 222.180.184.247 在 2008年05月05日, 03:33 下午 CST #

发表一条评论:
  • HTML语法: 禁用