| Reply | « Previous Thread | Next Thread » |
|
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();
}
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. |
|
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){
}
}
|
|
Hi anderssl,
try changing this line: Code:
textbox = new TextBox("Streaming test", test, 32, 0);
Code:
textbox = new TextBox("Streaming test", test, 4000, TextField.ANY);
Pit |
|
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |