How to store the audio/Video file to SQLite database in android.? [duplicate]
Asked Answered
K

1

8

Am new to developing, am successfully store the images to database by converting the images in to bytes array and store it to SQLite database in BLOB (find below code). But am not getting how to store audio's/video's into DB any one help me PLZ...

 public void getImage(View view){
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("image/* video/*");
    startActivityForResult(Intent.createChooser(intent, "select picture"), 1);

}

public void onActivityResult(int requestCode, int resultCode, Intent data){
    if(resultCode == RESULT_OK){
        Uri imageUri = data.getData();
        String imagePath = getPath(imageUri);

        image1.setVisibility(View.VISIBLE);

        image1.setImageURI(imageUri);
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        Toast.makeText(getApplicationContext(), ""+bitmap, Toast.LENGTH_SHORT).show();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        img = byteArrayOutputStream.toByteArray();
    }
}

 public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

public void saveImage(View v){

    imageDatabase = new ImageDatabase(this);

    imageDatabase.insert("first",img);

    Toast.makeText(getApplicationContext(), ""+imageDatabase.numberOfRows(),Toast.LENGTH_LONG).show();
}

In above code am taking the image from sdcard and displaying in ImageView and storing into DB.

Kesler answered 15/1, 2016 at 11:16 Comment(0)
I
2

Store the media files in internal/external storage, and store the path to it in your database.

see Saving Files

Ilysa answered 15/1, 2016 at 11:17 Comment(5)
Please don't post link as an answer. In future the link may change which will make this answer useless.Whalen
You're right, but I can't really do better. All I can do is suppress this sentenseIlysa
Renaud thanks for your replay, can you help me out by sending the any example code for this...Kesler
where are the audio/video files located ? how do you get them ? with a chooser like your image example ?Ilysa
Audio files are located in sdcard, any way by chooser or by give the path of the audio file. (better from chooser).Kesler

© 2022 - 2024 — McMap. All rights reserved.