473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

java Stream Audio

2 New Member
I want to use a ServerSocket at a PC
and a Socket for users
And I tried to Stream a music from Server to Client
But I dont know what should I send to the Client
Here's part of my code
Expand|Select|Wrap|Line Numbers
  1. public static void CP(File media , int LoopCount)
  2.    {
  3.       AudioInputStream AIS = null;
  4.       try
  5.       {
  6.          AIS = AudioSystem.getAudioInputStream(media);
  7.       }
  8.       catch(Exception e)
  9.       {
  10.          e.printStackTrace();
  11.       }
  12.       if (AIS != null)
  13.       {
  14.         AudioFormat    format = AIS.getFormat();
  15.         System.out.println(format.toString());
  16.         SourceDataLine line = null ;
  17.         try
  18.         {
  19.            line = AudioSystem.getSourceDataLine(format);
  20.         }
  21.         catch(Exception ex){}
  22.  
  23.         byte[]    abData = new byte[128000];
  24.         int readByte = 0;
  25.         while(readByte != -1)
  26.         {
  27.             try
  28.             {              
  29.               readByte = AIS.read(abData, 0, abData.length);
  30.               ops.write(new byte[readByte]);
  31.               if(readByte > 0)
  32.               {
  33.                  line.open(format);
  34.                  line.start();              
  35.                  int lineWritten = line.write(abData,0,readByte);
  36.                  //System.out.println(readByte);
  37.               }
  38.             }
  39.             catch (LineUnavailableException e)
  40.             {
  41.               e.printStackTrace();
  42.             }
  43.             catch (Exception e)
  44.             {
  45.               e.printStackTrace();
  46.             }
  47.         }
  48.       }
  49.    }
What should I send? the <readByte> ? or the <lineWritten>
Sep 15 '14 #1
3 1984
chaarmann
785 Recognized Expert Contributor
Send the <readByte>.
The <lineWritten> is just an iteger that tells you about the success of your data sent (there may be an error)
Sep 22 '14 #2
hansun11
2 New Member
Well .. I tried I sent <readByte> to the client
Then here'S another question. Don't know how to use it
To play an audio need a inputstream a format and a line.
But to new a stream needs a file or url. And format needs stream line needs format
But I only got a readbyte . So i have no idea how to use it
I''ll paste on the code of the client later
Sep 23 '14 #3
chaarmann
785 Recognized Expert Contributor
Use ByteArrayInputStream. This stream only needs bytes, no file or URL.
Sep 24 '14 #4

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

Similar topics

2
by: Raed Sawalha | last post by:
Hello, I'm building a website that will sell recordings of local small bands. I would like to a have a pop up that will play songs of my db and display the song info. Can anybody point me to...
1
by: ACaunter | last post by:
Hi all, Have been getting no luck lately, but there must be a way i can recording audio from the website and save it.. It's no problem on applications (VB.Net), and I know other have done it...
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: hzgt9b | last post by:
Using VS 2003, VB.NET and/or ASP.NET 2.0, BACKGROUND I have a window forms based application that contains a TreeView control and a WebBroswer (AxSHDocVw.AxWebBrowser) control. The TreeView is...
4
by: hzgt9b | last post by:
Using VS 2003, VB.NET and/or ASP.NET 2.0, BACKGROUND I have a window forms based application that contains a TreeView control and a WebBroswer (AxSHDocVw.AxWebBrowser) control. The TreeView is...
1
by: Chris | last post by:
Hi, Can anyone point me to info on how to stream audio from a web server in more or less real time (i.e. exact synchronization is not an issue but it would be nice if the stream was no more than...
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,...
2
by: cityrocker2005 | last post by:
Hi! Programmers, I have code for streaming audio file from remote server, if anybody know about it please send it to me.
2
by: anupamaheshwari | last post by:
Dear All, I am planning to write a program in Java language - Client Server; where in two clients can call each other if the have the application installed. It's like dialing a computer,...
0
by: =?Utf-8?B?QnJlY2tpZQ==?= | last post by:
When I try to stream audio (live or cached) from online radio stations, WMP 11 will not fully open and/or play the audio, and I'm forced to close WMP completely. Anyone know how to resolve this?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.