`
mmdev
  • 浏览: 12922276 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

J2ME实现RTSP(只有在支持的手机才能用)

 
阅读更多
  1. importjavax.microedition.lcdui.*;
  2. importjavax.microedition.midlet.*;
  3. importjavax.microedition.media.*;
  4. importjavax.microedition.media.control.*;
  5. /**
  6. *AsimpleexampleoftheMMAPI(JSR135)supportforStreamingVideo
  7. *withtheSonyEricssonV800.
  8. *
  9. *ThiscodeispartoftheTips&Trickssectionat
  10. *www.SonyEricsson.com/developer
  11. *
  12. *COPYRIGHTAllrightsreservedSonyEricssonMobileCommunicationsAB2005.
  13. *ThesoftwareisthecopyrightedworkofSonyEricssonMobileCommunicationsAB.
  14. *Theuseofthesoftwareissubjecttothetermsoftheend-userlicense
  15. *agreementwhichaccompaniesorisincludedwiththesoftware.Thesoftwareis
  16. *provided"asis"andSonyEricssonspecificallydisclaimanywarrantyor
  17. *conditionwhatsoeverregardingmerchantabilityorfitnessforaspecific
  18. *purpose,titleornon-infringement.Nowarrantyofanykindismadein
  19. *relationtothecondition,suitability,availability,accuracy,reliability,
  20. *merchantabilityand/ornon-infringementofthesoftwareprovidedherein.
  21. *
  22. */
  23. publicclassStreamingVideoextendsMIDletimplementsCommandListener,PlayerListener,Runnable{
  24. privateDisplaymyDisplay;
  25. privateFormmyForm;
  26. privateThreadstreamingThread;
  27. privatePlayermyPlayer;
  28. privateVideoControlvc;
  29. privatebooleanrunning=false;
  30. publicStreamingVideo(){
  31. myDisplay=Display.getDisplay(this);
  32. myForm=newForm("StreamingTest");
  33. myForm.addCommand(newCommand("Exit",Command.EXIT,0));
  34. myForm.addCommand(newCommand("Start",Command.OK,0));
  35. myForm.setCommandListener(this);
  36. }
  37. protectedvoidstartApp()throwsMIDletStateChangeException{
  38. myDisplay.setCurrent(myForm);
  39. streamingThread=newThread(this);
  40. }
  41. protectedvoidpauseApp(){}
  42. protectedvoiddestroyApp(booleanunconditional){
  43. try{
  44. myPlayer.stop();
  45. myPlayer.close();
  46. }
  47. catch(Exceptione){
  48. log("Exception:"+e.toString());
  49. }
  50. }
  51. /**
  52. *InitsandstartsthePlayerforVideoStreaming
  53. */
  54. privatevoidstartStreaming(){
  55. try{
  56. myPlayer=Manager.createPlayer("rtsp://yourServer/mobile/realmp3.3gp");
  57. myPlayer.addPlayerListener(this);
  58. myPlayer.realize();
  59. //Grabthevideocontrolandsetittothecurrentdisplay.
  60. vc=(VideoControl)myPlayer.getControl("VideoControl");
  61. if(vc!=null){
  62. myForm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE,null));
  63. //setsthedisplaysizeofthevideo.
  64. vc.setDisplaySize(120,160);
  65. }
  66. myPlayer.start();
  67. }catch(Exceptione){
  68. log("Exception:"+e.toString());
  69. myForm.append("Exception:"+e.toString());
  70. }
  71. }
  72. publicvoidcommandAction(Commandc,Displayables){
  73. if(c.getCommandType()==Command.EXIT){
  74. running=false;
  75. notifyDestroyed();
  76. }else{
  77. streamingThread.start();
  78. }
  79. }
  80. /**
  81. *PlayerListenerInterfacemethod,logsallplayerevent.
  82. */
  83. publicvoidplayerUpdate(Playerplayer,Stringevent,ObjecteventData){
  84. log("**playerUpdate:"+event+"**");
  85. }
  86. publicvoidlog(Stringmsg){
  87. System.out.println(msg);
  88. }
  89. publicvoidrun(){
  90. running=true;
  91. startStreaming();
  92. while(running){
  93. Thread.yield();
  94. }
  95. }
  96. }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics