Failed to create MediaPlayer - java-me

I have downloaded the code of -
Experiments in Streaming Content in Java ME by Vikram Goyal
But when trying to run the application, with emulator, after running the Darwin Stream Server
I get the following error -
Midlet->startApp
StreamingDataSource->StreamingDataSource
StreamingDataSource->getContentType
StreamingDataSource->getLocator (locator = rtsp://127.0.0.1/sample_100kbit.avi)
javax.microedition.media.MediaException: Player cannot be created for video/avi
at javax.microedition.media.Manager.createPlayer(), bci=135
- com.iprs.test.Midlet.startApp(Midlet.java:14)
at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
at com.sun.midp.midlet.MIDletPeer.startApp(), bci=5
at com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=261
at com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=38
at com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=5
at com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=144
at com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
Midlet->destroyApp
This is the StartApp method -
public void startApp() {
try {
System.out.println("Midlet->startApp");
// create Player instance, realize it and then try to start it
Player player = Manager.createPlayer(new StreamingDataSource("rtsp://127.0.0.1/sample_100kbit.avi")); //(new StreamingDataSource("rtsp://localhost:554/tuner1.wav")); //sample.mp3")); //sample_100kbit.mp4"));
player.realize();
player.start();
} catch(Exception e) {
e.printStackTrace();
}
}
I have tried with some media types but i got the error.
How it can be solved?
Thanks,
Eyal.

The IP address 127.0.0.1 always points to the device you're using. So when used in a MIDlet, it points to the phone running the MIDlet. In other words, you're trying to stream a file from your phone to your phone.
This of course doesn't work since you don't have a running webserver on your phone.
To make it work you should figure out the correct IP address to your server.
If your phone is connected via WiFi you can most probably use a local IP such as 10.0.0.x or 192.168.0.x
If your phone is connected via GPRS or 3G, you'll need to figure out what IP your desktop computer has on the Internet, using a service such as www.whatismyip.com
After that you have to make sure your server is accessible. In other words, make sure that your router is allowing traffic on the specific port used by the RTSP protocol, and guiding traffic on that port to your server.
To take it one step at a time, it might be a good idea to google for existing RTSP streams, and try those out first. That way you'll know that your JavaME code works fine.
As far as I remember, playing RTSP streams with JavaME (at least on newer phones) is fairly straight forward though. Should run with the standard Player, without any additional classes.
See this: J2ME/StreamingMedia.htm">http://www.java2s.com/Tutorial/Java/0430_J2ME/StreamingMedia.htm
You should also be able to test if a certain RTSP feed is working, simply by entering the URL into your phone browser. It should then launch the phone's default media player and play the stream.

Related

How to structure an app which uses a mobile phone to transmit audio via UDP

I need some help structuring an App that allows for a speaker who can send audio via his/her phone mic and then for users to listen to this audio stream. I don't want to upload anything to the cloud as there may be bad internet reception.
What technologies to use? How do they talk to together?
Currently I have:
Have a mobile dongle that everyone connects to
host a server on this dongle?
Send an live audio stream to this server via UDP
Users listen to this server
Ideally it would be great if I could build this in React Native, which I think is possible. I am not sure how to host a server on a dongle though or even if this the best method?

Connecting to Web Bluetooth

I'm trying to connect a bluetooth device (ESP32, peripheral) with Web Bluetooth (central). I send an addvertising packet and I can see the device on the web page, but I fail to connect to it. My code for the ESP32 looks like this: (MicroPython)
ble.gap_advertise(interval_us=100, adv_data=bytearray(b'\x02\x01\x06\x06\x08\x45\x53\x50\x33\x32\x11\x07\x26\x6c\x34\x7f\xb2\x38\x61\x82\xbe\x4d\x1d\x64\xf1\xf7\x93\x16\x02\x19\x80'),resp_data=None, connectable=True)
In Web Bluetooth (JavaScript) I just request a device and try to connect to the gatt.
Can anyone help me out?
Thanks in advance!
The JavaScript does work with another bluetooth peripheral. (RN4678)
And in JavaScript I can find the peripheral (ESP32) after filtering, but I can't connect to it.
JavaScirpt:
server = await device.gatt.connect()
The code stops at that point.
MicroPython:
The GATT is defined using:
ble.gatts.register.services()
I'm trying to use my own service, not a SIG defined one. So I advertise b'(x...') which contains the flags, the service and the device name. And it works with the nRF Connect App. I can send and recive data. But it doesn't work with the bluetooth enabled web browser.
Thanks for your help!

Whitelisted chromecast works with default tictactoe app ID but not mine

I am trying to get the tic tac toe demo from github working on my Chromecast after changing only the app id of the clients. With the default app id, I have been able to launch and play the game with an android client and a mac client.
I have:
Added my Chromecast device on the developer console (it has a green status indicator)
Set (via the Android Chromecast app) the Chromecast to send the device serial number
Verified that the serial number is correct
Verified with both the Android and Windows Chromecast apps that the serial# setting is retained
Power cycled the Chromecast
Setup an app id in the developer console (status is a grey circle labeled 'Unpublished')
Entered an internet accessible (not local) URL for the app id
Installed the receiver app at the above url and verified I can access it from a browser on the same network as the Chromecast
Also tried a local IP address (192.168.x.x) which I understand is supported as well
Modified the web client ttt.js file to use my app id (and verified app id is correct)
Modified the android client (GameActivity.java) to use my app id (and verified app id)
Did a git diff to make sure that I didn't inadvertently change anything else
Verified that my local copy of the source is the latest from git
When running the android client I can connect to my Chromecast but the Chromecast home screen shows "Brain Freeze", "We're sorry, but something could not load", "Activity aborted".
The logcat console in eclipse for the android device reports, "ConnectionResultCallback. Unable to launch the game. statusCode: 2002".
The web client on the Mac results in the same messages on the Chromecast and
'"reason":"CANCELLED","type":"LAUNCH_ERROR"'
on the web page output.
Is there a way to get more information from the Chromecast to indicate what is going wrong with the launch?
Follow Up
It turns out that the issue was in my network setup and not in my chromecast setup. After sniffing the network traffic with wireshark, I could see that the ARP request to retrieve the MAC address of my server was not getting a response. I am running my server on Virtualbox with a bridged adapter but needed to turn on promiscuous mode (allow all). Now the chromecast successfully launches the receiver app and I can play the tic tac toe game when using an HTTP based URL. (I need to fix the certificate for HTTPS).
Thanks Les, for the effort.
Did you verify that [x] send my serial # to Google has been checked (using the setup app)?
Also, did you wait 15 minutes and then restart your device (power cycle)?

UdpClient does not receive multicast packets occasionally

I've written an server-application that is supposed to send and listen to upnp packets on several specified interfaces (but the problem already existed when there was only one network card). The code is straight forward and quite simple, but I'm facing a very strange behavior.
I have a list of Endpoints (IPAddresses of the interfaces) the application should listen for and send messages to and then creating a UdpClient for each of them with this code:
private UdpClient c;
private IPEndPoint ep;
public MyClass(IPAddress ip)
{
ep = new IPEndPoint(ip, 1900);
c = new UdpClient(ep);
c.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));
c.BeginReceive(onReceive, null);
}
Every minute I send a packet, which works without any problems
byte[] msg = System.Text.Encoding.ASCII.GetBytes(discoverMessage);
c.Send(msg, msg.Length, new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900));
The clients respond to this and my receive function gets called.
protected void onReceive(IAsyncResult r)
{
IPEndPoint rep = new IPEndPoint(IPAddress.Any, 0);
string msg = Encoding.ASCII.GetString(c.EndReceive(r, ref rep));
<-- do other things -->
c.BeginReceive(onReceive, null);
}
But from time to time it just does not receive any packets, i.e. my receive function is not fired at all, although they are definately coming in (I can see them with wireshark and I know the clients sent them to the network).
The "workaround" to solve this is then to restart the application, disable/enable interfaces, reboot the (guest)machine, change the endpoint-list (for example include 0.0.0.0) - honestly I haven't found THE solution/workaround but a combination of this seems to solve the problem. Once it is working again I can copy back the old config and everything works as before (so the configuration was fine, imho).
I'm using .NET 4.5 on Windows Server 2012, running in a Hyper-V guest on Windows 8, atm with 2 virtual network cards, one connected internal for management and on connected to my physical network card which is not shared with the host and is connected to the clientnetwork.
Has anyone experienced similar problems? I was thinking if Wireshark or winpcap could cause the problem as it sometimes happens when I'm using them to trace any problems. Or could it be a problem with the hyper-V virtual network cards? Or, what I would prefer, am I doing something wrong in my code?
UDP is meant to be a "lossy" protocol. See here. If you want reliabilty, you need to either implement error control or switch to TCP/IP which has that built-in
In the case where you have more than a single NIC, what network is the igmp join request going to ?
You may want to use the two parameter version of the JoinMulticastGroup method so that you can include the specific local interface IP address on which you want to look for the multicast traffic. This is particularly relevant in scenarios where the machine has more than a single physical NIC, providing access to multiple networks.

