- importjavax.microedition.lcdui.*;
- importjavax.microedition.midlet.*;
- importjavax.microedition.media.*;
- importjavax.microedition.media.control.*;
- /**
- *AsimpleexampleoftheMMAPI(JSR135)supportforStreamingVideo
- *withtheSonyEricssonV800.
- *
- *ThiscodeispartoftheTips&Trickssectionat
- *www.SonyEricsson.com/developer
- *
- *COPYRIGHTAllrightsreservedSonyEricssonMobileCommunicationsAB2005.
- *ThesoftwareisthecopyrightedworkofSonyEricssonMobileCommunicationsAB.
- *Theuseofthesoftwareissubjecttothetermsoftheend-userlicense
- *agreementwhichaccompaniesorisincludedwiththesoftware.Thesoftwareis
- *provided"asis"andSonyEricssonspecificallydisclaimanywarrantyor
- *conditionwhatsoeverregardingmerchantabilityorfitnessforaspecific
- *purpose,titleornon-infringement.Nowarrantyofanykindismadein
- *relationtothecondition,suitability,availability,accuracy,reliability,
- *merchantabilityand/ornon-infringementofthesoftwareprovidedherein.
- *
- */
- publicclassStreamingVideoextendsMIDletimplementsCommandListener,PlayerListener,Runnable{
- privateDisplaymyDisplay;
- privateFormmyForm;
- privateThreadstreamingThread;
- privatePlayermyPlayer;
- privateVideoControlvc;
- privatebooleanrunning=false;
- publicStreamingVideo(){
- myDisplay=Display.getDisplay(this);
- myForm=newForm("StreamingTest");
- myForm.addCommand(newCommand("Exit",Command.EXIT,0));
- myForm.addCommand(newCommand("Start",Command.OK,0));
- myForm.setCommandListener(this);
- }
- protectedvoidstartApp()throwsMIDletStateChangeException{
- myDisplay.setCurrent(myForm);
- streamingThread=newThread(this);
- }
- protectedvoidpauseApp(){}
- protectedvoiddestroyApp(booleanunconditional){
- try{
- myPlayer.stop();
- myPlayer.close();
- }
- catch(Exceptione){
- log("Exception:"+e.toString());
- }
- }
- /**
- *InitsandstartsthePlayerforVideoStreaming
- */
- privatevoidstartStreaming(){
- try{
- myPlayer=Manager.createPlayer("rtsp://yourServer/mobile/realmp3.3gp");
- myPlayer.addPlayerListener(this);
- myPlayer.realize();
- //Grabthevideocontrolandsetittothecurrentdisplay.
- vc=(VideoControl)myPlayer.getControl("VideoControl");
- if(vc!=null){
- myForm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE,null));
- //setsthedisplaysizeofthevideo.
- vc.setDisplaySize(120,160);
- }
- myPlayer.start();
- }catch(Exceptione){
- log("Exception:"+e.toString());
- myForm.append("Exception:"+e.toString());
- }
- }
- publicvoidcommandAction(Commandc,Displayables){
- if(c.getCommandType()==Command.EXIT){
- running=false;
- notifyDestroyed();
- }else{
- streamingThread.start();
- }
- }
- /**
- *PlayerListenerInterfacemethod,logsallplayerevent.
- */
- publicvoidplayerUpdate(Playerplayer,Stringevent,ObjecteventData){
- log("**playerUpdate:"+event+"**");
- }
- publicvoidlog(Stringmsg){
- System.out.println(msg);
- }
- publicvoidrun(){
- running=true;
- startStreaming();
- while(running){
- Thread.yield();
- }
- }
- }
J2ME实现RTSP(只有在支持的手机才能用)
最新推荐文章于 2021-02-19 16:29:17 发布
本文介绍了一个使用MMAPI (JSR135) 在索尼爱立信V800手机上实现流媒体视频播放的简单示例。代码展示了如何初始化并启动播放器进行视频流播放。
&spm=1001.2101.3001.5002&articleId=81834654&d=1&t=3&u=fd57d153403243efae32accfc862d6b3)
203

被折叠的 条评论
为什么被折叠?



