简体   繁体   English

我如何下载视频并将其转换为使用parse在videoview中播放?

[英]how can i download the video and convert it to play in videoview using parse?

video gets stored in parse. 视频将存储在解析中。

public void uvideo(View v) throws FileNotFoundException, IOException
    {

         File f = new File("/sdcard/Sample.3gp");
         byte[] videoUp=new byte[576600];  
            videoUp = IOUtils.toByteArray( new FileInputStream(f));


             files = new ParseFile("testVideo1", videoUp);

             files.saveInBackground(new SaveCallback() {


                 public void done(ParseException e) {
                      if(e==null) {
                          // SUCCESS!!!
                      } else {
                          e.printStackTrace();
                      }
                  }

             }, new ProgressCallback() {

             public void done(Integer percentDone) {

             System.out.println("Progress :" + percentDone);
              }
             });


    }

    // this code doesnt't work
    public void recievev(View c)
    {
        jobApplications = new ParseObject("Testvideo");
        jobApplications.put("applicantName", "Joe Smith");
        jobApplications.put("applicantResumevideo", files);
        jobApplications.saveInBackground();
        ParseUser.enableAutomaticUser();
        ParseACL defaultACL = new ParseACL();
       // If you would like all objects to be private by default, remove this line.
        defaultACL.setPublicReadAccess(true);
        ParseACL.setDefaultACL(defaultACL, true);

    }

      // this code doesnt't work
    public void rvideo(View c)
    {

       ParseFile applicantResume = (ParseFile)jobApplications.get("applicantResumevideo");
        applicantResume.getDataInBackground(new GetDataCallback() {
          public void done(byte[] data, ParseException e) {
            if (e == null) {
              // data has the bytes for the resume

             String strFile = Base64.encodeToString(data, Base64.NO_WRAP);
              try
              {
                BufferedReader br=new BufferedReader(new FileReader(strFile));
                BufferedWriter bw = new BufferedWriter(new FileWriter("/sdcard/s.3pg"));
                String line=br.readLine();
                String dt="";
                while(line != null)
                {
                 //System.out.println(line);
                dt = dt+"\n"+line;
                line = br.readLine();
                 } 
                   br.close();
                   bw.write(dt);
                   bw.close();

               }
               catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
                //Bitmap bMap = BitmapFactory.decodeByteArray(data, 0, data.length);
                catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }


            } else {
              // something went wrong
            }
          }
        });
       dvideo();
    }
      // this code doesnt't work because video doesn't get download
    public void dvideo()
    {
         VideoView v = (VideoView) findViewById(R.id.videoView1);
         Uri u=Uri.parse("/sdcard/S.3gp");
         v.setVideoURI(u);
         v.start();

    }

video gets played in browser when I click on video stored in parse, it gets downloaded to downloads folder and I can play in any media player. 当我单击解析后存储的视频时,该视频将在浏览器中播放,该视频将下载到downloads文件夹中,并且可以在任何媒体播放器中播放。 How to download video from parse and store it in parse and play in video view? 如何从解析中下载视频并将其存储在解析中并在视频视图中播放?

You are going to need to use a media controller. 您将需要使用媒体控制器。 I came across this same problem before. 我之前也遇到过同样的问题。 Here is an example. 这是一个例子。 i being the variable for the ParseObject you retrieved in your query. 我是您在查询中检索到的ParseObject的变量。 This code was written in C# for Xamarin for Android though. 这段代码是用C#为Xamarin for Android编写的。 It can be easily converted just lowercasing some these letters. 只需小写这些字母即可轻松转换。

var videoVar = i.Get<ParseFile> ("video"); 
                        string videoUrl = videoVar.Url.ToString ();

 VideoView video = FindViewById <VideoView> (Resource.Id.videoView); 

            var uri = Android.Net.Uri.Parse (videoUrl);
            video.SetVideoURI (uri); 
            MediaController mc = new MediaController (this); 

            video.SetMediaController (mc); 
            video.RequestFocus (); 
            mc.Show (); 
            video.Start (); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM