You Are Here:

Community: Developer Discussion Boards

#1 Old Post Strange bug with getSupportedContentTypes() - 2008-09-09, 14:00

Join Date: Dec 2007
Posts: 4
anderssl
Offline
Registered User
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.
Reply With Quote

#2 Old Re: Strange bug with getSupportedContentTypes() - 2008-09-09, 14:02

Join Date: Dec 2007
Posts: 4
anderssl
Offline
Registered User
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){
		
	}
}
Reply With Quote

#3 Old Re: Strange bug with getSupportedContentTypes() - 2008-09-09, 15:05

Join Date: Nov 2007
Posts: 2,029
Location: Rome, Italy
Send a message via MSN to jappit Send a message via Skype™ to jappit
jappit's Avatar
jappit
Offline
Forum Nokia Champion
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


www.jappit.com - mobile and web blog
Reply With Quote

#4 Old Re: Strange bug with getSupportedContentTypes() - 2008-09-09, 20:23

Join Date: Dec 2007
Posts: 4
anderssl
Offline
Registered User
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){
		
	}
}
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Very strange bug in opening URLs shrosenzwe Symbian Networking & Messaging 0 2007-10-15 14:54
7610 and strange bug with TTime anttiaa General Symbian C++ 2 2004-08-26 06:46
Strange bug on N3650 with Firmware 4.13 NeoEgoism General Symbian C++ 1 2004-05-04 05:08
Strange bug on N3650 with Firmware 4.13 NeoEgoism General Discussion 0 2004-05-03 13:13
Very strange TTime bug bjorn.rudolfsson General Symbian C++ 2 2004-01-13 16:10

Rate This

 
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: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