Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 808017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:29:45+00:00 2026-05-15T00:29:45+00:00

I have to send the audio data in byte array obtain by recording from

  • 0

I have to send the audio data in byte array obtain by recording from java applet at the client side to rails server at the controller in order to save.

So, what encoding parameters at the applet side be used and in what form the audio data be converted like String or byte array so that rails correctly recieve data and then I can save that data at the rails in the file. As currently the audio file made by rails controller is not playing. It is the following ERROR :

  LAVF_header: av_open_input_stream() failed

while playing with the mplayer.

Here is the sample Java Code i m using in which i m reading audio data from the audio file:

package networksocket;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JApplet;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.util.Properties;
import javax.swing.plaf.basic.BasicSplitPaneUI.BasicHorizontalLayoutManager;
import sun.awt.HorizBagLayout;
import sun.awt.VerticalBagLayout;
import sun.misc.BASE64Encoder;
/**
 *
  * @author mukand
 */
public class Urlconnection extends JApplet implements ActionListener
{

/**
 * Initialization method that will be called after the applet is loaded
 * into the browser.
 */


public BufferedInputStream in;
public BufferedOutputStream out;
public String line;
public FileOutputStream file;
public int bytesread;
public int toread=1024;
byte b[]= new byte[toread];
public String f="FINISH";
public String match;
public File fileopen;
public JTextArea jTextArea;
public Button refreshButton;
public HttpURLConnection urlConn;
public URL url;
OutputStreamWriter wr;
BufferedReader rd;

@Override
public void init() {
    // TODO start asynchronous download of heavy resources
    //textField= new TextField("START");
    //getContentPane().add(textField);
    JPanel p = new JPanel();
    jTextArea= new JTextArea(1500,1500);
    p.setLayout(new GridLayout(1,1, 1,1));
    p.add(new JLabel("Server Details"));
    p.add(jTextArea);
    Container content = getContentPane();
    content.setLayout(new GridBagLayout()); // Used to center the panel
    content.add(p);
    jTextArea.setLineWrap(true);

    refreshButton = new java.awt.Button("Refresh");
    refreshButton.reshape(287,49,71,23);
    refreshButton.setFont(new Font("Dialog", Font.PLAIN, 12));
    refreshButton.addActionListener(this);
    add(refreshButton);
    Properties properties = System.getProperties();
    properties.put("http.proxyHost", "netmon.iitb.ac.in");
    properties.put("http.proxyPort", "80");

}
@Override
public void actionPerformed(ActionEvent e)
{
    try
    {
        url = new URL("http://localhost:3000/audio/audiorecieve");
        urlConn = (HttpURLConnection)url.openConnection();
        //String login = "mukandagarwal:rammstein$";
        //String encodedLogin = new BASE64Encoder().encodeBuffer(login.getBytes());
        //urlConn.setRequestProperty("Proxy-Authorization",login);
        urlConn.setRequestMethod("POST");

       // urlConn.setRequestProperty("Content-Type",
       //"application/octet-stream");
        //urlConn.setRequestProperty("Content-Type","audio/mpeg");//"application/x-www- form-urlencoded");
        //urlConn.setRequestProperty("Content-Type","application/x-www- form-urlencoded");
        //urlConn.setRequestProperty("Content-Length", "" +
          // Integer.toString(urlParameters.getBytes().length));
        urlConn.setRequestProperty("Content-Language", "UTF-8");
        urlConn.setDoOutput(true);
        urlConn.setDoInput(true);
        byte bread[]=new byte[2048];
        int iread;
        char c;
        String data=URLEncoder.encode("key1", "UTF-8")+ "=";
        //String data="key1=";
        FileInputStream fileread= new FileInputStream("//home//mukand//Hellion.ogg");//Dogs.mp3");//Desktop//mausam1.mp3");
        while((iread=fileread.read(bread))!=-1)
        {
            //data+=(new String());
            /*for(int i=0;i<iread;i++)
            {
                //c=(char)bread[i];
                System.out.println(bread[i]);

            }*/
          data+= URLEncoder.encode(new String(bread,iread), "UTF-8");//new String(new String(bread));//
        //    data+=new String(bread,iread);
        }
        //urlConn.setRequestProperty("Content-Length",Integer.toString(data.getBytes().length));
        System.out.println(data);
        //data+=URLEncoder.encode("mukand", "UTF-8");
        //data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");
        //data="key1=";
        wr = new OutputStreamWriter(urlConn.getOutputStream());//urlConn.getOutputStream();
        //if((iread=fileread.read(bread))!=-1)
          //  wr.write(bread,0,iread);
        wr.write(data);
        wr.flush();

        fileread.close();
        jTextArea.append("Send");

        // Get the response
        rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
        while ((line = rd.readLine()) != null) {
            jTextArea.append(line);
        }
        wr.close();
        rd.close();
            //jTextArea.append("click");

    }
    catch (MalformedURLException ex) {
        Logger.getLogger(Urlconnection.class.getName()).log(Level.SEVERE, null, ex);
    }
    catch (IOException ex) {
            Logger.getLogger(Urlconnection.class.getName()).log(Level.SEVERE, null, ex);
        }

}
@Override
public void start()
{
}

@Override
public void stop()
{

}
@Override
public void destroy()
{

}

// TODO overwrite start(), stop() and destroy() methods

}

Here is the Rails controller function for recieving:

 def audiorecieve
 puts "///////////////////////////////////////******RECIEVED*******////"
 puts params[:key1]#+" "+params[:key2]
 data=params[:key1]
 #request.env('RAW_POST_DATA')
 file=File.new("audiodata.ogg", 'w')
 file.write(data)
 file.flush
 file.close
 puts  "////**************DONE***********//////////////////////"
 end

Please reply quickly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:29:46+00:00Added an answer on May 15, 2026 at 12:29 am

    Base64 encode the data. Send it as a string, receive it on the Rails side and decode it back to the original format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 450k
  • Answers 450k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the strings are meant to be seen/used by users… May 15, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer Did you check the value of the current directory? The… May 15, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer You can make your object Countable so that it works… May 15, 2026 at 8:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.