我正在尝试使用post方法将视频上传到服务器,但我正在
FileNotFoundException
这是我的代码。在路径变量中,我得到“content:/ media / external / video / media / 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
}
};
}
请告诉我哪里出错了。
答案 0 :(得分:1)