You Are Here:

Community: Developer Discussion Boards

#1 Old Sound - 2003-10-01, 09:19

Join Date: May 2003
Posts: 40
f_alonso_1
Offline
Registered User
I want to listened a tone-sound in Nokia 3650 and I write this code where archivo is a variable which contain the name of the wav file and this file is in res directory of my project:


public static void SonidoWav(Sound tono,String archivo){
System.out.println("Estamos dentro del bloque try");
String a=new String();
Class Objeto=a.getClass();
InputStream is = Objeto.getResourceAsStream(archivo);
System.out.println(" Contenido del archivo");
System.out.println(is);
DataInputStream dis = new DataInputStream(is);
byte[] array = null;
System.out.println("Declaración del array");
System.out.println("siguiente");
ByteArrayOutputStream datos = new ByteArrayOutputStream();
System.out.println("Antes del bucle");
for(int i=0;i<dis.available();i++){
System.out.println("error");
datos.write(dis.read());
System.out.println("Salida del bucle");
}
array = datos.toByteArray();
tono.init(array, 5);
System.out.println("Inicialización");
tono.setGain(255);
tono.play(1);
System.out.println("Fin del try");

It crashes because an exception is produced because the file is null but the file it is not null and I have this file in res directory. I tried this code which I saw in a post of this forum:

System.out.println("Estamos en el primer bloque try");
String a = new String();
Class Objeto = a.getClass();
InputStream is = Objeto.getResourceAsStream(archivo);
System.out.println(is);
System.out.println("in after load file");
StringBuffer str = new StringBuffer();
byte[] b = new byte[1];
try{
System.out.println("Estamos en el segundo bloquer try");
while(is.read(b)!=-1){
System.out.println("in after load file in while");
str.append(new String(b));
}
}
catch(OutOfMemoryError e){
System.out.println("out of memory" + e.getMessage());
}
System.out.println("Estamos casi cerrando el archivo");
is.close();
byte[] binaryData = new byte[str.length()];
System.out.println("Estamos casi recorriendo el bucle");
for(int i=0;i<binaryData.length;i++){
binaryData[i] = (byte)str.charAt(i);
}
//return binaryData;
System.out.println("Final del try segundo");
}
catch(Exception e){
System.out.println("exception in loading the wav file" +
e.getMessage());
System.gc();

and I found the same problem. With the last code in function I put
public static byte[] SonidoWav(Sound tono,String archivo)

why it crashes? What I am making bad? Another question is if is there any limitation in the length of the wav file?

Many thanks in advance!!
Reply With Quote

#2 Old 2003-10-08, 13:27

Join Date: Mar 2003
Posts: 382
jalev's Avatar
jalev
Offline
Forum Nokia Expert
Hola


You should be able to play wav files:


try
{
InputStream tune = this.getClass().getResourceAsStream ("/somefile.wav");
byte[] buffer = new byte[100000];
tune.read(buffer, 0, buffer.length);
sound = new Sound(buffer, Sound.FORMAT_WAV);
sound.init(buffer, Sound.FORMAT_WAV);
sound.play(2);
} catch (Exception e) {}

Please check this.
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

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: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d134434X 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