1

Androidのasp.netサーバーにビデオを送信しようとしています。しかし、動画のサイズが約26MBなので動画を送れませんか?ビデオをパーツに分割し、Java を使用して Android 経由で .net サーバーに送信する方法はありますか?

 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import android.app.Activity;
 import android.content.Intent;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
 import android.provider.MediaStore;
 import android.util.Log;

 public class VideoUploader extends Activity 
 {
/** Called when the activity is first created. */

public static final int SELECT_VIDEO=1;
public static final String TAG="UploadActivity";
String path="";

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    openGaleryVideo();
}

public void openGaleryVideo()
{
    Intent intent=new Intent();
    intent.setType("video/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Video"),SELECT_VIDEO);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_VIDEO) {
            Uri videoUri = data.getData();
            path= getPath(videoUri);
            doFileUpload();
        } 
    }
}
public String getPath(Uri uri)
{   
    String[] projection = { MediaStore.Video.Media.DATA};
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

public void doFileUpload()
{
        String pathToOurFile = path;//this will be the file path        
        String urlServer = "http://192.168.10.177/androidweb/default.aspx";
        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = 2*1024* 1024;

        try
        {
        FileInputStream fileInputStream = new FileInputStream(new File(pathToOurFile));

        URL url = new URL(urlServer);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        // Allow Inputs & Outputs
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setUseCaches(false);

        // Enable POST method
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setRequestProperty("Content-Type",  "multipart/form-data");
        connection.setRequestProperty("SD-FileName", "Chrysanthemum.JPEG");

        DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
        bytesAvailable = fileInputStream.available();
        bufferSize = Math.min(bytesAvailable, maxBufferSize);
        buffer = new byte[bufferSize];

        // Read file
        bytesRead = fileInputStream.read(buffer, 0, bufferSize);
        while (bytesRead > 0)
        {
            outputStream.write(buffer, 0, bufferSize);
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
        }//end of while statement

         int serverResponseCode = connection.getResponseCode();
         String serverResponseMessage = connection.getResponseMessage();
         Log.d("ServerCode",""+serverResponseCode);
         Log.d("serverResponseMessage",""+serverResponseMessage);
         fileInputStream.close();
         outputStream.flush();
         outputStream.close();
        }//end of try body

        catch (Exception ex)
        {
            //ex.printStackTrace();
            Log.e("Error: ", ex.getMessage());
        }
      }
}
4

1 に答える 1

0

まず、再構築するまでビデオを再生可能にする必要がない場合は、各部分で非常に多くのバイトを送信し、サーバーに再構築させます。この残りの部分では、個別に再生できるいくつかのビデオに分割する必要があると仮定します。

ICS のビデオ編集の例を見ることができますが、実装方法によっては、最新のデバイスに限定される可能性があります。

さもないと:

ほとんどの圧縮ビデオ形式は、絶対情報 (キーフレーム) の繰り返しシーケンスと、それに続く、そのベースに対してエンコードされたフレームの相対情報と考えることができます。使用している未指定の形式の詳細を理解すると、完全なキー フレームで新しいセクションが始まる場所で、カットしたいサイズに近い場所を特定する方法をおそらく学ぶことができます。そこでビデオを分割し、必要なファイル ヘッダーを新しい部分に作成し、元のヘッダーの長さ情報を調整します。

これを自分で行うことは教育的ですが、既存のソリューションを探す価値もあります。

于 2012-06-19T15:41:39.227 に答える