簡體   English   中英

我如何下載視頻並將其轉換為使用parse在videoview中播放?

[英]how can i download the video and convert it to play in videoview using 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();

    }

當我單擊解析后存儲的視頻時,該視頻將在瀏覽器中播放,該視頻將下載到downloads文件夾中,並且可以在任何媒體播放器中播放。 如何從解析中下載視頻並將其存儲在解析中並在視頻視圖中播放?

您將需要使用媒體控制器。 我之前也遇到過同樣的問題。 這是一個例子。 我是您在查詢中檢索到的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 (); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM