• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Playing Sound in Applet

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is it possible to play (online .wav file) sound in Applet using URL Like
(http://Music/demo/abc.wav)

I have tried

URL ur=new URL("file:\\C:\\Demo\\abc.wav");
AudioClip clip =Applet.newAudioClip(ur);
It's working fine
In fact i have tried getAudioClip() to run "http://Music/demo/abc.wav" but it's not working.

Actually i want to play "http://" URL file directly in applet
Please help me.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, what does "it doesn't work" mean? Are there any exceptions? Does the browser download the file if you enter "http://Music/demo/abc.wav" in the URL field?
 
Bagesh Tripathi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you for response.Yes,the browser is downloading the file.
The code i'am using is given below:
------------------------------------
package Sound;

import java.io.IOException;
import java.net.*;
import java.applet.*;


public class Sound2{
public static void main(String a[])
{
try {
String str1="http://simplythebest.net/sounds/WAV" +
"/WAV_files/cartoon_WAV_files/aladdin_goodbye.wav";

String str2="file:\\C:\\Documents and Settings\\btripathi" +
"\\Desktop\\ChatRoom_15April_Backup\\client\\sound\\ringin.wav";


URL url=new URL(str1); // 1
AudioClip clip =Applet.newAudioClip(url);
clip.play();
}catch(java.net.MalformedURLException e)
{
e.printStackTrace();
}


}
}
---------------------------------------------
Now when i pass str1 (as shown in //1) it,s workin fine,But whenever i pass str2 or whole URL("http://....").I'am unable to hear any sound.Even i'm not getting a single error.
[ July 05, 2007: Message edited by: yoshino ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a bit unclear what is now working, and what isn't.

As I understand it, this works:

but this doesn't

and neither does this

Is that correct? That the second one wouldn't work is very strange - it's the same as the first one.

Also, your display name still doesn't conform to the policy. It must consist of a first name and a last name, and not be obviously fictitious. Please take a moment to change it, which you can do right here.
 
Bagesh Tripathi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for creating confusion Actually

URL url=new URL("http://simplythebest.net/sounds/WAV/WAV_files/cartoon_WAV_files/aladdin_goodbye.wav");
is NOT working &
------------------------
URL url=new URL("file:\\C:\\Documents and Settings\\btripathi\\Desktop\\ChatRoom_15April_Backup\\client\\sound\\ringin.wav");
is working FINE
--------------------------

That is while accessing sound file from local system it's working fine,but while accessing file in Network/Internet it's not working.
[ July 05, 2007: Message edited by: Bagesh ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that the application quits before the clip is loaded. Both the newAudiopClip and play methods return immediately, even if the the clip isn't loaded. If you insert a "Thread.sleep(10000)" after the call to play, you should hear the clip playing.

Also, thanks for changing your display name. Unfortunately, it's still not valid, because -as I said above- it needs to have a first name and a last name. Please fix it accordingly.
[ July 05, 2007: Message edited by: Ulf Dittmer ]
 
Bagesh Tripathi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you for your response.
i'm using "Thread.sleep(10000)".But still I'm not getting the desired result(no sound )
Given below is the code.Please help me where i'm going wrong

package Sound;

import java.io.IOException;
import java.net.*;
import java.applet.*;

public class Sound2 {
public static void main(String a[]) throws java.net.MalformedURLException {

String str1 = "http://simplythebest.net/sounds/WAV/WAV_files/cartoon_WAV_files/aladdin_goodbye.wav";

URL url = new URL(str1);
AudioClip clip = Applet.newAudioClip(url);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
clip.play();
}
}

Thanks
[ July 05, 2007: Message edited by: Bagesh Tripathi ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to put the call to Thread.sleep after the call to clip.play.
 
Bagesh Tripathi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Done this also (i.e putting Thread.sleep after the call to clip.play) no success.If possible please provide some excerpts\source code.It would be great help to me.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works for me:
 
Bagesh Tripathi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

First of all Thanks a lot for your information & the solution you provided.
Given below is my code snipplet:
-------------------------------
import java.net.*;
import java.applet.*;

public class Sound2 {
public static void main(String a[]) throws java.net.MalformedURLException, InterruptedException {
URL url = new URL("http://simplythebest.net/sounds/WAV/WAV_files/cartoon_WAV_files/aladdin_goodbye.wav");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
Thread.sleep(10000);
}
}
-------------------------------------------

I don't know whats going wrong but i'm still not able to hear the sound.

Thanks
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic