如何转换视频文件(.MP4)格式转换成二进制格式的Andr​​oid?格式、转换成、视频文件、oid

2023-09-07 12:59:36 作者:少来偷看我

我要上传的Web服务器的视频。我要我要传递的文件以二进制格式的服务,我怎么能做到这一点?

I want to upload a video in web server. I got the service which to i want to pass a file in binary format how can i do this ?

我曾尝试将视频文件转换成二进制格式的base64的帮助..?

I have tried to convert the video file into binary format with the help of base64..?

public class binaryformat extends Activity {
private String strAttachmentCoded;
Button b1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b1=(Button)findViewById(R.id.button1);
    b1.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
             File file = new File("/mnt/sdcard/C:/Program Files (x86)/Wowza Media Systems/Wowza Media Server 3.1.2/content/sample.mp4");
                FileInputStream objFileIS = null;
                try
                {
                    objFileIS = new FileInputStream(file);
                } 
                catch (FileNotFoundException e) 
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
                byte[] byteBufferString = new byte[1024];
                try
                {
                    for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;) 
                    {
                     objByteArrayOS.write(byteBufferString, 0, readNum);
                     System.out.println("read " + readNum + " bytes,");
                    }
                } 
                catch (IOException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }                    
                byte[] byteBinaryData = Base64.encode((objByteArrayOS.toByteArray()), Base64.DEFAULT);
               strAttachmentCoded = new String(byteBinaryData);

        }
    });


}

}

推荐答案

我曾经历过在我的3个应用程序,这是好的,如果使用XML来发送图像或视频切换服务器。 在XML的base64字符串的形式发送图像或视频是最好的,如果你要上传的ANDROID一个图像或视频。

I have experienced in my 3 application that it is good if use XML to send the IMAGE or VIDEO over server. Sending IMAGE or VIDEO in the form of base64 String in the XML is best if you want to upload a IMAGE or VIDEO in ANDROID.

public static String uploadMultiplePhoto(String url, String xmlString) {
        String responseString = "";
        try {
            //instantiates httpclient to make request
            DefaultHttpClient httpclient = new DefaultHttpClient();
            //url with the post data
            HttpPost request = new HttpPost(url);
            //convert parameters into JSON object
            //JSONObject holder = new JSONObject(jsonObjString);

            //passes the results to a string builder/entity
            StringEntity se = new StringEntity(xmlString);
            //sets the post request as the resulting string
            request.setEntity(se);
            //sets a request header so the page receving the request
            //will know what to do with it
            request.setHeader("Accept", "application/xml");
            /*request.setHeader("Content-type", "application/xml");*/

            //Handles what is returned from the page
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            responseString = httpclient.execute(request, responseHandler);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return responseString;
    }