View Single Post

Thread: j2me streaming

#12 Old Re: j2me streaming - 2006-11-10, 20:10

Join Date: Apr 2003
Posts: 6,408
Location: USA, CA
hartti's Avatar
hartti
Offline
Nokia Expert
Simple streaming midlet (I hope I did not make any mistakes, when removing some extra testing stuff from the source).
This is edited version form one streaming midlet source code I grabbed somewhere, I did not anymore find the original code. [Edit: as pointed in the FN blog by Robert the source for this seems to be here http://developer.sonyericsson.com/si...aming_v800.jsp as the structure and variable names are same, even though there a number of differences in the code, hence I have copied the copyright disclaimer from the original available in the URL above. Thanks Robert! At the same time I apologize that Jöns Weimarck's work has been visible here without proper credit]
[Edit2: I removed the orginal one and rewrote the code as I felt that was proper thing to do. This current version works like the original one.]

Note also that the use of alerts here is not optimal. I was originally using alerts for another purpose than logging error information. now the log function looks like an ugly hack

Hartti

Code:
import javax.microedition.media.*;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class StreamVideo extends MIDlet implements Runnable, PlayerListener, CommandListener
{
	Display d;
	Form f;
	Alert a;
	Command exit, start;
	
    Thread streamThread;

    Player vp;
    VideoControl vc;
	
	public StreamVideo()
	{
		d = Display.getDisplay(this);
		f = new Form("Stream test");
		exit = new Command("Exit", Command.EXIT, 1);
		start = new Command("Start streaming", Command.OK, 1);
		f.addCommand(exit);
		f.addCommand(start);
		f.setCommandListener(this);
	}
	
	protected void destroyApp(boolean p1)
	{
        try {
            vp.stop();
            vp.close();
        }
        catch( Exception e ) {
        	log("Exception: " + e.toString());        
        }
        notifyDestroyed();
	}

	protected void startApp(  )
	{
		d.setCurrent(f);
		streamThread = new Thread(this);
	}

	protected void pauseApp()
	{
	}

	public void run()
	{
		doTheStream();
	}

	public void playerUpdate(Player p1, String p2, Object p3)
	{
        log("playerUpdate: " + p2);
	}
	
	public void commandAction(Command c1, Displayable d1)
	{
		if (c1 == start) {
	        streamThread.start();
		} else {
			destroyApp(true);
		}
	}
	
    public void log(String msg){
    	a = new Alert("Exception", msg, null, AlertType.CONFIRMATION);
    	d.setCurrent(a, f);
     }
    
    public void doTheStream()
    {
        try{
        	vp = Manager.createPlayer("rtsp://ra.yle.fi/yle24/video/uusin_mobile.rm");
        	vp.addPlayerListener(this);
        	vp.realize();
        	vc = (VideoControl)vp.getControl("VideoControl");
        	if (vc != null) {
        		f.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));
        		vc.setDisplaySize(176,144);
        		vc.setDisplayLocation(0,0);
        	}          
        	vp.start(); 
        }catch(Exception e){
        	log("Exception: " + e.toString());
        }    	
    }
}
Last edited by hartti : 2007-01-03 at 03:24.
Reply With Quote
 
 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowpostE2ephpE3fpE3d99479E26postcountE3d1X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE44iscussionE45ntryQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE44iscussionE45ntryQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE44iscussionE45ntryQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