473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Audio Streaming ( help again--very urgent )

I have written the code(in short) as below on the server side and client side


import sun.audio.*;
import java.io.*;
import java.net.*;

class Server2
{

public static void main(String args[])throws IOException
{


ServerSocket s=new ServerSocket(1000);//port no
Socket sc = s.accept();

InputStream in =sc.getInputStream();
OutputStream out =sc.getOutputStream();

BufferedReader fc=new BufferedReader(new InputStreamReader(in));
PrintStream pc=new PrintStream(out,true);



int i;
FileInputStream fin=new FileInputStream("LoopyMusic.wav");

try{
while(true){
i=fin.read();
if(i==-1) break;
pc.print(i);
}
}

catch(IOException ei)
{System.out.println("io exception");return;}

System.out.println("completed transfer :");


fin.close();
sc.close();s.close() ; }}
client :

import java.net.*;
import sun.audio.*;
import java.io.*;
class Client2
{

public static void main(String args[])throws IOException

{

Socket sc=new Socket("localhost",1000);//port no

InputStream in =sc.getInputStream();

FileOutputStream fout1=new FileOutputStream("play.wav");;

int i;

BufferedReader fu=new BufferedReader(new InputStreamReader(in));






try{
while(true){
i=fu.read();
if(i==-1)break; fout1 .write(i);

}
}

catch(IOException ei)
{System.out.println("io exception");
return;
}






fout1.close();
sc.close();
FileInputStream ifn = new FileInputStream("a.wav");

// Create an AudioStream object from the input stream.

AudioStream as = new AudioStream(ifn);

// Use the static class member "player" from class AudioPlayer to play
// clip.

System.out.println("started playing ");
AudioPlayer.player.start(as);
System.out.println("ended playing ");


}

}


The problem is that my original file of 918kB when copied ,goes upto 4 MB and does not play..it says this format is not supported

When i try to copy the file on server side and play it works perfectly well,then what's the problem when it's through server and client relation..

Please help !!
Apr 7 '07 #1
3 2808
JosAH
11,448 Expert 8TB
Don't use PrintStreams whatsoever; those audio files/streams are pure
binary streams only and you're supposed to just use those: FileInputStream,
FileOutputStream and the streams obtained from the sockets.

kind regards,

Jos
Apr 7 '07 #2
Don't use PrintStreams whatsoever; those audio files/streams are pure
binary streams only and you're supposed to just use those: FileInputStream,
FileOutputStream and the streams obtained from the sockets.

kind regards,

Jos
Hello,
I am really very sorry,but i didn't get it.

1.What should be used to write to the socket then,if not PrintStream ?Can you please help me out with this code.

2.If the above thing is rectified,will it work properly?

3.When this code of copying file is used(without any client-server architecture) it creates a new audio file with all properties matching the original one,But when it is copied on the other side (client side),it shows "No Summary".Why does this happen?

Thanks and expecting your co-operation
Apr 10 '07 #3
JosAH
11,448 Expert 8TB
Hello,
I am really very sorry,but i didn't get it.

1.What should be used to write to the socket then,if not PrintStream ?Can you please help me out with this code.

2.If the above thing is rectified,will it work properly?

3.When this code of copying file is used(without any client-server architecture) it creates a new audio file with all properties matching the original one,But when it is copied on the other side (client side),it shows "No Summary".Why does this happen?

Thanks and expecting your co-operation
I reread my reply and noticed that I misread your original post; I apologize for
my mistake. Don't use Readers whatsoever, i.e. if you want to read binary data
use InputStreams, not Readers. It also explains the growth of your file just
read. For text data user Readers/Writers, for binary data use Input/OutputStreams
only.

kind regards,

Jos
Apr 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: conaito VoIP | last post by:
conaito VoIP ActiveX library for developers of VoIP audio applications, such as voice chat, conference, VoIP, providing real-time low latency multi-client audio streaming over UDP/IP networks....
3
by: Mizu | last post by:
Hi, I have a problem,I would like make a audio streamer for a web, but I don't know,whitsh namespaces should I use.Also I need make web service,web aplication or desktop aplication. When somebody...
3
by: skt | last post by:
Hi Can anyone tell me how I can stream audio input from a microphone input in C/C++? I would prefer plain C/C++, rather than DirectX/Windows programming, though those would be fine too. Also, how...
2
by: Cerebral Believer | last post by:
Hi All, I plan to use streaming audio on my site. I had uploaded some .mp3's as part of a trial, and these streamed very badly so I tried .ram (RealAudio) files instead. The RealAudio files...
1
by: fai210 | last post by:
I need to write a program about audio streaming in java. Are there any good sites that contain relevant tutorial and have some good examples for reference? Thank you.
8
by: pankhudi | last post by:
Hi everyone... I have to do a project work related on online audio system in Java...I have done the server-client prog(socket prog) n playing audio files..But how to stream my audio file from one PC...
1
by: npm | last post by:
I know how to stream audio from within an .swf as well from an external mp3, but does anyone know if Flash is able to stream OGG? The filename for the stream is usually something like,...
0
MJMF
by: MJMF | last post by:
Streaming: how can i make an audio streaming to transmit the voice through a radio station to make the people listen by a web site. by C# please replay, help me MP3 audio effects: how can i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.