Live video streaming in j2me device - java-me

I am facing a problem in streaming video on devices which don't support RTSP streaming so I have to use anything else. Please suggest me any good approach related to this.
HttpConnection connection;
connection = (HttpConnection) Connector.open("http://myurl/video.3gp?streamable=true", Connector.READ_WRITE);
InputStream is = ((HttpConnection) connection).openInputStream();
player = Manager.createPlayer(is ,"video/3gpp");
//or below line in both cases it throw OutOfMemory error
//player = Manager.createPlayer("myurl/video.3gp?streamable=true");
player.addPlayerListener(this);
player.realize();
player.prefetch();
player.start();
I added Progressive-Download= true in jad file and tested on nokia X3. It throws OutOfMemory error.

Related

Reaading Audio in a UWP application

Hi everyone I'm trying to read an audio file in a UWP application using the method shown below:
MediaPlayer player = new MediaPlayer();
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/" + fileName));
Debug.WriteLine(file.Path);
var f = File.Exists(file.Path);
player.AutoPlay = false;
player.Source = MediaSource.CreateFromStorageFile(file);
player.Play();
But I get the following esception: System.TypeInitializationException: 'The type initializer for 'Focus.Services.Utility' threw an exception.'
Please can someone help ? I tried several methods for reading audio files but none seems to give.

bluetooth file transfer in c#

I am writing a bluetooth file transfer from my PC to Samsung galaxy using 32Feet.net
Following is the code,i am getting like:
Internal server error final
On my mobile set i saw file transfer but incomplete and message "remote device disconnected"
I tried to send file directly from my pc and it succeeded but using C# it did not work.
I tried 32Feet.net and some other blogs but could not get through.I read i should do pairing but dont know how to do it.
Please help me out of this.
private void sendFile()
{
SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog();
// dialog.ShowAuthenticated = true;
dialog.ShowRemembered = true;
dialog.ShowUnknown = true;
OpenFileDialog ofd = new OpenFileDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (ofd.ShowDialog() == DialogResult.OK)
{
System.Uri uri = new Uri("obex://" + dialog.SelectedDevice.DeviceAddress + "/" + ofd.FileName);
ObexWebRequest request = new ObexWebRequest(uri);
request.ReadFile(ofd.FileName);
ObexWebResponse response = (ObexWebResponse)request.GetResponse();
MessageBox.Show(response.StatusCode.ToString());
response.Close();
Cursor.Current = Cursors.Default;
}
else
{
MessageBox.Show("File Not Selected");
}
}
else
{
MessageBox.Show("Device Not Selected");
}
}
Pairing is something you do with Bluetooth devices before you transfer files between them. The devices have to know who they are talking to and trust each other.
On Windows XP
http://support.microsoft.com/kb/883259
On Windows Vista, 7, or 8 go to the start menu and start typing "Bluetooth". The entries that pop up should lead you the right direction.

How to get information/data from platformRequest() in J2ME?

