×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Post Strange bug with getSupportedContentTypes()

    Hey,
    I am trying to do audio streaming with jme on a Nokia Navigator 6110. I have read the docs and some threads on this, and it doesn't seem clear whether it's possible to do real streaming at all in jme, so as a start I decided to test the output from getSupportedContentTypes and getSupportedProtocols, like so many recommend... But even this doesn't seem to work properly.

    Here's where it crashes:

    Code:
    try {
      protocols = Manager.getSupportedProtocols(contenttype);
      test = "Number of protocols: " + protocols.length + "\n";
    				
      if (protocols != null && protocols[0] != null)
        test +=  protocols[0] + "\n";
    				
      for(int i=0; i<protocols.length; i++){
        test += protocols[i] + "\n";
      }
    				
    }
    catch (Exception e){
      test = "Something went wrong when finding protocols: " + e.getMessage();
    }
    If I comment out the for-loop, everything is fine: It prints out the length of the array, and the first entry in the array. But somehow the for-loop makes it crash (in S60 emulator it gives an unhandled exception - even though I am catching all exceptions! In the phone the script just freezes). The behaviour seems to be the same with getSupportedContentTypes(). But very erratic.

    I suspect I must be doing some really stupid mistake, but I can't see it myself. Can anyone help me please?

    I'm posting the entire code below.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Re: Strange bug with getSupportedContentTypes()

    Here's the entire code. Basically it sets up a form with two fields, where you can test either a given protocol or a content type - and get a list of supported types/protocols in a separate textbox.

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    
    public class Streamtest extends MIDlet implements CommandListener {
    
    	private TextBox textbox;
    	private Form form;
    	private TextField pField, cField;
    	private Display display;
    	private Command protocolCommand, contentCommand, exitCommand, backCommand;
    	
    	private String test = "";
    	private String[] supported = new String[30];
    	private String[] protocols = new String[10];
    	
    	public Streamtest() {
    		form = new Form("Media protocols test");
    		
    		pField = new TextField("Protocol:", "http", 100, TextField.ANY);
    		cField = new TextField("Content type:", "audio/mpeg", 100, TextField.ANY);
    		
    		protocolCommand = new Command("Test protocol", Command.SCREEN, 0);
    		contentCommand = new Command("Test content", Command.SCREEN, 0);
    		exitCommand = new Command("Exit", Command.EXIT, 1);
    		
    		backCommand = new Command("Back", Command.SCREEN, 1);
    	    
    		form.append(pField);
    		form.append(cField);
    		form.addCommand(protocolCommand);
    		form.addCommand(contentCommand);
    		form.addCommand(exitCommand);
    		form.setCommandListener(this);
    		
    		display = Display.getDisplay(this);
    		
    		
    		
    		
    	}
    	
    	public void findContentTypes(String protocol){
    		if (protocol != null && protocol != ""){
    			// showAlert("Starting test","Protocol: " + protocol);
    			try {
    
    				supported = Manager.getSupportedContentTypes(protocol);
    				test = "Number of content types: " + supported.length + "\n";
    				
    				if (supported != null && supported[0] != null) test += supported[0];
    				
    				for(int i=0; i<supported.length; i++){
    					test += supported[i] + "\n";
    				}
    				
    				
    			}
    			catch (Exception e){
    				test = "Something went wrong:" + e.getMessage();
    			}
    		}
    		else {
    			test = "The protocol variable is empty; did you forget to write something in the protocol field?";
    		}
    
    		textbox = new TextBox("Streaming test", test, 32, 0);
    		textbox.addCommand(exitCommand);
    		textbox.addCommand(backCommand);
    		textbox.setCommandListener(this);
    		display.setCurrent(textbox);
    	}
    	
    	public void findProtocols(String contenttype){
    		if (contenttype != null && contenttype != ""){
    			try {
    				protocols = Manager.getSupportedProtocols(contenttype);
    				test = "Number of protocols: " + protocols.length + "\n";
    				
    				if (protocols != null && protocols[0] != null) test += protocols[0] + "\n";
    				
    				for(int i=0; i<protocols.length; i++){
    					test += protocols[i] + "\n";
    				}
    				
    			}
    			catch (Exception e){
    				test = "Something went wrong when finding protocols: " + e.getMessage();
    			}
    		}
    		else {
    			test = "The content variable is empty; did you forget to write something in the content field?";
    		}
    
    		textbox = new TextBox("Streaming test", test, 32, 0);
    		textbox.addCommand(exitCommand);
    		textbox.addCommand(backCommand);
    		textbox.setCommandListener(this);
    		display.setCurrent(textbox);
    	}
    	
    	public void commandAction(Command c, Displayable s) {
    		if (c == exitCommand){
    			destroyApp(false);
    			notifyDestroyed();
    		}	
    		else if	(c == protocolCommand){
    			String teststring = pField.getString();
    			findContentTypes(teststring);
    		}
    		else if (c == contentCommand){
    			String teststring = cField.getString();
    			findProtocols(teststring);
    		}
    		else if (c == backCommand){
    			display.setCurrent(form);
    			textbox = null;
    		}
    	}
    	
    	public void showAlert(String title, String message){
    		Alert alert = new Alert(title, message, null, AlertType.ERROR);
    		display.setCurrent(alert);
    	}
    	
    	public void startApp(){
    		display.setCurrent(form);
    		
    	}
    	
    	public void pauseApp(){
    		
    	}
    	
    	public void destroyApp(boolean condition){
    		
    	}
    }

  3. #3
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Strange bug with getSupportedContentTypes()

    Hi anderssl,

    try changing this line:
    Code:
    textbox = new TextBox("Streaming test", test, 32, 0);
    to this:
    Code:
    textbox = new TextBox("Streaming test", test, 4000, TextField.ANY);
    (the Exception you're getting could be due to the TextBox max allowed size you set, that is not enough to hold all the content-type/protocol names)

    Pit

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Re: Strange bug with getSupportedContentTypes()

    I feel stupid. But thank you.

    Actually there were some more bugs, but with your help I got sensible output so I could find the others.

    I suspect this is trivial to most of you, but in case anyone else are having similar problems, I post my finished code here. It's a simple program in which you can enter the name of a protocol and get out which contenttypes can be used with it, or vice versa. Distribute freely.

    Code:
    /*
     * A simple test program for testing which media protocols are supported by a j2me phone,
     * and which content types can be used with certain protocols.
     * 
     * @author Anders Sundnes Løvlie
     * folk.uio.no/anderssl
     * a.s.lovlie at media.uio.no
     * 
     */
    
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    
    public class Streamtest extends MIDlet implements CommandListener {
    
    	private TextBox textbox;
    	private Form form;
    	private TextField pField, cField;
    	private Display display;
    	private Command protocolCommand, contentCommand, exitCommand, backCommand;
    	
    	private String[] supported = new String[30];
    	private String[] protocols = new String[10];
    	
    	public Streamtest() {
    		// User interface
    		
    		form = new Form("Media protocols test");
    		
    		pField = new TextField("Protocol:", "http", 100, TextField.ANY);
    		cField = new TextField("Content type:", "audio/mpeg", 100, TextField.ANY);
    		
    		protocolCommand = new Command("Test protocol", Command.SCREEN, 0);
    		contentCommand = new Command("Test content", Command.SCREEN, 0);
    		exitCommand = new Command("Exit", Command.EXIT, 1);
    		
    		backCommand = new Command("Back", Command.SCREEN, 1);
    	    
    		form.append(pField);
    		form.append(cField);
    		form.addCommand(protocolCommand);
    		form.addCommand(contentCommand);
    		form.addCommand(exitCommand);
    		form.setCommandListener(this);
    		
    		display = Display.getDisplay(this);	
    		
    	}
    	
    	public void findContentTypes(String protocol){
    		if (protocol != null && protocol != ""){
    			try {
    				supported = Manager.getSupportedContentTypes(protocol);
    			}
    			catch (Exception e){
    				showAlert("Error", "Something went wrong when finding contenttypes:" + e);
    				return;
    			}
    		}
    		else {
    			showAlert("Error", "The protocol variable is empty; did you forget to write something in the protocol field?");
    			return;
    		}
    		displayResults(supported,protocol);
    	}
    	
    	public void findProtocols(String contenttype){
    		if (contenttype != null && contenttype != ""){
    			try {
    				protocols = Manager.getSupportedProtocols(contenttype);
    			}
    			catch (Exception e){
    				showAlert("Error", "Something went wrong when finding protocols: " + e);
    				return;
    			}
    		}
    		else {
    			showAlert("Error", "The content variable is empty; did you forget to write something in the content field?");
    			return;
    		}
    	
    		displayResults(protocols, contenttype);
    	}
    	
    	public void displayResults(String[] results, String teststring){
    		String output = "";
    		try {
    			if (results == null){
    				output += "Error: '" + teststring + "' not supported on this phone. (Results was 'null'.)";
    			}
    			else if (results.length<1){
    				output += "Error: '" + teststring + "' not supported on this phone. (Length of results was 0.)";
    			}
    			else if (results[0] == null){
    				output += "Error: '" + teststring + "' not supported on this phone. (Result array is empty.)";
    			}
    			else {
    				output = "Number of entries: " + results.length + "\n";
    									
    				for(int i=0; i<results.length; i++){
    					output += results[i] + "\n";
    				}
    			}				
    		}
    		catch (Exception e){
    			output = "Something went wrong when finding results: " + e;
    		}
    	
    		textbox = new TextBox("Streaming test", output, 4000, TextField.ANY);
    		textbox.addCommand(exitCommand);
    		textbox.addCommand(backCommand);
    		textbox.setCommandListener(this);
    		display.setCurrent(textbox);
    	}
    	
    	public void commandAction(Command c, Displayable s) {
    		if (c == exitCommand){
    			destroyApp(false);
    			notifyDestroyed();
    		}	
    		else if	(c == protocolCommand){
    			String teststring = pField.getString();
    			findContentTypes(teststring);
    		}
    		else if (c == contentCommand){
    			String teststring = cField.getString();
    			findProtocols(teststring);
    		}
    		else if (c == backCommand){
    			display.setCurrent(form);
    			textbox = null;
    		}
    	}
    	
    	public void showAlert(String title, String message){
    		Alert alert = new Alert(title, message, null, AlertType.ERROR);
    		display.setCurrent(alert);
    	}
    	
    	public void startApp(){
    		display.setCurrent(form);
    		
    	}
    	
    	public void pauseApp(){
    		
    	}
    	
    	public void destroyApp(boolean condition){
    		
    	}
    }

Similar Threads

  1. Very strange bug in opening URLs
    By shrosenzwe in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-10-15, 13:54
  2. 7610 and strange bug with TTime
    By anttiaa in forum Symbian
    Replies: 2
    Last Post: 2004-08-26, 05:46
  3. Strange bug on N3650 with Firmware 4.13
    By NeoEgoism in forum Symbian
    Replies: 1
    Last Post: 2004-05-04, 04:08
  4. Strange bug on N3650 with Firmware 4.13
    By NeoEgoism in forum General Development Questions
    Replies: 0
    Last Post: 2004-05-03, 12:13
  5. Very strange TTime bug
    By bjorn.rudolfsson in forum Symbian
    Replies: 2
    Last Post: 2004-01-13, 15:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×