0
我想上傳到使用POST方法服務器的視頻,但我正在逐漸安卓:在上傳視頻
FileNotFoundException異常
這裏是我的代碼文件中未發現異常。在PATH變量中我得到「內容:/媒體/外部/視頻/媒體/ 2」
public class VideoPlayUploadActivity extends Activity {
private VideoView video_play;
private Button accept_and_go;
private Button reject_and_do;
Uri vid;
String user;
String question;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_view);
video_play = (VideoView) findViewById(R.id.videoView1);
accept_and_go = (Button) findViewById(R.id.button_accept_and_go_over_video);
reject_and_do = (Button) findViewById(R.id.button_reject_and_do_over_video);
Intent extras = getIntent();
vid = Uri.parse(extras.getStringExtra("uri"));
if (vid == null) {
Toast.makeText(VideoPlayUploadActivity.this, "No Video",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(VideoPlayUploadActivity.this,
"Playback: " + vid.getPath(), Toast.LENGTH_LONG).show();
MediaController mc = new MediaController(this);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
video_play.setMediaController(mc);
video_play.setVideoURI(vid);
video_play.start();
}
accept_and_go.setOnClickListener(accept_go_listener);
}
private View.OnClickListener accept_go_listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String path = vid.getPath();
File file = new File(path);
try {
HttpClient client = new DefaultHttpClient();
String postURL = "xxxxxxxxxxxxxxxxxxxxxxxxupdateAnswerFile";
HttpPost post = new HttpPost(postURL);
FileBody bin = new FileBody(file);
StringBody user = new StringBody("1");
StringBody question = new StringBody("25");
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("user", user);
reqEntity.addPart("question", question);
reqEntity.addPart("answer", bin);
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Log.i("RESPONSE", EntityUtils.toString(resEntity));
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "exception", 0).show();
e.printStackTrace();
}
}
};
private View.OnClickListener reject_do_listenter = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
};
}
請告訴我在哪裏,我錯了。
內容://不是文件,它不能在FileBody中使用。嘗試一個inputstreamBody並打開InputStream與contentResolver.openInputStream(路徑) – njzk2