I want to implement a behavior similar to Whatsapp, where when the user can upload an image. I tried opening the images in my app, but if the image is too large, I will have an out of memory error.
To solve this, I'm opening forwarding the images to be open in the phone's native image viewer using the platformRequest() method.
However, I want to know how is it Whatsapp modifies the phone's native image viewer to add a "Select" button, with which the user selects the image he wants to upload. How is that information sent back to the J2ME application and how is the image resized?
Edit:
I tried this in two different ways, both of which gave me the OOME.
At first, I tried the more direct method:
FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
if (!fc.exists()) {
throw new IOException("File does not exists");
}
InputStream fis = fc.openInputStream();
Image im = Image.createImage(fis);
fis.close();
When that didn't work, I tried a more "manual" approach, but that gave me an error as well.
FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
if (!fc.exists()) {
throw new IOException("File does not exists");
}
InputStream fis = fc.openInputStream();
ByteArrayOutputStream file = new ByteArrayOutputStream();
int c;
byte[] data = new byte[1024];
while ((c = fis.read(data)) != -1) {
file.write(data, 0, c);
}
byte[] fileData = null;
fileData = file.toByteArray();
fis.close();
fc.close();
file.close();
Image im = Image.createImage(fileData, 0, fileData.length);
When I call the createImage method, the out of memory error occurs in both cases.
This varies with the devices. An E72 gives me the error with 3MB images, while a newer device will give me the error with images larger than 10MBs.
MIDP 2 (JSR 118) does not have API for that, you need to find another way to handle big images.
As for WhatsApp, it looks like they do not rely on MIDP in supporting this functionality. If you check the Wikipedia page you'll note that they don't claim general Java ME as supported platform, but instead, list narrower platforms like Symbian, S40, Blackberry etc.
This most likely means that they implement "problematic features" like one you're asking about using platform-specific API of particular target devices, having essentially separate projects / releases for every platform listed.
If this feature is really necessary in your application, you likely will have to do something like this.
In this case, consider also encapsulating problematic features in a way to make it easier to switch just part of your source code when building it for different platforms. For example, Class.forName(String) can be used to load platform specific implementation depending on target platform.
//...
Image getImage(String resourceName) {
// ImageUtil is an interface with method getImage
ImageUtil imageUtil = (ImageUtil) Class.forName(
// get platform-specific implementation, eg
// "mypackage.platformspecific.s40.S40ImageUtil"
// "mypackage.platformspecific.bb.BBImageUtil"
// "mypackage.platformspecific.symbian.SymbialImageUtil"
"mypackage.platformspecific.s40.S40ImageUtil");
return imageUtil.getImage(resourceName);
}
//...

Java Me video player realize error with http - MediaException

I'm using the below code (references from, http://www.java-tips.org/java-me-tips/midp/playing-video-on-j2me-devices.html). It fails at 'realize()', with the javax.microedition.media.MediaException, "Unable to create native player". What is the problem here?
I tried this using both Eclipse and Netbeans. Am I missing some "internet" permissions or using any incorrect encoding, the video is an external 'mpg' test-resource and does work fine when downloaded through a desktop browser.
public void run()
{
String url = "http://www.fileformat.info/format/mpeg/sample/05e7e78068f44f0ea748855ef33c9f4a/MELT.MPG";
//Append the GUI to a form
Form form = new Form("Video on java mobile!");
Display display = Display.getDisplay(this);
display.setCurrent(form);
try
{
HttpConnection conn = (HttpConnection)Connector.open(url,
Connector.READ_WRITE);
InputStream is = conn.openInputStream();
Player p = Manager.createPlayer(is,"video/mpeg");
//I tried the below, but that didn't work either
//Player p = Manager.createPlayer(url);
p.realize();
//Get the video controller
VideoControl video = (VideoControl) p.getControl("VideoControl");
if(video != null)
{
//Get a GUI to display the video
Item videoItem = (Item)video.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE, null);
form.append(videoItem);
}
//Start the video
p.prefetch();
p.start();
}
catch(Exception e)
{
form.append(url + " Error:" + e.getMessage());
}
}
I've just started with Java, Eclipse, Netbeans. Since, there similar samples found everywhere, I believe I'm missing something very basic. Can someone please help?
The problem here was the video file. Although my source video seemed "mpeg", it wasn't acceptable to the emulator. After searching through a bit, I found a converter and I manually converted some sample mp4 to "mpeg". It finally worked with the same emulator, after I tried to download and play these manually converted files.
One piece of advise if you are new J2ME/JavaME apps (like me), keep playing with the input data sources/formats and the emulators. Switching emulators or the input data-formats is an easy way to identify the not-so-evident problems.

how to upload a audio file using HTTP POST from blackberry 5.0?

i need to upload a audio file stored in phone memory using http post. what steps required for it. any helps will be appreciated.
i doing the client side progrmming.
InputStream inputStream = null;
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(url);
if (connDesc != null)
{
HttpConnection httpConn;
httpConn = (HttpConnection)connDesc.getConnection();
httpConn.setRequestMethod(HttpConnection.POST);
URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
//here i want to append the audio data from phone memmory . how it will be done?
thanks
There is an example of using the HTTP POST protocol in the API documentation for HttpConnection. You will, as PA suggests, have to provide an HTTP server to accept the conection and do something with the data.

Resources