J2ME SMS Server on mobile phone

Is it possible to have a j2me app on a mobile to act as a "SMS gateway" that will handle incommming messages, do a query on a database via GPRS and reply the user back?
This is entirely possible on any J2ME handset that supports JSR 120 (i.e.: most of them). However as Wonil said, you can't just process ANY incoming SMS message. It has to be an SMS sent to a port number on which your app is listening (using a server connection as Wonil explained).
It wouldn't be automatic unless the app was signed (as confirmation is generally required for sending SMS and network access).
Another approach is to tether your phone to a PC using a USB cable/bluetooth/IR, open a serial connection using the phone as a modem, and write a program to listen for new SMSs using AT+CGML as described here. This would allow ANY incoming SMS to be processed (no port number required), and without any annoying confirmation prompts.
HTH
I think you should check about JSR-120 documentation to confirm.
But, in my thought it might be impossible. If you want to receive message by using JSR-120, you should assign specific end point(port number) to listen as like below:
serverConn = (MessageConnection)Connector.open("sms://:5000");
So, you can't catch all SMS messages. It can't be a gateway then.
It probably depends if your phone supports it. Have a look at the J2ME Wireless Messaging API:
The Wireless Messaging API (WMA) is an optional package for the Java 2
Platform, Mobile Edition (J2ME) that
provides platform-independent access
to wireless communication resources
like Short Message Service (SMS).
http://java.sun.com/products/wma/overview.html
This article has some examples which can probably serve as a starting point for what you want to achieve: http://www.ibm.com/developerworks/wireless/library/wi-extendj2me/
Edit: as others have pointed out, you might not be able to receive all messages.

Resources