2017-10-23 20 views
0

firebaseのストレージに動画を追加し、カードビューのリサイクラービューですべてのアップロード動画を取得したいと考えています。アプリでFirebaseから動画を取り込む方法は?

これに関する参考資料またはソースコードを提供してください。

firebaseで動画をアップロードしようとしていますが、正常にアップロードされましたが、取得できません。

ありがとうございます。

public class VideoUplod extends AppCompatActivity 
{ 
    private static final int RC_PDF_PICKER = 2; 
    private FirebaseStorage mFirebaseStorage; 
    private StorageReference mChatPDFStorageReference; 
    public static final int RC_SIGN_IN = 1; 

    @Override 


protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_video_uplod); 

    VideoView videoView =(VideoView)findViewById(R.id.image); 


    //Creating MediaController 
    MediaController mediaController= new MediaController(this); 
    mediaController.setAnchorView(videoView); 


    //specify the location of media file 
    Uri uri=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/media/1.mp4"); 

    //Setting MediaController and URI, then starting the videoView 
    videoView.setMediaController(mediaController); 
    videoView.setVideoURI(uri); 
    videoView.requestFocus(); 
    videoView.start(); 



    mFirebaseStorage =FirebaseStorage.getInstance(); 
    mChatPDFStorageReference = mFirebaseStorage.getReference().child("Video"); 

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.setType("video/*"); 
    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); 
    startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PDF_PICKER); 
} 
@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == RC_SIGN_IN) { 
     if (resultCode == RESULT_OK) { 
      // Sign-in succeeded, set up the UI 
      Toast.makeText(this, "Signed in!", Toast.LENGTH_SHORT).show(); 
     } else if (resultCode == RESULT_CANCELED) { 
      // Sign in was canceled by the user, finish the activity 
      Toast.makeText(this, "Sign in canceled", Toast.LENGTH_SHORT).show(); 
      finish(); 
     } 
     //for photo storage check 
    } else if (requestCode == RC_PDF_PICKER && resultCode == RESULT_OK) { 
     Uri selectedImageUri = data.getData(); 

     // Get a reference to store file at chat_photos/<FILENAME> 

     StorageReference photoRef = mChatPDFStorageReference.child(selectedImageUri.getLastPathSegment()); 

     // Upload file to Firebase Storage 

     photoRef.putFile(selectedImageUri) 
       .addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { 

        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 
         // When the image has successfully uploaded, we get its download URL 
         @SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl(); 

         // Set the download URL to the message box so that the user can send it to the database 
        } 
       }); 
     } 
    } 
} 
+0

あなたの努力を示すためにいくつかのコードを投稿する必要があります。 –

+0

「これについての参考資料またはソースコードを入力してください」 - その人のようには動作しません – JMedinilla

+0

はい、私は努力を加えていますので、今すぐ助けてください@SafanMomin –

答えて

0

私はを見てみたい:ドキュメントからアプリケーション(videosource)に

、それはかなり簡単ですファイルをダウンロードする:

StorageReference videoRef = storageRef.child("videos/myvideo.mp4"); 

final long ONE_MEGABYTE = 1024 * 1024; 
videoRef.getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() { 
    @Override 
    public void onSuccess(byte[] bytes) { 
     // Transform bytes to a video, play 
    } 
}).addOnFailureListener(new OnFailureListener() { 
    @Override 
    public void onFailure(@NonNull Exception exception) { 
     // Handle any errors 
    } 
}); 
関連する問題