473,396 Members | 1,929 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.

java Stream Audio

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 1982
chaarmann
785 Expert 512MB
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
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 Expert 512MB
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.