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

时间:2014-04-02 05:29:10

标签: android parse-platform

视频存储在解析中。

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();

    }
当我点击存储在解析中的视频时,

视频在浏览器中播放,它被下载到下载文件夹,我可以在任何媒体播放器中播放。 如何从解析下载视频并将其存储在解析中并在视频视图中播放?

1 个答案:

答案 0 :(得分:1)

您将需要使用媒体控制器。我之前遇到过同样的问题。这是一个例子。我是您在查询中检索到的ParseObject的变量。这段代码是用C#为Xamarin for Android编写的。它可以很容易地转换,只是降低了一些这些字母。

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 ();