I am a iphone/android developer, and now trying hands on Blackberry.
Need guidance in streaming radio url in blackberry.
need some resources , links to play radio streaming in blackberry.
Appreciate it.
I think the link will help you,there is a sample zip file also
http://supportforums.blackberry.com/t5/Java-Development/Streaming-media-Start-to-finish/ta-p/488255
And if you get a url you can directly give the url to Player object,Blackberry support almost all type of media files.
private void invokeMediaPlayer(String url){
try {
player = javax.microedition.media.Manager.createPlayer(url);
player.realize();
volume = (VolumeControl)player.getControl("VolumeControl");
volume.setLevel(40);
player.prefetch();
player.start();
player.addPlayerListener(this);
/* metaDataTrimmed = inner.getMetaData1();
System.out.println(metaDataTrimmed);*/
} catch (IOException e) {
e.printStackTrace();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Related
I'm trying to incorporate video and audio file attachment to forum posts in an app, and the playback isn't working on iOS. On Android it works fine. The code looks like this (for audio, and similar for video):
String localAudiofilePath = FileSystemStorage.getInstance().getAppHomePath() + (String) fileInfo.get("path");
InputStream is = null;
Media m = null;
try{
is = FileSystemStorage.getInstance().openInputStream(localAudiofilePath);
m = MediaManager.createMedia(is, "audio/" + extractFileExtension((String) fileInfo.get("path")));
}catch(Exception ex){
ex.printStackTrace();
}
m.play();
final Media mm = m;
Display.getInstance().scheduleBackgroundTask(new Runnable() {
#Override
public void run() {
while(mm.isPlaying()){
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
}
mm.cleanup();
}
});
I don't see any errors in the console, and when debugging I see the catch block is not entered. However, no sound comes out of the device when I try to play the audio, and the video player remains blank, giving me this message in the console:
2018-01-18 04:22:20.213822 MyApplication[24425:2262915] [Playback] ❗️Playback failed with error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x61000024c2d0 {Error Domain=NSOSStatusErrorDomain Code=-12893 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12893), NSLocalizedDescription=The operation could not be completed}, not resolving (canResolve: YES, errorResolver: (null))
What am I missing?
You are using the audio recording mime type to playback a video. I guess Android ignores it which is fine. The iOS port sees an audio format for the stream data and assumes this is an audio file. You need to specify the mime file type of the video you are playing.
The problem was not at all media playback. The file wasn't actually present on the device, even though no exception was reported by iOS nor was the catch clause ever entered. My incorrect assumptions were 1. that I could use try/catch around the input stream instantiation as a means of checking if the file exists (it worked on Android but not iOS), and 2. that the operating system would necessarily throw an exception if the file wasn't present (not the same as 1., but tied into it).
My new, working code looks like this:
String localAudiofilePath = FileSystemStorage.getInstance().getAppHomePath() + MyApplication.DIRECTORY_APP_DOWNLOADS + "/" + (String) fileInfo.get("path");
if(!FileSystemStorage.getInstance().exists(localAudiofilePath)){
Cn1FileUtils.downloadRemoteFile("https://medonline.co.il/uploads/" + (String) fileInfo.get("path"), (String) fileInfo.get("path"), true);
}
InputStream is = null;
media = null;
try{
is = FileSystemStorage.getInstance().openInputStream(localAudiofilePath);
media = MediaManager.createMedia(is, "audio/" + Cn1FileUtils.extractFileExtension((String) fileInfo.get("path")));
}catch(Exception ex){
ex.printStackTrace();
ToastBar.showErrorMessage(MyApplication.getInstance().getString("error_loading_file"));
return;
}
media.play();
I am trying to write a function that takes an input URL of any Stack Overflow link, gets the source code of the page, parses it, gets the accepted answer, and also gets the answer with the most upvotes.
I am new to this and I don't know how to do this. This is what I've tried out. It just returns the first answer using jsoup.
protected void doHtmlParse(String url) {
// TODO Auto-generated method stub
Document doc;
try {
doc = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get();
Element answer = doc.select("td[class=answercell]").get(0);
System.out.println("Answer is \n" + answer.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I only need to display the answer part, but it has to be the accepted answer. How do I approach this?
You don't really need to parse html. Use their REST API.
Have a look.
Here's an example. Note the is_accepted attribute.
EDIT:
Well, after you've got the chosen answer through the API, you could do this:
String answer = document.getElementById("answer-"+id).outerHtml();
I am now able to get the accepted answer via this code.
protected void doHtmlParse(String url) {
// TODO Auto-generated method stub
Document doc;
try {
doc = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get();
Element answer = doc.select("div[class=answer accepted-answer]").first();
Elements tds = answer.getElementsByTag("td");
for(Element td : tds) {
String clasname = td.attr("class");
if(clasname.equals("answercell")) {
System.out.println("\n\nAccepted answerrr is \n" + td.text());
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Can any one please tell me the process through which I can open a photo gallery in the blackberry application to choose a photo to upload, is there any file uploading control in the blackeberry 5.0 and also tell me the process to save the photo from the blackberry application to the remote server using HttpWebRequest.
Thanks
Their is nice way which i have done. Just get selected image from the phone through file browser or file io method than convert it to a byte array than just encode it to base64 String and send this string to the server by http request.
and at server side just do opposite.
final byte[] chunk;
chunk = new byte[actualSize];
try {
int bytesRead = in.read(chunk);
fconn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
String encodedStr = Base64OutputStream.encodeAsString(chunk, 0, chunk.length,false,false);
}
Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
// Create message.
Message msg = new Message(sentfolder);
// Add TO Recipients.
Address toList[] = new Address[1];
try {
toList[0]= new Address("someemail#email.com", "Some Email");
} catch(AddressException e) {
System.out.println(e.toString());
}
try {
msg.addRecipients(Message.RecipientType.TO, toList);
} catch (MessagingException e) {
System.out.println(e.toString());
}
// Add CC Recipients.
Address ccList[] = new Address[1];
try {
ccList[0]= new Address("someemail#gmail.com", "some address");
} catch(AddressException e) {
System.out.println(e.toString());
}
try {
msg.addRecipients(Message.RecipientType.CC, ccList);
} catch (MessagingException e) {
System.out.println(e.toString());
}
// Add the subject.
msg.setSubject("A Test Email");
// Add the message body.
try {
msg.setContent("This is a test message.");
} catch(MessagingException e) {
// Handle messaging exceptions.
}
// Send the message.
try {
Transport.send(msg);
} catch(MessagingException e) {
System.out.println(e.getMessage());
}
System.out.println("Email sent successfully.");
Are you running this on a simulator? If so, which development environment (eclipse or JDE)? Have you started the MDS or are you using ESS? (With MDS 4, you don't need ESS.)
Personally, I use eclipse with the plug-in, then set the run-time configuration to launch MDS.
However, before doing that, you need to edit the rimpublic.property file to configure it to connect to your e-mail server (if you are using a remote e-mail server). If you are going to use a local mail client, configure MDS to use that as a pass-through.
Let me know what your setup / configuration is and I'll try to help more.
I have coded to get the info from the user and send an email of clicking a button. The program is getting executed for a while and then the simulator is crashing showing error
"DE427"-Message queue full... Here's the code that i have done...
if(field==SendMail)
{
Message m = new Message();
Address a = null;
try {
a = new Address("user#xyz.com", "Rahul");
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Address[] addresses = {a};
try {
m.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, addresses);
m.setContent("Name:"+Name.getText().toString()+"\n"+ "Phone :"+Phone.getText().toString()+
"\n"+ "Date & Time:"+DateShow.getText().toString()+"\n"+"Make:"+Make.getText().toString()+
"\n"+"Model:"+Model.getText().toString()+"\n"+"Miles:"+Miles.getText().toString()+"\n");
m.setSubject("Appointment Request (Via Blackberry app)");
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(m));
}
Can anyone tell me what the error is and how to rectify the problem....Plz...
It seems there is an issue with certain versions of Windows XP and the Blackberry simulator version. Check this link http://supportforums.blackberry.com/t5/Testing-and-Deployment/Simulator-quot-device-Error-DE427-quot/m-p/556321
If you clean up the simulator (delete .dmp files from simulator directory) and restart the simulator it works fine