我使用Hostinger的免费网络托管服务器。我在那里制作了桌子,想在桌子上添加网址和一些细节。
所以这是我的php文件
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$vehiclename = $_POST['vehiclename'];
$vehicleUrl= $_POST[vehicleUrl];
$date = $_POST['date'];
$location = $_POST['location'];
$note = $_POST['note'];
require_once('dbConnect.php');
$sql ="SELECT id FROM table2 ORDER BY id ASC";
$res = mysqli_query($con,$sql);
$id = 0;
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
}
$path = "uploads/$id.mp4";
$actualpath = "http://trafficviolation.esy.es/hosting/$path";
$sql = "INSERT INTO table2 (vehiclename,vehicleUrl,date,location,note) VALUES ('$vehiclename','$actualpath','$date','$location','$note')";
if(mysqli_query($con,$sql)){
file_put_contents($path,base64_decode($vehicleUrl));
echo "Successfully Uploaded";
}
mysqli_close($con);
}else{
echo "Error";
}
?>
&#13;
这是我的ActivityVedio.java类
public class ActivityVideo extends AppCompatActivity {
public VideoView vid;
EditText vehiclename;
EditText note;
EditText date1;
EditText location;
public Uri file;
String a;
public static final String UPLOAD_URL_VIdeo = "http://trafficviolation.esy.es/hosting/upload1Copy1.php";
private String selectedPath;
private String KEY_VIDEO = "vehicleUrl";
private String KEY_NAME = "vehiclename";
private String DATE = "date";
private String LOCATION = "location";
private String NOTE = "note";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
vid=(VideoView)findViewById(R.id.imViewVideo);
date1= (EditText) findViewById(R.id.date);
location= (EditText) findViewById(R.id.location);
vehiclename= (EditText) findViewById(R.id.name);
note= (EditText) findViewById(R.id.note);
Intent i = getIntent();
file = Uri.parse(i.getExtras().get("vidFile").toString());
selectedPath=i.getStringExtra("vidFile");
String dateTime=i.getStringExtra("date");
String a="abc";
if(dateTime.equals(a)){
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy
File file = new File(selectedPath);
Date lastModDate = new Date(file.lastModified());
String strDate = sdfDate.format(lastModDate);
date1.setText(strDate);
}
else{
date1.setText(dateTime);
}
location.setText(i.getStringExtra("location"));
// Show video on videoview
vid.setVideoURI(file);
MediaController mediaController = new
MediaController(this);
mediaController.setAnchorView(vid);
vid.setMediaController(mediaController);
vid.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
}
});
vid.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.save:
uploadVideo(); // ***Error on logcat : at com.example.t_buddhika.cam_17_2.ActivityVideo.onOptionsItemSelected(ActivityVideo.java:158)***
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void uploadVideo() {
String hname = vehiclename.getText().toString().trim();
String hdate = date1.getText().toString().trim();
String hlocation = location.getText().toString().trim();
String hnote = note.getText().toString().trim();
upload(hname,hdate,hlocation,hnote);// ***Error on logcat :at com.example.t_buddhika.cam_17_2.ActivityVideo.uploadVideo(ActivityVideo.java:172)***
}
private void upload(String hname, String hdate, String hlocation, String hnote) {
class UploadVideo extends AsyncTask<String, Void, String> {
ProgressDialog uploading;
RequestHandler rh = new RequestHandler();
@Override
protected void onPreExecute() {
super.onPreExecute();
uploading = ProgressDialog.show(ActivityVideo.this, "Uploading Video", "Please wait...", false, false);// ***Error on logcat at com.example.t_buddhika.cam_17_2.ActivityVideo$1UploadVideo.onPreExecute(ActivityVideo.java:183)***
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
uploading.dismiss();
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(String... params) {
int bytesAvailable,bufferSize;
FileInputStream objFileIS = null;
try
{
objFileIS = new FileInputStream(selectedPath);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
try
{
bytesAvailable = objFileIS.available();
Log.i("Huzza", "Initial .available : " + bytesAvailable);
bufferSize = Math.min(bytesAvailable, 1*1024*1024);
byte[] buffer = new byte[bufferSize];
for (int readNum; (readNum = objFileIS.read(buffer)) != -1;)
{
objByteArrayOS.write(buffer, 0, readNum);
}
}
catch (IOException e)
{
e.printStackTrace();
}
String videodata = Base64.encodeToString(objByteArrayOS.toByteArray(), Base64.DEFAULT);
HashMap<String, String> data = new HashMap<String,String>();
data.put(KEY_VIDEO, videodata);
data.put(KEY_NAME,params[0]);
data.put(DATE,params[1]);
data.put(LOCATION,params[2]);
data.put(NOTE,params[3]);
String result = rh.sendPostRequest(UPLOAD_URL_VIdeo,data);
return result;
}
}
UploadVideo uv = new UploadVideo();
uv.execute(hname,hdate,hlocation,hnote);// ***Error on logcat : at com.example.t_buddhika.cam_17_2.ActivityVideo.upload(ActivityVideo.java:254)***
}
}
&#13;
所以这只适用于某些视频。但对于某些视频,此代码对我不起作用。那么我该如何解决这个错误?
错误报告就像这样
Activity com.example.t_buddhika.cam_17_2.ActivityVideo has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42182f80 V.E..... R......D 0,0-480,243} that was originally added here
android.view.WindowLeaked: Activity com.example.t_buddhika.cam_17_2.ActivityVideo has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42182f80 V.E..... R......D 0,0-480,243} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:304)
at android.app.ProgressDialog.show(ProgressDialog.java:116)
at android.app.ProgressDialog.show(ProgressDialog.java:104)
at com.example.t_buddhika.cam_17_2.ActivityVideo$1UploadVideo.onPreExecute(ActivityVideo.java:183)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at com.example.t_buddhika.cam_17_2.ActivityVideo.upload(ActivityVideo.java:254)
at com.example.t_buddhika.cam_17_2.ActivityVideo.uploadVideo(ActivityVideo.java:172)
at com.example.t_buddhika.cam_17_2.ActivityVideo.onOptionsItemSelected(ActivityVideo.java:158)
at android.app.Activity.onMenuItemSelected(Activity.java:2548)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:147)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:620)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:139)
at android.view.View.performClick(View.java:4278)
at android.view.View$PerformClick.run(View.java:17429)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5099)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:803)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:570)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
在ProgressDialog
AsyncTask
private void upload(String hname, String hdate, String hlocation, String hnote) {
final ProgressDialog uploading = new ProgressDialog(this);
uploading.setTitle("Uploading Video");
uploading.setMessage("Please wait...");
uploading.setCancelable(true);
class UploadVideo extends AsyncTask<String, Void, String> {
protected void onPreExecute() {
uploading.show();
// rest of your code....
}
protected void onPostExecute() {
uploading.dismiss();
// rest of your code here....
}
}
//....
}
它可以解决您的问题。