在解析服务器android上上传视频

时间:2018-02-24 09:17:01

标签: android performance android-layout android-studio

我是Android的初学者,有人可以为我提供从移动视频库上传视频并将其保存在解析服务器上的工作教程吗?提前致谢 !         `Intent intent = new Intent(Intent.ACTION_PICK,         MediaStore.Video.Media.EXTERNAL_CONTENT_URI);         intent.setType( “视频/ *”);         startActivityForResult(intent,1);

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull 
    String[] 
    permissions, @NonNull int[] grantResults) 
    {
    super.onRequestPermissionsResult(requestCode, permissions, 
    grantResults);

    if (requestCode == 1) 
    {
        if (grantResults.length > 0 && grantResults[0] == 
    PackageManager.PERMISSION_GRANTED) 
        {
            getPhoto();

        }
    }
   }


   @Override
   protected void onCreate(Bundle savedInstanceState) 
   {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != 
    PackageManager.PERMISSION_GRANTED) 
    {
        requestPermissions(new String[]
        {Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
    } else {
        getPhoto();
    }

   }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent 
    data) 
   {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode==1 && resultCode==ChatActivity.RESULT_OK && data!=null)
    {
        try
        {
            VideoView mVideo=(VideoView) findViewById(R.id.videoView);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();


            byte[] byteArray =stream.toByteArray();
            ParseFile file = new ParseFile("resume.mp4", byteArray);

            ParseObject object = new ParseObject("Video");
            object.put("video",file);
            object.put("username", 
     ParseUser.getCurrentUser().getUsername());
            object.saveInBackground(new SaveCallback() 
            {
                @Override
                public void done(ParseException e) 
                {
                    if(e==null)
                    {
                        Toast.makeText(ChatActivity.this,"Vidoe 
    Saved",Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                        Toast.makeText(ChatActivity.this,"Vidoe not 
    Saved",Toast.LENGTH_SHORT).show();

                    }
                }
            });

        } 
        catch (Exception ex) 
        {
            ex.printStackTrace();
        }

    }`

我已经在清单文件中授予了访问外部数据的权限!

1 个答案:

答案 0 :(得分:0)

您很可能希望使用此处docs.parseplatform.org所述的ParseFile作为视频。